From 7ba0dc06a5dae378ec22682a066299802222fcd6 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 2 Apr 2009 02:52:23 +0000 Subject: [PATCH] test and fix for register --depth --- NOTES | 1 - RegisterCommand.hs | 3 ++- Tests.hs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NOTES b/NOTES index 82685b4b3..03d8d0781 100644 --- a/NOTES +++ b/NOTES @@ -10,7 +10,6 @@ clever tricks like the plague." --Edsger Dijkstra * to do ** errors -*** --depth works with reg -W but not with reg *** register report should sort by date ** features *** more ledger features diff --git a/RegisterCommand.hs b/RegisterCommand.hs index 034c67b27..9e2909470 100644 --- a/RegisterCommand.hs +++ b/RegisterCommand.hs @@ -33,7 +33,8 @@ showRegisterReport opts args l | otherwise = showtxns summaryts nulltxn startbal where interval = intervalFromOpts opts - ts = filterempties $ filter matchapats $ ledgerTransactions l + ts = filterempties $ filter matchapats $ filterdepth $ ledgerTransactions l + filterdepth = filter (\t -> (accountNameLevel $ account t) <= depth) filterempties | Empty `elem` opts = id | otherwise = filter (not . isZeroMixedAmount . amount) diff --git a/Tests.hs b/Tests.hs index 158cd6f00..9565f1e2c 100644 --- a/Tests.hs +++ b/Tests.hs @@ -476,6 +476,19 @@ tests = [ ] + , "register report with depth arg" ~: + do + l <- sampleledger + showRegisterReport [Depth "2"] [] l `is` unlines + ["2008/01/01 income income:salary $-1 $-1" + ,"2008/06/01 gift income:gifts $-1 $-2" + ,"2008/06/03 eat & shop expenses:food $1 $-1" + ," expenses:supplies $1 0" + ," assets:cash $-2 $-2" + ,"2008/12/31 pay off liabilities:debts $1 $-1" + ] + + ,"show dollars" ~: show (dollars 1) ~?= "$1.00" ,"show hours" ~: show (hours 1) ~?= "1.0h"