From 3e6943e5f6f03d7682f5fa533e87ddca919f3f57 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 7 Apr 2009 23:02:25 +0000 Subject: [PATCH] don't show trailing spaces on amountless postings --- Ledger/LedgerTransaction.hs | 7 +++---- Tests.hs | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Ledger/LedgerTransaction.hs b/Ledger/LedgerTransaction.hs index f088ff03c..0a55a30c9 100644 --- a/Ledger/LedgerTransaction.hs +++ b/Ledger/LedgerTransaction.hs @@ -71,14 +71,13 @@ showLedgerTransaction' elide t = | otherwise = map showposting ps where showposting p = showacct p ++ " " ++ (showamount $ pamount p) ++ (showcomment $ pcomment p) - showpostingnoamt p = showacct p ++ " " ++ (showcomment $ pcomment p) + showpostingnoamt p = rstrip $ showacct p ++ " " ++ (showcomment $ pcomment p) showacct p = " " ++ showstatus p ++ (showaccountname $ paccount p) showamount = printf "%12s" . showMixedAmount showaccountname s = printf "%-34s" s showcomment s = if (length s) > 0 then " ; "++s else "" - showstatus p = case pstatus p of - True -> "* " - False -> "" + showstatus p = if pstatus p then "* " else "" + rstrip = reverse . dropWhile (== ' ') . reverse isLedgerTransactionBalanced :: LedgerTransaction -> Bool isLedgerTransactionBalanced (LedgerTransaction {ltpostings=ps}) = diff --git a/Tests.hs b/Tests.hs index 994b365f7..fc458327e 100644 --- a/Tests.hs +++ b/Tests.hs @@ -748,6 +748,9 @@ tests = [ ,"show hours" ~: show (hours 1) ~?= "1.0h" + ,"showLedgerTransaction" ~: do + showLedgerTransaction entry1 `is` entry1_str + ,"smart dates" ~: do let str `gives` datestr = fixSmartDateStr (parsedate "2008/11/26") str `is` datestr "1999-12-02" `gives` "1999/12/02" @@ -915,8 +918,8 @@ rawposting1 = Posting False "expenses:food:dining" (Mixed [dollars 10]) "" Regul entry1_str = unlines ["2007/01/28 coopportunity" - ," expenses:food:groceries $47.18" - ," assets:checking" + ," expenses:food:groceries $47.18" + ," assets:checking" ,"" ]