hledger/tests/account-aliases.test
2019-07-08 08:28:03 +01:00

228 lines
3.6 KiB
Plaintext

# alias-related tests
# simple aliases
# 1. simple alias directive
<
alias checking = assets:bank:checking
1/1
(checking:a) 1
$ hledger -f- accounts
assets:bank:checking:a
# 2. simple alias matches whole account name components only
<
alias a:b = A:B
1/1
(a:b:c) 1 ; should match this
1/1
(a:bb:d) 1 ; should not match this
$ hledger -f- accounts
A:B:c
a:bb:d
# 3. a simple alias matching the whole account name works
<
alias a:b = A:B
1/1
(a:b) 1
$ hledger -f- accounts
A:B
# regular expression aliases
# 4. regex alias directive
<
alias /^(.+):bank:([^:]+):?(.*)/ = \1:\2 \3
1/1
(assets:bank:B:checking:a) 1
$ hledger -f- accounts
assets:B checking:a
# 5. regex alias pattern is a case-insensitive regular expression
# matching anywhere in the account name. All matching aliases are
# applied to an account name in turn, most recently seen first. The
# replacement can replace multiple matches within the account name.
# The replacement pattern supports numeric backreferences.
#
<
alias /a/ = b
2011/01/01
A a 1
a a 2
c
alias /A (.)/=\1
2011/01/01
A a 1
a a 2
c
$ hledger -f- print
2011/01/01
b b 1
b b 2
c
2011/01/01
b 1
b 2
c
>=0
# CLI
# 6. --alias command-line options are applied in the order written.
# Spaces are allowed if quoted.
#
<
2011/01/01
a a 1
A a 2
c
$ hledger -f- print --alias '/A (.)/=a' --alias /a/=b
2011/01/01
b 1
b 2
c
>=0
# 7. alias options are applied after alias directives.
#
<
alias /^a/=B
alias /^a/=E
alias E=F
2011/01/01
[a:x] 1
[x:a:x]
$ hledger -f- print --alias /a/=A --alias /B/=C --alias /B/=D --alias /C/=D
2011/01/01
[E:x] 1
[x:A:x]
>=0
# 8. alias options
<
01/01 Opening balances
(bank) 100
(credit-card) -10
01/02
expenses 5
cc
01/03
expenses 5
b
01/04 Credit card charge
cc = 0
b
01/05
expenses 5
b = 75
$ hledger -f- balance --alias=cc=credit-card --alias=b=bank
75 bank
15 expenses
--------------------
90
# 9. query will search both origin and substitution in alias
<
alias a = b
2017/1/1
a 1
b -1
$ hledger -f- reg '^a$' '^b$'
2017/01/01 b 1 1
b -1 0
# recursive aliases https://github.com/simonmichael/hledger/issues/1055
# 10. Recursive command line simple aliases.
<
2000/01/01
(one) 1
$ hledger -f- --alias "one=two" --alias "two=three" print
2000/01/01
(three) 1
>=0
# 11. Recursive simple alias directives. Note the reverse order,
# alias directives are applied most recent first (bottom up).
<
alias two = three
alias one = two
2000/01/01
(one) 1
$ hledger -f- print
2000/01/01
(three) 1
>=0
# 12. Only one of these is applied.
<
alias one = three
alias one = two
2000/01/01
(one) 1
$ hledger -f- print
2000/01/01
(two) 1
>=0
# 13. Recursive command line regexp aliases.
<
2000/01/01
(one) 1
$ hledger -f- --alias "/one/=two" --alias "/two/=three" print
2000/01/01
(three) 1
>=0
# 14. Recursive regexp alias directives.
# Alias directives are applied most recent first (bottom up).
<
alias /two/ = three
alias /one/ = two
2000/01/01
(one) 1
$ hledger -f- print
2000/01/01
(three) 1
>=0
# 15. Only one of these is applied.
<
alias /one/ = three
alias /one/ = two
2000/01/01
(one) 1
$ hledger -f- print
2000/01/01
(two) 1
>=0