hledger/tests/journal/valuation2.test
2020-01-07 15:58:54 -08:00

224 lines
4.6 KiB
Plaintext

# More valuation tests. See also valuation.test.
; some market prices
P 2019-01-01 B 10 A
P 2019-01-01 C 2 B
P 2019-01-01 A 100 D
P 2019-01-01 E 3 D
; a transaction with both amounts in B
2019-06-01
a 1 B
b
; tests follow. This comment directive makes this file readable
; by hledger, as well as shelltest; useful when troubleshooting.
comment
# 1. normal unvalued output
$ hledger -f- print -x
2019-06-01
a 1 B
b -1 B
>=
# 2. current market value in default valuation commodity
$ hledger -f- print -x -V
2019-06-01
a 10 A
b -10 A
>=
# 3. same as above, but request commodity A explicitly
$ hledger -f- print -x --value=now,A
2019-06-01
a 10 A
b -10 A
>=
# 4. request commodity B - no effect
$ hledger -f- print -x --value=now,B
2019-06-01
a 1 B
b -1 B
>=
# 5. request commodity we don't have prices for - no effect
$ hledger -f- print -x --value=now,Z
2019-06-01
a 1 B
b -1 B
>=
# 6. request commodity C - uses reverse of C->B price.
# There's nothing setting C display style, so the default style is used,
# which shows no decimal digits.
# And because that makes it display as zero, the commodity symbol
# and sign are not shown either.
$ hledger -f- print -x --value=now,C
2019-06-01
a 0
b 0
>=
# # There's nothing setting C display style, so the default style is used,
# # but the precision is increased to show the decimal digit
# # (otherwise it would show C0).
# $ hledger -f- print -x --value=now,C
# 2019-06-01
# a C0.5
# b C-0.5
#
# >=
# 7. request commodity D - chains B->A, A->D prices
$ hledger -f- print -x --value=now,D
2019-06-01
a 1000 D
b -1000 D
>=
# 8. request commodity E - chains B->A, A->D, reverse of D->E prices.
# As with C above, E gets the default display style, with precision 0.
$ hledger -f- print -x --value=now,E
2019-06-01
a E333
b E-333
>=
# # As with C above, E gets the default display style, but with the precision
# # increased to show the decimal digits, but no more than 8.
# $ hledger -f- print -x --value=now,E
# 2019-06-01
# a E333.33333333
# b E-333.33333333
#
# >=
# Document some print behaviour.
# I think I've forgotten some other weird cases meant for here.
# First an example with no market price, just a transaction price.
<
2000/01/01
a -1A @ 1B
b 1B
# 9. Normal print output.
$ hledger -f- print
2000-01-01
a -1A @ 1B
b 1B
>=0
# 10. Valuing in a commodity with no market price has no effect.
$ hledger -f- print -XZ
2000-01-01
a -1A @ 1B
b 1B
>=0
# 11. -B converts to the transaction price's commodity.
$ hledger -f- print -B
2000-01-01
a -1B
b 1B
>=0
# 12. Note the -XZ nullifies the -B here, because both are forms of --value
# (-B -XZ is equivalent to --value=cost --value=end,Z), and the rightmost wins.
$ hledger -f- print -B -XZ
2000-01-01
a -1A @ 1B
b 1B
>=0
# With a market price: same as above.
<
P 2000/1/1 A 1B
2000/01/01
a -1A @ 1B
b 1B
# 13.
$ hledger -f- print
2000-01-01
a -1A @ 1B
b 1B
>=0
# 14.
$ hledger -f- print -XZ
2000-01-01
a -1A @ 1B
b 1B
>=0
# 15.
$ hledger -f- print -B
2000-01-01
a -1B
b 1B
>=0
# 16.
$ hledger -f- print -B -XZ
2000-01-01
a -1A @ 1B
b 1B
>=0
# A few more tests for -V (and -X, which should work similarly). #1083.
<
P 2000/01/01 A 2 B
P 2002/01/01 A 3 B
2000/01/01
(a) 1 A
# 17. -V uses today as the default valuation date, unlike --value=end.
$ hledger -f- reg -V
2000-01-01 (a) 3 B 3 B
# 18. -V uses the report end date, if specified, as valuation date.
$ hledger -f- reg -V -e 2001
2000-01-01 (a) 2 B 2 B
# 19. In balance reports too.
$ hledger -f- bal -N -V
3 B a
# 20.
$ hledger -f- bal -N -V -e 2001
2 B a
#
<
P 2001/01/01 A 1 B
P 2002/01/01 A 2 B
2000-01-01
(a) 1 A
# 21. The valuation date is the last day of the report period. In
# other words, the report end date is exclusive with respect to price
# directives. This is a change from older hledger and Ledger, where it
# was inclusive.
$ hledger -f- bal -N -V -e 2002-01-01
1 B a