Skip to content

Commit

Permalink
Fix Bug 1147: Check balance assertions against the amount AFTER
Browse files Browse the repository at this point in the history
  • Loading branch information
mk12 committed Mar 23, 2016
1 parent 16c2b8d commit 4d207e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/textual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 12 additions & 0 deletions test/regress/1147-a.test
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/regress/1147-b.test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4d207e3

Please sign in to comment.