hledger/tests/prices.test

203 lines
5.0 KiB
Plaintext

# price-related tests
# 1. print a transaction with an explicit unit price
bin/hledger -f- print
<<<
2011/01/01
expenses:foreign currency €100 @ $1.35
assets
>>>
2011/01/01
expenses:foreign currency €100 @ $1.35
assets $-135.00
>>>=0
# 2. -B/--cost converts to the price's commodity ("cost")
bin/hledger -f- print --cost
<<<
2011/01/01
expenses:foreign currency €100 @ $1.35
assets
>>>
2011/01/01
expenses:foreign currency $135.00
assets $-135.00
>>>=0
# 3. -B should ignore historical price directives
bin/hledger -f- print -B
<<<
P 2011/01/01 € $1.35
2011/01/01
expenses:foreign currency €100
assets
>>>
2011/01/01
expenses:foreign currency €100
assets €-100
>>>=0
# 4. print a transaction with a total price
bin/hledger -f - print
<<<
2011/01/01
expenses:foreign currency €100 @@ $135
assets
>>>
2011/01/01
expenses:foreign currency €100 @@ $135
assets $-135
>>>=0
# 5. when the balance has exactly two commodities, both unpriced, infer an
# implicit conversion price for the first one in terms of the second.
bin/hledger -f - print
<<<
2011/01/01
expenses:foreign currency €100
misc $2.1
assets $-135.00
misc €1
misc €-1
misc $-2.1
>>>
2011/01/01
expenses:foreign currency €100 @ $1.35
misc $2.10
assets $-135.00
misc €1 @ $1.35
misc €-1 @ $1.35
misc $-2.10
>>>=0
# # 6. when the *cost-basis* balance has exactly two commodities, both
# # unpriced, infer an implicit conversion price for the first one in terms
# # of the second.
# bin/hledger -f - print
# <<<
# 2011/01/01
# expenses:foreign currency €100
# assets $-135.00
# misc $3.1 @ 2 bob
# misc $-3.1 @ 2 bob
# misc £1 @@ 2 shekels
# misc £-1 @@ 2 shekels
# >>>
# 2011/01/01
# expenses:foreign currency €100 @ $1.35
# assets €-100 @ $1.35
# misc $3.1 @ 2 bob
# misc $-3.1 @ 2 bob
# misc £1 @@ 2 shekels
# misc £-1 @@ 2 shekels
#
## 7. another, from ledger tests. Just one posting to price so uses @@.
bin/hledger -f - print
<<<
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
>>>
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG @@ $17,783.72
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
>>>=0
# 8. when the balance has more than two commodities, don't bother
bin/hledger -f - print
<<<
2011/01/01
expenses:foreign currency €100
assets $-135
expenses:other £200
>>>= !0
# 9. another
bin/hledger -f - balance -B
<<<
2011/01/01
expenses:foreign currency €99
assets $-130
expenses:foreign currency €1
assets $-5
>>>
$-135 assets
$135 expenses:foreign currency
--------------------
0
>>>=0
# 10. transaction in two commodities should balance out properly
bin/hledger -f - balance --cost
<<<
2011/01/01 x
a 10£ @@ 16$
b
>>>
16$ a
-16$ b
--------------------
0
>>>=0
# 11. When commodity price is specified implicitly, transaction should
# be considered balanced out even when first amount is negative
# (that is, price for it should be determined properly, with proper sign)
bin/hledger -f - balance
<<<
2011/01/01 x
a -10£
b 16$
>>>
-10£ a
16$ b
--------------------
16$
-10£
>>>=0
# 12. When commodity price is specified implicitly, transaction should
# NOT be considered balanced out when BOTH amounts are negative
bin/hledger -f - balance
<<<
2011/01/01 x
a -10£
b -16$
>>>
>>>=1
# 13. Differently-priced lots of a commodity should be merged in balance report
bin/hledger -f - balance
<<<
2011/1/1
(a) £1 @ $2
2011/1/1
(a) £1 @ $3
>>>
£2 a
--------------------
£2
>>>=0
# 14. this should balance
bin/hledger -f - balance
<<<
2011/1/1
a 1h @ $10
b 1h @ $20
c $-30
>>>= 0
# 15. this should balance, ignoring the P
bin/hledger -f - balance
<<<
P 2011/11/15 EUR CHF 1.234
2011/11/19
a EUR 1000.00
b CHF -1254
>>>= 0