From 4dc61e76bfb47293a11a82f0ab61f525759f25e3 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 3 Apr 2014 18:04:28 -0700 Subject: [PATCH] test and fix display of zero-balance leaves (fixes #170) --- hledger-lib/Hledger/Data/Account.hs | 5 +++-- tests/balance-eliding.test | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Data/Account.hs b/hledger-lib/Hledger/Data/Account.hs index 662d7ac5d..f29ba62ff 100644 --- a/hledger-lib/Hledger/Data/Account.hs +++ b/hledger-lib/Hledger/Data/Account.hs @@ -125,10 +125,11 @@ pruneAccounts :: (Account -> Bool) -> Account -> Maybe Account pruneAccounts p = headMay . prune where prune a - | null prunedsubs = if p a then [] else [a] - | otherwise = [a{asubs=prunedsubs}] + | null prunedsubs = if p a then [] else [a'] + | otherwise = [a'] where prunedsubs = concatMap prune $ asubs a + a' = a{asubs=prunedsubs} -- | Flatten an account tree into a list, which is sometimes -- convenient. Note since accounts link to their parents/subs, the diff --git a/tests/balance-eliding.test b/tests/balance-eliding.test index 5f6e5d1e8..cd688e1f4 100644 --- a/tests/balance-eliding.test +++ b/tests/balance-eliding.test @@ -46,3 +46,15 @@ hledgerdev -f - balance --no-total >>>2 >>>=0 +# 5. Zero-balance leaves should also be hidden by default. +hledgerdev -f - balance --no-total +<<< +1/1 + (a) 1 + (a:aa) 1 + (a:aa) -1 + (a:aa:aaa) 1 + (a:aa:aaa) -1 +>>> + 1 a +>>>=0