diff options
author | Mitchell Kember <mk12360@gmail.com> | 2016-03-22 21:57:56 -0700 |
---|---|---|
committer | Mitchell Kember <mk12360@gmail.com> | 2016-03-22 23:09:27 -0700 |
commit | d082b6485f371b9eae01789b245a7944535a69d2 (patch) | |
tree | efb8982deec06497e302cd7c1849454d3c180a15 | |
parent | 16c2b8d58d98c41a8b9093116dfa34d5da71b44a (diff) | |
download | fork-ledger-d082b6485f371b9eae01789b245a7944535a69d2.tar.gz fork-ledger-d082b6485f371b9eae01789b245a7944535a69d2.tar.bz2 fork-ledger-d082b6485f371b9eae01789b245a7944535a69d2.zip |
Fix Bug 1147: Check balance assertions against the amount AFTER
-rw-r--r-- | src/textual.cc | 22 | ||||
-rw-r--r-- | test/baseline/feat-balance_assert-off.test | 2 | ||||
-rw-r--r-- | test/baseline/feat-balance_assert_split.test | 4 | ||||
-rw-r--r-- | test/regress/1147-a.test | 12 | ||||
-rw-r--r-- | test/regress/1147-b.test | 10 |
5 files changed, 37 insertions, 13 deletions
diff --git a/src/textual.cc b/src/textual.cc index ccd87ca0..4549581b 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -1671,25 +1671,27 @@ post_t * instance_t::parse_post(char * line, break; } - amount_t tot = amt - diff; - DEBUG("post.assign", "line " << context.linenum << ": " << "diff = " << diff); DEBUG("textual.parse", "line " << context.linenum << ": " << "POST assign: diff = " << diff); - if (! diff.is_zero()) { - if (! post->amount.is_null()) { - diff -= post->amount; - if (! no_assertions && ! diff.is_zero()) - throw_(parse_error, - _f("Balance assertion off by %1% (expected to see %2%)") - % diff % tot); - } else { + if (post->amount.is_null()) { + // balance assignment + if (! diff.is_zero()) { post->amount = diff; DEBUG("textual.parse", "line " << context.linenum << ": " << "Overwrite null posting"); } + } else { + // balance assertion + diff -= post->amount; + if (! no_assertions && ! diff.is_zero()) { + amount_t tot = amt - diff; + throw_(parse_error, + _f("Balance assertion off by %1% (expected to see %2%)") + % diff % tot); + } } if (stream.eof()) diff --git a/test/baseline/feat-balance_assert-off.test b/test/baseline/feat-balance_assert-off.test index fed24d4a..d1da753e 100644 --- a/test/baseline/feat-balance_assert-off.test +++ b/test/baseline/feat-balance_assert-off.test @@ -13,6 +13,6 @@ While parsing file "$FILE", line 8: While parsing posting: Assets:Cash -$10 = $80 ^^^ -Error: Balance assertion off by $-10 (expected to see $100) +Error: Balance assertion off by $-10 (expected to see $90) end test diff --git a/test/baseline/feat-balance_assert_split.test b/test/baseline/feat-balance_assert_split.test index 2d9cce9f..ad299325 100644 --- a/test/baseline/feat-balance_assert_split.test +++ b/test/baseline/feat-balance_assert_split.test @@ -14,7 +14,7 @@ 2012-01-04 Test ; UUID: foo - Liabilities:MasterCard $150.00 = $-300 + Liabilities:MasterCard $150.00 = $-150 <Assets:Checking> 2012-01-04 Test @@ -24,7 +24,7 @@ 2012-01-04 Test ; UUID: baz - Liabilities:MasterCard $150.00 = $0 + Liabilities:MasterCard $150.00 = $150 <Assets:Checking> ;; b.dat diff --git a/test/regress/1147-a.test b/test/regress/1147-a.test new file mode 100644 index 00000000..e999c312 --- /dev/null +++ b/test/regress/1147-a.test @@ -0,0 +1,12 @@ +2000/01/01 Pre-transaction balance + A $5.00 = $0.00 + B + +test bal -> 1 +__ERROR__ +While parsing file "$FILE", line 2: +While parsing posting: + A $5.00 = $0.00 + ^^^^^ +Error: Balance assertion off by $-5.00 (expected to see $5.00) +end test diff --git a/test/regress/1147-b.test b/test/regress/1147-b.test new file mode 100644 index 00000000..d3a1cffc --- /dev/null +++ b/test/regress/1147-b.test @@ -0,0 +1,10 @@ +2000/01/01 Post-transaction balance + A $5.00 = $5.00 + B + +test bal + $5.00 A + $-5.00 B +-------------------- + 0 +end test |