hledger/tests/accounts-sorting.test

134 lines
1.7 KiB
Plaintext
Raw Normal View History

journal: a new account sorting mechanism, and a bunch of sorting fixes A bunch of account sorting changes that got intermingled. First, account codes have been dropped. They can still be parsed and will be ignored, for now. I don't know if anyone used them. Instead, account display order is now controlled by the order of account directives, if any. From the mail list: I'd like to drop account codes, introduced in hledger 1.9 to control the display order of accounts. In my experience, - they are tedious to maintain - they duplicate/compete with the natural tendency to arrange account directives to match your mental chart of accounts - they duplicate/compete with the tree structure created by account names and it gets worse if you think about using them more extensively, eg to classify accounts by type. Instead, I plan to just let the position (parse order) of account directives determine the display order of those declared accounts. Undeclared accounts will be displayed after declared accounts, sorted alphabetically as usual. Second, the various account sorting modes have been implemented more widely and more correctly. All sorting modes (alphabetically, by account declaration, by amount) should now work correctly in almost all commands and modes (non-tabular and tabular balance reports, tree and flat modes, the accounts command). Sorting bugs have been fixed, eg #875. Only the budget report (balance --budget) does not yet support sorting. Comprehensive functional tests for sorting in the accounts and balance commands have been added. If you are confused by some sorting behaviour, studying these tests is recommended, as sorting gets tricky.
2018-09-23 10:45:07 +03:00
# accounts report sorting.
# 1. Accounts are sorted alphabetically, at each tree level.
# Flat mode. Unused parent accounts are not added (b).
<
2018/1/1
(b:j) 1
2018/1/1
(c) 1
2018/1/1
(b:i) 1
2018/1/1
(a:k) 1
$ hledger -f- acc
a:k
b:i
b:j
c
>=
# 2. Tree mode. Missing parent accounts are added (b).
$ hledger -f- acc --tree
a
k
b
i
j
c
>=
# 3. With account directives, flat mode.
# At each tree level, declared accounts are sorted first, in
# declaration order, followed by undeclared accounts sorted alphabetically.
# Unused parent accounts are not added (b).
# The b:k, b:j declarations affect the subs of b, not b itself.
<
account b:k
account b:j
account d
2018/1/1
(a:l) 1
2018/1/1
(b:i) 1
2018/1/1
(b:j) 1
2018/1/1
(b:k) 1
2018/1/1
(c) 1
2018/1/1
(d) 1
$ hledger -f- acc
d
a:l
b:k
b:j
b:i
c
>=
# 4. With account directives, tree mode.
# Missing parent accounts are added (b).
$ hledger -f- acc --tree
d
a
l
b
k
j
i
c
>=
# 5. With a depth limit:
# deeper accounts are not excluded
# account names are clipped
# empty clipped names are removed
# duplicate clipped names are removed
# non-matched clipped names are removed.
# Flat mode.
$ hledger -f- acc d b l --depth 1
d
b
>=
# # .
# $ hledger -f- acc
# >=
# # .
# $ hledger -f- acc
# >=
# # .
# $ hledger -f- acc
# >=
# # .
# $ hledger -f- acc
# >=
# # .
# $ hledger -f- acc
# >=
# # .
# $ hledger -f- acc
# >=
# # . With --drop: TODO not supported ?
# empty modified names are removed
# duplicate modified names are removed
# non-matched modified names are removed ?
# modified names are sorted somehow ?
# $ hledger -f- acc --drop 1
# l
# k
# j
# i
# >=