From 27c1f0605576bcd807ad253c8c6513e5354d1aaa Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 23 Nov 2008 21:21:18 +0000 Subject: [PATCH] make --depth activate -s like ledger's -d'<=N' --- BalanceCommand.hs | 4 ++-- Options.hs | 2 +- Tests.hs | 38 ++++++++++++++++++++++++-------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/BalanceCommand.hs b/BalanceCommand.hs index 7eb58561b..3d0efef81 100644 --- a/BalanceCommand.hs +++ b/BalanceCommand.hs @@ -126,10 +126,10 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr) matchedacctnames = balancereportacctnames l sub apats t t = (if empty then id else pruneZeroBalanceLeaves) $ ledgerAccountTree maxdepth l apats = fst $ parseAccountDescriptionArgs args - sub = SubTotal `elem` opts + maxdepth = fromMaybe 9999 $ depthFromOpts opts + sub = SubTotal `elem` opts || (isJust $ depthFromOpts opts) empty = Empty `elem` opts collapse = Collapse `elem` opts - maxdepth = fromMaybe 9999 $ depthFromOpts opts totalstr = if isZeroMixedAmount total then "" else printf "--------------------\n%20s\n" $ showMixedAmount total diff --git a/Options.hs b/Options.hs index cb38e939a..202b0980a 100644 --- a/Options.hs +++ b/Options.hs @@ -117,7 +117,7 @@ endDateFromOpts opts = -- | Get the value of the depth option, if any. depthFromOpts :: [Opt] -> Maybe Int -depthFromOpts opts = +depthFromOpts opts = case depthopts of (x:_) -> Just $ read x _ -> Nothing diff --git a/Tests.hs b/Tests.hs index 35f13a11d..b1c0dc82a 100644 --- a/Tests.hs +++ b/Tests.hs @@ -127,7 +127,7 @@ balancecommand_tests = TestList [ " $1 liabilities\n" ++ "") , - "balance report with --subtotal" ~: + "balance report with -s" ~: ([SubTotal], []) `gives` (" $-1 assets\n" ++ " $-2 cash\n" ++ @@ -140,6 +140,28 @@ balancecommand_tests = TestList [ " $-1 salary\n" ++ " $1 liabilities:debts\n" ++ "") + , + "balance report --depth limits -s" ~: + ([SubTotal,Depth "1"], []) `gives` + (" $-1 assets\n" ++ + " $2 expenses\n" ++ + " $-2 income\n" ++ + " $1 liabilities\n" ++ + "") + , + "balance report --depth activates -s" ~: + ([Depth "2"], []) `gives` + (" $-1 assets\n" ++ + " $-2 cash\n" ++ + " $1 saving\n" ++ + " $2 expenses\n" ++ + " $1 food\n" ++ + " $1 supplies\n" ++ + " $-2 income\n" ++ + " $-1 gifts\n" ++ + " $-1 salary\n" ++ + " $1 liabilities:debts\n" ++ + "") , "balance report with account pattern o" ~: ([], ["o"]) `gives` @@ -149,7 +171,7 @@ balancecommand_tests = TestList [ " $-1\n" ++ "") , - "balance report with account pattern o and --subtotal" ~: + "balance report with account pattern o and -s" ~: ([SubTotal], ["o"]) `gives` (" $1 expenses:food\n" ++ " $-2 income\n" ++ @@ -227,18 +249,6 @@ balancecommand_tests = TestList [ ([Collapse], ["cash"]) `gives` (" $-2 assets:cash\n" ++ "") - , - "balance report with --depth 1" ~: - ([SubTotal,Collapse,Depth "1"], ["assets"]) `gives` - (" $-1 assets\n" ++ - "") - , - "balance report with --depth 2" ~: - ([SubTotal,Collapse,Depth "2"], ["assets"]) `gives` - (" $-1 assets\n" ++ - " $-2 cash\n" ++ - " $1 saving\n" ++ - "") , "balance report with cost basis" ~: do let l = cacheLedger [] $