From 278e5dde644361400192e492f40f5adadf465e5f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 9 Mar 2010 04:11:23 +0000 Subject: [PATCH] amount display tests, fix a case where "auto" amount was displayed as 0 --- hledger-lib/Ledger/Amount.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Ledger/Amount.hs b/hledger-lib/Ledger/Amount.hs index 893f91136..44a2a421c 100644 --- a/hledger-lib/Ledger/Amount.hs +++ b/hledger-lib/Ledger/Amount.hs @@ -201,9 +201,9 @@ showMixedAmountWithoutPrice m = concat $ intersperse "\n" $ map showfixedwidth a -- | Get the string representation of a mixed amount, and if it -- appears to be all zero just show a bare 0, ledger-style. showMixedAmountOrZero :: MixedAmount -> String -showMixedAmountOrZero a - | isZeroMixedAmount a = "0" - | otherwise = showMixedAmount a +showMixedAmountOrZero a | a == missingamt = "" + | isZeroMixedAmount a = "0" + | otherwise = showMixedAmount a -- | Get the string representation of a mixed amount, or a bare 0, -- without any \@ prices. @@ -270,7 +270,14 @@ missingamt = Mixed [Amount Commodity {symbol="AUTO",side=L,spaced=False,comma=Fa tests_Amount = TestList [ "showMixedAmount" ~: do - showMixedAmount (Mixed []) ~?= "0" + showMixedAmount (Mixed [Amount dollar 0 Nothing]) `is` "$0.00" + showMixedAmount (Mixed []) `is` "0" + showMixedAmount missingamt `is` "" + + ,"showMixedAmountOrZero" ~: do + showMixedAmountOrZero (Mixed [Amount dollar 0 Nothing]) `is` "0" + showMixedAmountOrZero (Mixed []) `is` "0" + showMixedAmountOrZero missingamt `is` "" ,"amount arithmetic" ~: do let a1 = dollars 1.23