279 lines
4.4 KiB
Plaintext
279 lines
4.4 KiB
Plaintext
# * add command
|
|
# Note the use of $$ to uniquify temp files, needed since tests run concurrently.
|
|
##############################################################################
|
|
# data validation
|
|
#
|
|
# ** 1. should prompt again for a bad date
|
|
<
|
|
2009/1/32
|
|
$ hledger -f $$-add.j add; rm -f $$-add.j
|
|
> /A valid hledger smart date is required/
|
|
>2 //
|
|
|
|
# ** 2. should accept a blank date
|
|
<
|
|
|
|
$ hledger -f $$-add.j add; rm -f $$-add.j
|
|
> /Date .*Description:/
|
|
>2 //
|
|
|
|
##############################################################################
|
|
# precision and commodity handling
|
|
#
|
|
# ** 3. simple add with no existing journal, no commodity entered
|
|
<
|
|
|
|
|
|
a
|
|
1000.0
|
|
b
|
|
|
|
.
|
|
$ hledger -f $$-add.j add; rm -f $$-add.j
|
|
> /Date.*Description.*Account 1.*Amount 1.*Account 2.*Amount 2.*Account 3.*or \. or enter to finish.*/
|
|
>2 //
|
|
|
|
# ** 4. default commodity with greater precision does not alter entered precision
|
|
<
|
|
|
|
|
|
a
|
|
A1000.0
|
|
b
|
|
|
|
.
|
|
|
|
$ printf 'D A1000.00\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
|
> /a +A1000\.0/
|
|
>2 //
|
|
|
|
# ** 5. default commodity with less precision does not alter entered precision
|
|
<
|
|
|
|
|
|
a
|
|
A1000.00
|
|
b
|
|
|
|
.
|
|
|
|
$ printf 'D A1000.0\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
|
> /a +A1000\.00/
|
|
>2 //
|
|
|
|
# ** 6. default commodity symbol is not added when not provided (#815)
|
|
<
|
|
|
|
|
|
a
|
|
1000
|
|
b
|
|
|
|
.
|
|
|
|
$ printf 'D A1000.00\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
|
> /a +1000/
|
|
>2 //
|
|
|
|
# ** 7. existing commodity with greater precision
|
|
<
|
|
|
|
|
|
a
|
|
A1000.0
|
|
b
|
|
|
|
.
|
|
$ printf '2010/1/1\n a A1000.00\n b\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
|
> /a +A1000\.0/
|
|
>2 //
|
|
|
|
# ** 8. existing commodity with less precision
|
|
<
|
|
|
|
|
|
a
|
|
A1000.00
|
|
b
|
|
|
|
.
|
|
|
|
$ printf '2010/1/1\n a A1000.0\n b\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
|
|
> /a +A1000\.00/
|
|
>2 //
|
|
|
|
# ** 9. default amounts should not fail to balance due to precision
|
|
<
|
|
2010/1/1
|
|
x
|
|
a
|
|
0.25
|
|
b
|
|
0.5
|
|
c
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /Amount 3 \[-0.75\]:/
|
|
>2 //
|
|
|
|
# ** 10. Balance assertions with ==
|
|
|
|
<
|
|
2025-05-01
|
|
x
|
|
a
|
|
50 USD
|
|
b
|
|
-50 USD == 50 USD
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> //
|
|
>2 /Balance assertion failed in b/
|
|
|
|
# ** 11. Balance assertions with =
|
|
|
|
<
|
|
2025-05-01
|
|
x
|
|
a
|
|
10 USD
|
|
a
|
|
10 EUR
|
|
a
|
|
-10 EUR = 0 EUR
|
|
a
|
|
-10 USD = 0 USD
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /Save this transaction to the journal/
|
|
>2 //
|
|
|
|
# ** 12. Assertions with subaccounts
|
|
|
|
<
|
|
2025-05-01
|
|
x
|
|
a:b
|
|
1000 JPY
|
|
a
|
|
-500 JPY ==* 500 JPY
|
|
c
|
|
-500 JPY
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /Save this transaction to the journal/
|
|
>2 //
|
|
|
|
# ** 13. Assertions with posting dates
|
|
|
|
<
|
|
2025-05-01
|
|
x
|
|
a
|
|
50 USD ; date:2025-05-10
|
|
b
|
|
-50 USD
|
|
.
|
|
y
|
|
2025-05-05
|
|
x2
|
|
a
|
|
10 USD == 10 USD
|
|
c
|
|
-10 USD
|
|
.
|
|
# Check the output with c to make sure we get to the final transaction display
|
|
# (anything generic is also in the first transaction)
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /c[[:space:]]+-10 USD/
|
|
>2 //
|
|
|
|
# ** 14. Multi-commodity subaccount assertions
|
|
<
|
|
2025-05-01
|
|
x
|
|
a:b
|
|
50 EUR
|
|
a:c
|
|
500 MXN
|
|
a
|
|
-50 EUR =* 0 EUR
|
|
a
|
|
-500 MXN =* 0 MXN
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /Save this transaction to the journal/
|
|
>2 //
|
|
|
|
# ** 15. Assertion combined with posting date
|
|
<
|
|
2025-05-10
|
|
x
|
|
(a)
|
|
10
|
|
.
|
|
y
|
|
2025-05-10
|
|
x2
|
|
(a)
|
|
3 = 3 ; date:2025-05-01
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /\(a\)[[:space:]]+3 = 3 ; date:2025-05-01/
|
|
>2 //
|
|
|
|
# ** 16. Verify that -I skips assertions
|
|
<
|
|
2025-05-10
|
|
x
|
|
a
|
|
10 USD = 20 USD
|
|
b
|
|
-10 USD
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal -I add; rm -f nosuch.$$.journal
|
|
> /Save this transaction to the journal/
|
|
>2 //
|
|
|
|
# ** 17. Partial dates in added transaction
|
|
<
|
|
2025-05-01
|
|
x
|
|
a
|
|
10 USD ; date:5/2
|
|
b
|
|
-10 USD
|
|
.
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> /Save this transaction to the journal/
|
|
>2 //
|
|
|
|
# ** 18. add checks existing assertions
|
|
<
|
|
2025-05-10
|
|
x
|
|
a
|
|
10 USD == 10 USD
|
|
b
|
|
-10 USD
|
|
.
|
|
y
|
|
2025-05-01
|
|
x
|
|
a
|
|
10 USD
|
|
$ rm -f nosuch.$$.journal; hledger -f nosuch.$$.journal add; rm -f nosuch.$$.journal
|
|
> //
|
|
>2 /Balance assertion failed in a/
|
|
|
|
|
|
## 18. shouldn't add decimals if there aren't any
|
|
## printf '\n\na\n1\nb\n' | hledger -f /dev/null add
|
|
# <
|
|
#
|
|
#
|
|
# a
|
|
# 1
|
|
# b
|
|
# $ hledger -f /dev/null add
|
|
# > /amount 2 \[-1\]/
|