hledger/tests/journal/balance-assertions.test
2016-02-19 17:52:40 -08:00

139 lines
1.9 KiB
Plaintext
Executable File

#!/usr/bin/env shelltest
# 1. test some balance assertions
hledger -f - stats
<<<
2013/1/1
a $1 =$1
b =-$1
2013/1/2
a $1 =$2
b $-1 =$-2
2013/1/3
a $1 = $3
b $-1 = $-3
(b) $1 = $-2
>>> /Transactions/
>>>2
>>>=0
# 2. same entries as 1 but different parse order, assertion should still pass based on date
hledger -f - stats
<<<
2013/1/1
a $1 =$1
b =-$1
2013/1/3
a $1 = $3
b $-1 = $-3
(b) $1 = $-2
2013/1/2
a $1 =$2
b $-1 =$-2
>>> /Transactions/
>>>2
>>>=0
# 3. like 1 but switch order of postings in last entry,
# assertion should fail and exit code should be non zero
hledger -f - stats
<<<
2013/1/1
a $1 =$1
b =-$1
2013/1/2
a $1 =$2
b $-1 =$-2
2013/1/3
a $1 = $3
(b) $1 = $-2
b $-1 = $-3
>>>
>>>2 /balance assertion failed on 2013\/01\/03/
>>>=1
# 4. should also work without commodity symbols
hledger -f - stats
<<<
2013/1/1
(a) 1 =1
>>> /Transactions/
>>>2
>>>=0
# 5. should work for fractional amount with trailing zeros
hledger -f - stats
<<<
2013/1/1
a $1.20 =$1.20
b =-$1.20
2013/1/2
a $0.10 =$1.3
b =-$1.3
2013/1/3
a $0.7 =$2
b =-$2
>>> /Transactions/
>>>2
>>>=0
# 6. assertions currently check only a single commodity's balance, like Ledger
hledger -f - stats
<<<
1/2
(a) A1
(a) B1 = A1
(a) 0 = A1
(a) C0 = D0
>>> /Transactions/
>>>2
>>>=0
# 7. balances should accumulate (#195)
hledger -f - stats
<<<
1/1
(a) 1F = 1F
(a) 2G = 2G
1/2
(a) 3F = 4F
>>> !/assertion failed/
>>>2
>>>=0
# 8. what should happen here ? Currently,
# in a, 3.4 EUR @@ $5.6 and -3.4 EUR cancel out (wrong ?)
# in b,
#
# hledger -f - stats
# <<<
# 2013/1/1
# a $1.20
# a 3.4 EUR @@ $5.6
# b
# 2013/1/2
# a -3.4 EUR
# b
# 2013/1/3
# a $0.1 =$1.30
# b =-$1.30
# >>> /Transactions/
# >>>2
# >>>=0