# * Amounts, commodity symbols, commodity directives, amount styles.. 

# ** 1. decimal point/digit grouping chars are autodetected, 
# separately for each commodity, which can be surprising. TODO
# So hledger parses 1 XAU at 1000 USD here:
<
1/1
    assets:gold  1,000 XAU @ 1,000.00 USD
    equity 
$ hledger -f - bal --flat --no-total -B
        1,000.00 USD  assets:gold
       -1,000.00 USD  equity

# while ledger parses 1000 XAU at 1000 USD each:
# $ ledger bal --flat --no-total -B
#           USD1000000  assets:gold
#          USD-1000000  equity)

# a commodity may contain/end with numbers, if double quoted
# ** 2. without quotes, fail. XXX parse error should be clearer here
<
2010-04-05 x
   a   10 DE0002635307
   b
$ hledger -f- print
>2 /unexpected/
>= 1

# ** 3. with quotes, ok; quotes appear in print output
<
2010-04-05 x
   a   10 "DE 0002 635307"
   b
$ hledger -f- print --explicit
2010-04-05 x
    a     10 "DE 0002 635307"
    b    -10 "DE 0002 635307"

>=

# ** 4. and in other reports too, I guess
$ hledger -f- balance
 10 "DE 0002 635307"  a
-10 "DE 0002 635307"  b
--------------------
                   0  

# ** 5. autobalance with prices
<
2016/1/1
    saving-card  $-105
    snacks  95 EUR @@ $100
    Equity:Unbalanced

$ hledger -f- print -x
2016-01-01
    saving-card                   $-105
    snacks               95 EUR @@ $100
    Equity:Unbalanced                $5

>=

# ** 6. The four decimal places of the market price should not alter the
# canonical style of two decimal places in a's converted-to-B balance
# (#295), but it turns out they do with -V. This can be fixed with a
# commodity directive.
<
; use a commodity directive to ensure B is displayed with two decimal
; places, or the price directive plus -V would make it four
commodity 1.00 B

P 2015/1/1 A 1.0001 B

2015/1/1
    (a)  1.00 A
    (b)  1.00 B
$ hledger -f- bal -V -N
              1.00 B  a
              1.00 B  b

# ** 7. A multi-line commodity directive also works.
<
commodity B
  format 1.00 B

P 2015/1/1 A 1.0001 B

2015/1/1
    (a)  1.00 A
    (b)  1.00 B

$ hledger -f- bal -V -N
              1.00 B  a
              1.00 B  b

# TODO
# ** 8. From the first amount it should detect that decimal point is period, 
# from the second it should detect that there are comma-separated digit groups of size 3,
# giving commodity A a canonical style of 1,000.00 A.
#<
#2015/1/1
#    (a)  1000.00 A
#
#2015/1/1
#    (a)    1,000 A
#
#$ hledger -f- print
#2015-01-01
#    (a)    1,000.00 A
#
#2015-01-01
#    (a)    1,000.00 A
#
#>=

# TODO #749

# ** 8. Here the amount is parsed as 1. I think (hope) no country uses space 
# for decimal point, so we should parse this as 1000.
<
2018-01-01
 (a)   USD1 000

$ hledger -f- reg amt:1

# ** 9. This commodity directive should complain about a missing decimal separator,
# which we now require.
<
commodity 1 000  USD

2018-01-01
  (a)   USD1 000

$ hledger -f- bal
>2 /decimal point or decimal comma/
>=1

# ** 10. After a space-grouped amount, a posting comment should parse.
<
2018-01-01
  (a)   USD 1 000  ;comment

$ hledger -f- print
> //    # any stdout, no stderr, 0 exit code

# ** 11. After a space-grouped amount, trailing whitespace should parse.
<
2018-01-01
  (a)   USD 1 000 

$ hledger -f- print
> //    # any stdout, no stderr, 0 exit code

# ** 12. After commodity on the right, don't parse tab
<
2020-07-21
	a    	-1600 EUR
	a		1600 EUR	
	
; import Stock value at 2020-07-22
2020-07-21 
	a 	-1 EUR  
	a 	 1 EUR	
