From b9b9ce7d513cb1eb9d2a0b93f976e568ca1e88cb Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 12 Oct 2008 06:45:54 +0000 Subject: [PATCH] another balance report test, another step closer --- BalanceCommand.hs | 9 +++++---- Tests.hs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/BalanceCommand.hs b/BalanceCommand.hs index 464ea0123..4a2c1eea3 100644 --- a/BalanceCommand.hs +++ b/BalanceCommand.hs @@ -93,9 +93,10 @@ Some notes for the implementation: - zero-balance leaf accounts are removed - the resulting account tree is displayed with each account's aggregated - balance, with boring parents prefixed to the next line. A boring parent - has the same balance as its single child and is not explicitly matched - by the display options. + balance, with boring parents prefixed to the next line + +- a boring parent has the same balance as its child and is not explicitly + matched by the display options. - the sum of the balances shown is displayed at the end, if it is non-zero @@ -177,7 +178,7 @@ showAccountTreeWithBalances matchedacctnames = showbal = printf "%20s" $ show bal indent = replicate (indentlevel * 2) ' ' leafname = accountLeafName fullname - isboringparent = numsubs == 1 && (bal == subbal || not matched) numsubs = length subs subbal = abalance $ root $ head subs matched = fullname `elem` matchedacctnames + isboringparent = numsubs >= 1 && (bal == subbal || not matched) diff --git a/Tests.hs b/Tests.hs index 1ce4b6dc5..fd6c4c4e1 100644 --- a/Tests.hs +++ b/Tests.hs @@ -182,6 +182,18 @@ balancecommandtests = \ $1 liabilities:debts\n\ \" --" (balancereport [] ["e"] l) + , + + "balance report with unmatched parent of two matched subaccounts" ~: do + rl <- rawledgerfromfile "sample.ledger" + let l = cacheLedger (regexFor ["cash","saving"]) $ filterRawLedgerEntries "" "" wildcard rl + assertequal + " $-2 assets:cash\n\ + \ $1 assets:saving\n\ + \--------------------\n\ + \ $-1\n\ + \" --" + (balancereport [] ["cash","saving"] l) ] -- | Assert a parsed thing equals some expected thing, or print a parse error.