From 821f1b7120668b860c9370ede2fbec924d815abc Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 2 Sep 2015 16:38:45 -0700 Subject: [PATCH] lib: fix tests for zero amount style (#230, #276) --- hledger-lib/Hledger/Data/Amount.hs | 6 ++-- hledger-lib/Hledger/Reports/BalanceReport.hs | 2 +- tests/misc/amount-rendering.test | 29 ++++++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 9398867e0..57c24b61d 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -624,13 +624,13 @@ tests_Hledger_Data_Amount = TestList $ -- MixedAmount - ,"adding mixed amounts, preserving minimum precision and a single commodity on zero" ~: do + ,"adding mixed amounts to zero, the commodity and amount style are preserved" ~: do (sum $ map (Mixed . (:[])) [usd 1.25 - ,usd (-1) `withPrecision` 0 + ,usd (-1) `withPrecision` 3 ,usd (-0.25) ]) - `is` Mixed [usd 0 `withPrecision` 0] + `is` Mixed [usd 0 `withPrecision` 3] ,"adding mixed amounts with total prices" ~: do (sum $ map (Mixed . (:[])) diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 99581e232..126f22973 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -170,7 +170,7 @@ tests_balanceReport = showw (acct,amt) = (acct, showMixedAmountDebug amt) assertEqual "items" (map showw eitems) (map showw aitems) assertEqual "total" (showMixedAmountDebug etotal) (showMixedAmountDebug atotal) - usd0 = nullamt{acommodity="$"} + usd0 = usd 0 in [ "balanceReport with no args on null journal" ~: do diff --git a/tests/misc/amount-rendering.test b/tests/misc/amount-rendering.test index dc13dfd04..80a76492c 100644 --- a/tests/misc/amount-rendering.test +++ b/tests/misc/amount-rendering.test @@ -46,7 +46,7 @@ hledger -f - balance 0 >>>=0 -# 4. a zero amount is always displayed as just "0", regardless of any commodity/decimal places/price (like ledger) +# 4. a single-commodity zero amount's commodity/decimal places/price is preserved, when possible # hledger -f- print --empty <<< @@ -55,11 +55,36 @@ hledger -f- print --empty b >>> 2010/03/01 x - a 0 + a 0 @ 3EUR b 0 >>>=0 +# 5. +# When preserving a zero amount's commodity, we should also preserve +# the amount style, such as where to place the symbol. +# https://github.com/simonmichael/hledger/issues/230 +hledger -f- balance +<<< +D 1000,00€ + +1/1 + a:b 0 + +1/2 + a:1 4000,58 + a:D -1000,58 + e -3000 +>>> + 3000,00€ a + 4000,58€ 1 + -1000,58€ D + -3000,00€ e +-------------------- + 0 +>>>= 0 + + # 5. mixed amounts with prices # XXX # hledger -f - print