hledger/tests/journal/numbers.test
Simon Michael 0b380971f7 journal: require a decimal point in commodity/format/D directives
A commodity directive that doesn't specify the decimal point character
increases ambiguity and the chance of misparsing numbers, especially
as it overrides all style information inferred from the journal amounts.
In some cases it caused amounts with a decimal point to be parsed as if
with a digit group separator so 1.234 became 1234.

We could augment it with extra info from the journal amounts, when available,
but it would still be possible to be ambiguous, and that won't be obvious.

A commodity directive is what we recommend to nail down the style.
It seems the simple and really only way to do this reliably is to require
an explicit decimal point character. Most folks probably do this already.

Unfortunately, it makes another potential incompatiblity with ledger and
beancount journals. But the error message will be clear and easy to
work around.
2018-04-20 21:56:06 -07:00

224 lines
3.0 KiB
Plaintext

# 1. Simple case
hledger bal -f - --no-total
<<<
2017/1/1
a 1,000.00 EUR
b -1,000.00 EUR
>>>
1,000.00 EUR a
-1,000.00 EUR b
>>>2
>>>=0
# 2. No digits before decimal sep
hledger bal -f - --no-total
<<<
2017/1/1
a .01 EUR
b
>>>
0.01 EUR a
-0.01 EUR b
>>>2
>>>=0
# 3. No digits after decimal sep
hledger bal -f - --no-total
<<<
2017/1/1
a 1. EUR
b
>>>
1 EUR a
-1 EUR b
>>>2
>>>=0
# 4. No digits at all
hledger bal -f -
<<<
2017/1/1
a . EUR
b
>>>
>>>=1
# 5. Space between digits groups
hledger bal -f - --no-total
<<<
2017/1/1
a 1 000.00 EUR
b -1 000.00 EUR
>>>
1 000.00 EUR a
-1 000.00 EUR b
>>>2
>>>=0
# 6. Space between digits groups in commodity directive
hledger bal -f - --no-total
<<<
commodity 1 000.00 EUR
2017/1/1
a 1,000.00 EUR
b -1,000.00 EUR
>>>
1 000.00 EUR a
-1 000.00 EUR b
>>>2
>>>=0
# 7. Default commodity
hledger bal -f -
<<<
D 1,000.00 EUR
2017/1/1
a 1,000
b -1,000 EUR
>>>
1,000.00 EUR a
-1,000.00 EUR b
--------------------
0
>>>2
>>>=0
# 8. Omitted decimals
hledger bal -f -
<<<
2017/1/1
a 1,000 EUR
b -1,000.00 EUR
>>>
>>>=1
# 9. Omitted decimals with commodity hint
hledger bal -f -
<<<
commodity 1,000.00 EUR
2017/1/1
a 1,000 EUR
b -1,000.00 EUR
>>>
1,000.00 EUR a
-1,000.00 EUR b
--------------------
0
>>>2
>>>=0
# 10. Omitted decimals with commodity hint and symbol on left
hledger bal -f -
<<<
commodity €1,000.00
2017/1/1
a €1,000
b €-1,000.00
>>>
€1,000.00 a
€-1,000.00 b
--------------------
0
>>>2
>>>=0
# 11. Commodity directive requires a decimal point
hledger bal -f -
<<<
commodity 1000 EUR
>>>2 /please include a decimal point/
>>>=1
# 12. Commodity directive with zero precision
hledger bal -f -
<<<
commodity 100. EUR
2017/1/1
a 1,000 EUR
b -1,000.00 EUR
>>>
1000 EUR a
-1000 EUR b
--------------------
0
>>>2
>>>=0
# 13. Big prices
hledger bal -f - --no-total
<<<
2017/1/1
a -1 BTC @ 24,840 UAH
b 24,840.00 UAH
>>>
>>>=1
# 14. Big prices with commodity hint
hledger bal -f - --no-total
<<<
commodity ₴1,000.00
2017/1/1
a -1 BTC @ ₴24,840
b ₴24,840.00
>>>
-1 BTC a
₴24,840.00 b
>>>2
>>>=0
# 15. adjacent punctuation chars
hledger bal -f -
<<<
2017/1/1
a 1,,0,,0.0 EUR
b -1..0..0,0 EUR
>>>
>>>=1
# 16. adjacent punctuation chars of different types
hledger bal -f -
<<<
2017/1/1
a 1,0,.0 EUR
b -1.0.,0 EUR
>>>
>>>=1
# 17. separator chars vary
hledger bal -f -
<<<
2017/1/1
a 1.0,0.0,0 EUR
b -1,0.0,0.0 EUR
>>>
>>>=1
# 18. number begins with a decimal char
hledger bal -f -
<<<
2017/1/1
a .1 EUR
b -.1 EUR
>>>
0.1 EUR a
-0.1 EUR b
--------------------
0
>>>2
>>>=0
# 19. number begins with a separator char
hledger bal -f -
<<<
2017/1/1
a ,100.0 EUR
b -,100.0 EUR
>>>
>>>=1