hledger/tests/prices.test

173 lines
4.5 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 €-100 @ $1.35
>>>=0
# 2. convert to 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. with a historical price directive
bin/hledger -f- print -B
<<<
P 2010/12/31 € $1.34
P 2011/01/01 € $1.35
P 2011/01/02 € $1.36
2011/01/01
expenses:foreign currency €100
assets
>>>
2011/01/01
expenses:foreign currency $135.00
assets $-135.00
>>>=0
# 4. 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 €-100 @@ $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