2011-08-05 04:05:39 +04:00
|
|
|
# alias-related tests
|
|
|
|
|
2015-05-28 20:39:12 +03:00
|
|
|
# simple aliases
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 1. simple alias directive
|
|
|
|
<
|
2015-05-14 22:50:32 +03:00
|
|
|
alias checking = assets:bank:checking
|
|
|
|
1/1
|
|
|
|
(checking:a) 1
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- accounts
|
2015-05-14 22:50:32 +03:00
|
|
|
assets:bank:checking:a
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 2. simple alias matches whole account name components only
|
|
|
|
<
|
2015-05-14 22:50:32 +03:00
|
|
|
alias a:b = A:B
|
|
|
|
1/1
|
|
|
|
(a:b:c) 1 ; should match this
|
|
|
|
1/1
|
|
|
|
(a:bb:d) 1 ; should not match this
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- accounts
|
2015-05-14 22:50:32 +03:00
|
|
|
A:B:c
|
|
|
|
a:bb:d
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 3. a simple alias matching the whole account name works
|
|
|
|
<
|
2015-05-28 20:39:12 +03:00
|
|
|
alias a:b = A:B
|
|
|
|
1/1
|
|
|
|
(a:b) 1
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- accounts
|
2015-05-28 20:39:12 +03:00
|
|
|
A:B
|
|
|
|
|
|
|
|
# regular expression aliases
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 4. regex alias directive
|
|
|
|
<
|
2015-05-14 22:50:32 +03:00
|
|
|
alias /^(.+):bank:([^:]+):?(.*)/ = \1:\2 \3
|
|
|
|
1/1
|
|
|
|
(assets:bank:B:checking:a) 1
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- accounts
|
2015-05-14 22:50:32 +03:00
|
|
|
assets:B checking:a
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 5. regex alias pattern is a case-insensitive regular expression
|
2015-05-14 22:50:32 +03:00
|
|
|
# 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.
|
2014-10-25 02:05:10 +04:00
|
|
|
#
|
2019-06-19 20:42:10 +03:00
|
|
|
<
|
2015-05-14 22:50:32 +03:00
|
|
|
alias /a/ = b
|
2014-10-25 02:05:10 +04:00
|
|
|
|
2011-08-05 04:05:39 +04:00
|
|
|
2011/01/01
|
2014-10-25 02:05:10 +04:00
|
|
|
A a 1
|
|
|
|
a a 2
|
|
|
|
c
|
|
|
|
|
2015-05-14 22:50:32 +03:00
|
|
|
alias /A (.)/=\1
|
2014-10-25 02:05:10 +04:00
|
|
|
|
|
|
|
2011/01/01
|
|
|
|
A a 1
|
|
|
|
a a 2
|
2011-08-05 04:05:39 +04:00
|
|
|
c
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- print
|
2011-08-05 04:05:39 +04:00
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
b b 1
|
|
|
|
b b 2
|
2017-01-13 18:25:44 +03:00
|
|
|
c
|
2014-10-25 02:05:10 +04:00
|
|
|
|
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
b 1
|
|
|
|
b 2
|
2017-01-13 18:25:44 +03:00
|
|
|
c
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
>=0
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2015-05-28 20:39:12 +03:00
|
|
|
# CLI
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 6. --alias command-line options are applied in the order written.
|
2015-05-14 22:50:32 +03:00
|
|
|
# Spaces are allowed if quoted.
|
2014-10-25 02:05:10 +04:00
|
|
|
#
|
2019-06-19 20:42:10 +03:00
|
|
|
<
|
2011-08-05 04:05:39 +04:00
|
|
|
2011/01/01
|
2014-10-25 02:05:10 +04:00
|
|
|
a a 1
|
|
|
|
A a 2
|
|
|
|
c
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- print --alias '/A (.)/=a' --alias /a/=b
|
2011-08-05 04:05:39 +04:00
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
b 1
|
|
|
|
b 2
|
2017-01-13 18:25:44 +03:00
|
|
|
c
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
>=0
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 7. alias options are applied after alias directives.
|
2014-10-25 02:05:10 +04:00
|
|
|
#
|
2019-06-19 20:42:10 +03:00
|
|
|
<
|
2015-05-14 22:50:32 +03:00
|
|
|
alias /^a/=B
|
|
|
|
alias /^a/=E
|
2014-10-25 02:05:10 +04:00
|
|
|
alias E=F
|
2011-08-05 04:05:39 +04:00
|
|
|
|
|
|
|
2011/01/01
|
|
|
|
[a:x] 1
|
|
|
|
[x:a:x]
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- print --alias /a/=A --alias /B/=C --alias /B/=D --alias /C/=D
|
2011-08-05 04:05:39 +04:00
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
[E:x] 1
|
2017-01-13 18:25:44 +03:00
|
|
|
[x:A:x]
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
>=0
|
2017-01-13 19:02:11 +03:00
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 8. alias options
|
|
|
|
<
|
2018-04-18 01:58:53 +03:00
|
|
|
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
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- balance --alias=cc=credit-card --alias=b=bank
|
2018-04-18 01:58:53 +03:00
|
|
|
75 bank
|
|
|
|
15 expenses
|
|
|
|
--------------------
|
|
|
|
90
|
|
|
|
|
2019-06-19 20:42:10 +03:00
|
|
|
# 9. query will search both origin and substitution in alias
|
|
|
|
<
|
2017-01-13 19:02:11 +03:00
|
|
|
alias a = b
|
2018-01-02 02:47:31 +03:00
|
|
|
2017/1/1
|
2017-01-13 19:02:11 +03:00
|
|
|
a 1
|
|
|
|
b -1
|
2019-06-19 20:42:10 +03:00
|
|
|
$ hledger -f- reg '^a$' '^b$'
|
2017-01-13 19:02:11 +03:00
|
|
|
2017/01/01 b 1 1
|
|
|
|
b -1 0
|
2019-06-21 22:16:56 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|