Skip to content

Commit ccd298e

Browse files
authored
Fix alignments formatting multiple currency formats (#42)
1 parent 53d7c25 commit ccd298e

File tree

8 files changed

+422
-528
lines changed

8 files changed

+422
-528
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2025-10-21 - [0.3.3]
4+
5+
- Fix alignments formatting multiple currency formats.
6+
37
## 2025-10-21 - [0.3.2]
48

59
### Bug fixes

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hledger-fmt"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
rust-version = "1.74.1"
55
edition = "2021"
66
description = "An opinionated hledger's journal files formatter."

src/common.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/formatter/mod.rs

Lines changed: 76 additions & 158 deletions
Large diffs are not rendered by default.

src/formatter/tests.rs

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn auto_posting_rule() {
263263
}
264264

265265
#[test]
266-
fn two_full_transactions() {
266+
fn full_transaction_1() {
267267
assert_format(
268268
r#"
269269
2024-01-01 opening balances ; At the start, declare pre-existing balances this way.
@@ -273,33 +273,39 @@ fn two_full_transactions() {
273273
equity:start ; One amount can be left blank. $-10500 is inferred here.
274274
; Some of these accounts we didn't declare above,
275275
; so -s/--strict would complain.
276+
"#,
277+
r#"
278+
2024-01-01 opening balances ; At the start, declare pre-existing balances this way.
279+
assets:savings $10000 ; Account names can be anything. lower case is easy to type.
280+
assets:checking $1000 ; assets, liabilities, equity, revenues, expenses are common.
281+
liabilities:credit card $-500 ; liabilities, equity, revenues balances are usually negative.
282+
equity:start ; One amount can be left blank. $-10500 is inferred here.
283+
; Some of these accounts we didn't declare above,
284+
; so -s/--strict would complain.
285+
"#,
286+
);
287+
}
276288

277-
2024-01-03 ! (12345) pay rent
289+
#[test]
290+
fn full_transaction_2() {
291+
assert_format(
292+
r#"2024-01-03 ! (12345) pay rent
278293
; Additional transaction comment lines, indented.
279294
; There can be a ! or * after the date meaning "pending" or "cleared".
280295
; There can be a parenthesised (code) after the date/status.
281296
; Amounts' sign shows direction of flow.
282297
assets:checking $-500 ; Minus means removed from this account (credit).
283298
expenses:rent $500 ; Plus means added to this account (debit).
284299
"#,
285-
r#"
286-
2024-01-01 opening balances ; At the start, declare pre-existing balances this way.
287-
assets:savings $10000 ; Account names can be anything. lower case is easy to type.
288-
assets:checking $1000 ; assets, liabilities, equity, revenues, expenses are common.
289-
liabilities:credit card $-500 ; liabilities, equity, revenues balances are usually negative.
290-
equity:start ; One amount can be left blank. $-10500 is inferred here.
291-
; Some of these accounts we didn't declare above,
292-
; so -s/--strict would complain.
293-
294-
2024-01-03 ! (12345) pay rent
300+
r#"2024-01-03 ! (12345) pay rent
295301
; Additional transaction comment lines, indented.
296302
; There can be a ! or * after the date meaning "pending" or "cleared".
297303
; There can be a parenthesised (code) after the date/status.
298304
; Amounts' sign shows direction of flow.
299305
assets:checking $-500 ; Minus means removed from this account (credit).
300306
expenses:rent $500 ; Plus means added to this account (debit).
301307
"#,
302-
);
308+
)
303309
}
304310

305311
#[test]
@@ -330,8 +336,8 @@ fn transaction_with_shares() {
330336
"#,
331337
r#"
332338
2024-01-15 buy some shares, in two lots ; Cost can be noted.
333-
assets:investments:2024-01-15 2.0 AAAA @ $1.50 ; @ means per-unit cost
334-
assets:investments:2024-01-15-02 3.0 AAAA @@ $4 ; @@ means total cost
339+
assets:investments:2024-01-15 2.0 AAAA @ $1.50 ; @ means per-unit cost
340+
assets:investments:2024-01-15-02 3.0 AAAA @@ $4 ; @@ means total cost
335341
; ^ Per-lot subaccounts are sometimes useful.
336342
assets:checking $-7
337343
"#,
@@ -409,7 +415,7 @@ fn separate_transactions() {
409415
}
410416

411417
#[test]
412-
fn assert_balance_transaction() {
418+
fn balance_transaction() {
413419
// assert balance transactions are formatted aligning the equal sign
414420
assert_format(
415421
r#"
@@ -436,8 +442,8 @@ fn assert_balance_transaction() {
436442
assets:bank:gold 0 gold = -10 gold
437443
assets:pouch 0 gold = 4 gold
438444
assets:pouch 0 "Chocolate Frogs" = 3 "Chocolate Frogs"
439-
assets:investments:2024-01-15 0.0 AAAA = 2.0 AAAA @ $1.50
440-
assets:investments:2024-01-15-02 0.0 AAAA = 3.0 AAAA @@ $4
445+
assets:investments:2024-01-15 0.0 AAAA = 2.0 AAAA @ $1.50
446+
assets:investments:2024-01-15-02 0.0 AAAA = 3.0 AAAA @@ $4
441447
liabilities:credit card $0 = $-500
442448
"#,
443449
);
@@ -448,15 +454,17 @@ fn complex_transaction() {
448454
assert_format(
449455
r#"
450456
2024-01-15 hello ; a comment
457+
assets:checking 10000,00€ @ 32543.000345€ ==* $56424324€ ; posting
451458
assets:checking 10000€ @ 32543.000345€ ==* $56424324€ ; comments
452459
expenses:food $10.010000 @@ $33.3 = 56€ ; must be
453460
foo 50000000.0000000000€ @@ 65579€ == $78.7 ; aligned
454461
"#,
455462
r#"
456463
2024-01-15 hello ; a comment
457-
assets:checking 10000€ @ 32543.000345€ ==* $56424324€ ; comments
458-
expenses:food $10.010000 @@ $33.3 = 56€ ; must be
459-
foo 50000000.0000000000€ @@ 65579€ == $78.7 ; aligned
464+
assets:checking 10000,00€ @ 32543.000345€ ==* $56424324€ ; posting
465+
assets:checking 10000€ @ 32543.000345€ ==* $56424324€ ; comments
466+
expenses:food $10.010000 @@ $33.3 = 56€ ; must be
467+
foo 50000000.0000000000€ @@ 65579€ == $78.7 ; aligned
460468
"#,
461469
);
462470
}
@@ -485,8 +493,8 @@ fn lots() {
485493
assets:investments:2024-01-15-02 0.0 AAAA = 3.0 AAAA @@ $4
486494
"#,
487495
r#"2024-01-15 foobar
488-
assets:investments:2024-01-15 0.0 AAAA = 2.0 AAAA @ $1.50
489-
assets:investments:2024-01-15-02 0.0 AAAA = 3.0 AAAA @@ $4
496+
assets:investments:2024-01-15 0.0 AAAA = 2.0 AAAA @ $1.50
497+
assets:investments:2024-01-15-02 0.0 AAAA = 3.0 AAAA @@ $4
490498
"#,
491499
);
492500
}
@@ -511,14 +519,15 @@ fn issue_27() {
511519
assets:cash USDT 120
512520
"#,
513521
r#"2024-01-02 exchange imaginary currency
514-
income:cash EUR-100 @@ USDT120
515-
assets:cash USDT120
522+
income:cash EUR -100 @@ USDT 120
523+
assets:cash USDT 120
516524
"#,
517525
)
518526
}
519527

528+
// https://github.com/mondeja/hledger-fmt/issues/32
520529
#[test]
521-
fn issue_32_unicode() {
530+
fn unicode_in_entry_name() {
522531
assert_noop_format(
523532
r#"2025-09-23 * Zakupy
524533
a.ca -106,98
@@ -608,3 +617,31 @@ fn transaction_with_multi_spaced_description_and_valid_comment() {
608617
"#,
609618
);
610619
}
620+
621+
// https://github.com/mondeja/hledger-fmt/issues/32
622+
#[test]
623+
fn transaction_with_multiple_currency_formatting() {
624+
assert_noop_format(
625+
r#"2025-01-01 Example transaction
626+
assets:acc1 £10,000.00
627+
assets:acc2 1.000,00€
628+
assets:acc3 £1000,00
629+
assets:acc3 £1000€
630+
equity
631+
"#,
632+
)
633+
}
634+
635+
// https://github.com/mondeja/hledger-fmt/issues/32
636+
#[test]
637+
fn space_as_thousands_separator() {
638+
assert_noop_format(
639+
r#"2025-09-21 * Example transaction
640+
a.bankaccount -2 049,44
641+
e.expanse 116,99
642+
e.someotherexpense $1 018,99
643+
e.anotherexpense 1,99
644+
e.thirdexpense
645+
"#,
646+
)
647+
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#[doc(hidden)]
22
#[cfg(feature = "cli")]
33
pub mod cli;
4-
mod common;
54
mod formatter;
65
mod parser;
76

0 commit comments

Comments
 (0)