$ hledger -f- bal a
--------------------
                   0  
>=

# ** 12. Example of surprising decimal mark parsing behaviour.
# Without a commodity declaration, these amounts are parsed as 10 and 10000.
# <
# 2000/1/1
#     a                $-10,000
#     b                 $10,000.00
#
# $ hledger -f- print
# could not balance this transaction (real postings are off by $9,990,000)
# 2000-01-01
#     a        $-10,000
#     b     $10,000,000

# ** 13. A commodity's display style should come from the first-parsed amount
<
2020-01-01
    (a)            1.00 $

2020-01-02
    (b)            $2,00

$ hledger -f - print
2020-01-01
    (a)          1.00 $

2020-01-02
    (b)          2.00 $

>=

# ** 14. Balance assertion amounts are always displayed at their full precision,
# overriding commodity styles. (#1465)
<
commodity A 1.

2021-01-01
  (a)   0.001A
  (a)   1.122A = 1.123A
$ hledger -f - print
2021-01-01
    (a)         A 0.001
    (a)         A 1.122 = A 1.123

>=

# The current state of parse errors when commodity symbols containing non-letters 
# are not quoted. (#1532)

# ** 15. Unquoted commodity symbol on the left, gives this long error message.
<
2021-01-01
  (a)   A1B 2

$ hledger -f- print cur:A1B amt:2
>2 /unexpected 'B'/
>=1

# ** 16. Unquoted commodity symbol on the right, gives this long error message.
<
2021-01-01
  (a)   1 A2

$ hledger -f- print cur:A1 amt:2
>2 /unexpected '2'/
>=1

# ** 17. Unquoted commodity symbol on the left ending with numbers, could parse successfully.
<
; A 12
2021-01-01
  (a)   A1 2

$ hledger -f- print cur:A amt:12
2021-01-01
    (a)           A1 2.

>=

# ** 18. Unquoted commodity symbol on the right beginning with numbers, could parse successfully.
<
; intended 1 "2A", parses as 12 A
2021-01-01
  (a)   1 2A

$ hledger -f- print cur:A amt:12
2021-01-01
    (a)           1 2.A

>=

# ** 19. Unquoted commodity symbol on the left ending with numbers and E/e (exponent), unspaced, 
# could parse successfully.

<
; intended "A1E" 2, parses as A 1E2
2021-01-01
  (a)   A1E2

$ hledger -f- print cur:A amt:100
2021-01-01
    (a)            A100

>=

# ** 20. Unquoted commodity symbol on the right beginning with E and numbers, unspaced, 
# could parse successfully.

<
; intended 1 "e2e", parses as 1e2 e
2021-01-01
  (a)   1e2e

$ hledger -f- print cur:e amt:100
2021-01-01
    (a)            100e

>=

# ** 21. Unquoted commodity symbol on the left consisting of only numbers.
# It could happen..
<
; intended "111" 2, parses as 1112.
2021-01-01
  (a)   111 2

$ hledger -f- print cur: amt:1112
2021-01-01
    (a)          111 2.

>=

<
P 2021-01-01 A  1000 B
2021-01-01
  (a)    1 A

2021-01-02
  (a)   10 A

2021-01-03
  (a)   10 A @ 0.1 B

2021-01-04
  (a)    1 B @ 0.001 A

2021-01-05
  (a)    1 B

# ** 22. balance report cur: and amt: query matches currency before valuation/cost
$ hledger -f- balance -N -V -B cur:A "amt:<5"
              1000 B  a
>=

# ** 23. register report cur: and amt: query matches currency before valuation/cost
$ hledger -f- register -V -B cur:A "amt:<5"
2021-01-01                      (a)                         1000 B        1000 B
>=

# ** 24. aregister report cur: and amt: query matches currency before valuation/cost
$ hledger -f- aregister a -V -B cur:A "amt:<5"
Transactions in a and subaccounts (matching query):
2021-01-01                      a                           1000 B        1000 B
>=

# ** 25. print report cur: and amt: query matches currency before valuation/cost
$ hledger -f- print -V -B a cur:A "amt:<5"
2021-01-01
    (a)          1000 B

>=
