#!/usr/bin/env shelltest # balance assertion & balance assignment tests # 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.*line 11, column 12/ >>>=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 # 8. resetting a balance hledger -f - stats <<< 2013/1/1 a $1.20 b 2013/1/2 a =$1.3 b 2013/1/2 a $10 =$11.3 b =$-11.3 >>> /Transactions/ >>>2 >>>=0 # 9. Multiple assertions for an account in the same transaction. hledger -f - stats <<< 2013/1/1 a $1 =$1 b =-$1 2013/1/2 a $1 =$2 b $-1 =$-2 2013/1/3 a $2 = $4 b $-1 = $-3 b $-1 = $-4 >>> /Transactions/ >>>2 >>>=0 # 10. Multiple assertions and assignments for an account in the same transaction. hledger -f - stats <<< 2013/1/1 a $1 =$1 b =-$1 2013/1/3 a $6 = $7 b $-1 = $-2 b $-1 = $-3 b $-7 = $-10 b $-1 b $-1 = $-12 b 2013/1/4 a $0 = $7 b $0 = $-7 >>> /Transactions/ >>>2 >>>=0 # 11. Assignments and virtual postings hledger -f - stats <<< 2013/1/1 b [a] 1$ (b) = $14 [b] a 4$ 2013/1/2 [a] = $5 b = $9 >>> /Transactions/ >>>2 >>>=0 # 12. Having both assignments and posting dates is not supported. hledger -f - stats <<< 2013/1/1 a $1 =$1 b =$-1 ; date:2012/1/1 >>>2 /balance assignments may not have a custom date/ >>>=1 # 13. Posting Date hledger -f - stats <<< 2011/5/5 [a] = -10 2013/1/1 a 1 = -12 b c = 5 2014/1/1 a ; date:2012/1/1 d 3 = 3 2015/1/1 [a] ; date:2011/1/1 [d] 10 >>> /Transactions/ >>>2 >>>=0 # 14. Mix different commodities hledger -f - stats <<< 2016/1/1 a $1 b -1 zorkmids 2016/1/2 a $-1 = $0 b >>> /Transactions/ >>>2 >>>=0 # 15. Mix different commodities and assignments hledger -f - stats <<< 2016/1/1 a $1 b -1 zorkmids 2016/1/4 [a] = $1 2016/1/5 [a] = -1 zorkmids 2016/1/2 a b = 0 zorkmids >>> /Transactions/ >>>2 >>>=0 # 16. Total assertions (==) parse correctly hledger -f - stats <<< 2016/1/1 a $1 b 2016/1/2 a == $1 >>> /Transactions/ >>>2 >>>=0 # 17. Total assertions consider entire multicommodity amount hledger -f - stats <<< 2016/1/1 a $1 b 2016/1/2 a 1 zorkmids b 2016/1/3 a 0 == $1 >>>2 /balance assertion.*line 10, column 15/ >>>=1 # 18. Mix different commodities and total assignments hledger -f - stats <<< 2016/1/1 a $1 a -1 zorkmids b 2016/1/2 a == $1 b -1 zorkmids 2016/1/3 b 0 = $-1 b 0 = 0 zorkmids >>> /Transactions/ >>>2 >>>=0 # 19. Balance assertions may have a price, but it's ignored hledger -f- print <<< 2019/01/01 (a) 1A @ 1B = 1A @ 2B >>> 2019/01/01 (a) 1A @ 1B = 1A @ 2B >>>=0 # 20. Balance assignments may have a price, and it's used for the posting amount. # But not shown as part of the balance assertion in the resulting posting. hledger -f- print --explicit <<< 2019/01/01 (a) = 1A @ 2B >>> 2019/01/01 (a) 1A @ 2B = 1A @ 2B >>>=0 # 21. close generates balance assertions without prices hledger -f- close -e 2019/1/2 <<< 2019/01/01 (a) 1A @ 1B = 1A @ 2B >>> 2019/01/01 closing balances a -1A @ 1B = 0A equity:closing balances 2019/01/02 opening balances a 1A @ 1B = 1A equity:opening balances >>>=0 # 22. The exact amounts are compared; display precision does not affect assertions. hledger -f- print <<< commodity $1000.00 2019/01/01 (a) $0.006 2019/01/02 (a) $1.00 = $1.006 >>> /2019/ >>>2 >>>=0 # 23. This fails hledger -f- print <<< commodity $1000.00 2019/01/01 (a) $0.006 2019/01/02 (a) $1.00 = $1.01 >>>2 /difference: 0\.004/ >>>=1 # 24. This fails hledger -f- print <<< commodity $1000.00 2019/01/01 (a) $0.006 2019/01/02 (a) $1.00 = $1.0061 >>>2 /difference: 0\.0001/ >>>=1 # 25. Inclusive assertions include balances from subaccounts. hledger -f- print <<< 2019/1/1 (a) X1 (a) Y3 (a:b) Y7 (a) 0 =* X1 (a) 0 =* Y10 (a:b) 0 =* Y7 (a:b) 0 ==* Y7 >>> 2019/01/01 (a) X1 (a) Y3 (a:b) Y7 (a) 0 =* X1 (a) 0 =* Y10 (a:b) 0 =* Y7 (a:b) 0 ==* Y7 >>>2 >>>=0