hledger/hledger/test/journal/parse-errors.test
Stephen Morgan 686a0871a9 lib: Make sure fromamount and toamount have opposite signs when inferring prices.
Also change priceInferrerFor so that it would give the correct
(negative) prices when fromamount and toamount have the same sign.
2021-05-02 21:14:36 +10:00

158 lines
3.2 KiB
Plaintext

# Testing parse error messages for accuracy and usefulness.
# A journal with an incomplete date.
<
2018
# XXX depends on the executable being named "hledger" (prepended by GHC.Err.error)
# 1.
$ hledger -f - print
>2
hledger: -:1:5:
|
1 | 2018
| ^
unexpected newline
expecting date separator or digit
>=1
# A journal with an unbalanced transaction.
<
2009/1/1
a 1
# 2. When read from stdin with no reader prefix, the journal reader is used
# (before 1.17, all readers were tried and the timedot reader would succeed),
# giving an unbalanced error in this case.
$ hledger -f - print
>2 /real postings' sum should be 0 but is: 1/
>=1
# 3. We expect to have reference to line number with last posting
# NB: \< and \> match start and end of a word.
$ hledger -f journal:- print
>2 /\<2\>/
>=1
# A posting without two spaces between account and amount.
<
2018/1/1
(a) 1
# 4. hledger doesn't detect this as an error directly, it parses account name "(a) 1" and
# amount 0 here.
$ hledger -f - print -x
2018-01-01
(a) 1 0
>=
# 5. Two (or more) postings with implicit amount cannot be balanced.
<
2018/1/1
a 1
b
c
$ hledger -f journal:- print
>2 /can't have more than one real posting with no amount/
>=1
# 6. Two (or more) virtual postings with implicit amount cannot be balanced.
# (And the error message contains line numbers).
<
2018/1/1
[a] 1
[b]
[c]
$ hledger -f journal:- print
>2 /lines 1-4/
>=1
# 7. Balancing error messages show the recorded precision, not the display precision.
<
2010/1/1
a 1C @ $1.0049
a $-1.000
$ hledger -f- print
>2 /real postings' sum should be 0 but is: \$0.0049/
>=1
# 8. Multiple postings all with the same sign gets a distinct error message.
<
2020-01-01
a 1A
b 1A
$ hledger -f- print
>2 /real postings all have the same sign/
>=1
# 9. Zeros don't trigger the same sign error.
<
2020-01-01
a A 0
b B 0
$ hledger -f- print
2020-01-01
a 0
b 0
>=0
# 10. An inferred multicommodity amount doesn't trigger the same sign error.
<
2020-01-01
a A 1
b B 1
c
$ hledger -f- print
2020-01-01
a A 1
b B 1
c
>=0
# 11. For multiple postings all with the same sign but in different commodities,
# the error should show the original amounts, without inferring transaction prices.
<
2020-01-01
a 1A
b 1B
$ hledger -f- print
>2
hledger: "-" (lines 1-3)
could not balance this transaction:
real postings all have the same sign
2020-01-01
a 1A
b 1B
>=1
# 12. Typical "hledger equity --close" transaction does not trigger sign error.
<
2019-01-01 opening balances
assets:a1 $3
assets:a2 £10
equity:opening/closing balances
2019-12-31 closing balances
assets:a1 $-3 = $0.00
assets:a2 £-10 = £0.00
equity:opening/closing balances
$ hledger -f- print
2019-01-01 opening balances
assets:a1 $3
assets:a2 £10
equity:opening/closing balances
2019-12-31 closing balances
assets:a1 $-3 = $0.00
assets:a2 £-10 = £0.00
equity:opening/closing balances
>=0