From cbf4029b8b70a6c542171493c1cd07c7217e084b Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Mon, 1 Jun 2020 22:27:08 +0100 Subject: [PATCH] lib: test for issue with sign checking code + fix --- hledger-lib/Hledger/Data/Amount.hs | 1 + tests/journal/parse-errors.test | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index a7c1a2f57..6850ae558 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -610,6 +610,7 @@ isNegativeMixedAmount m = [] -> Just False [a] -> Just $ isNegativeAmount a as | all isNegativeAmount as -> Just True + as | not (any isNegativeAmount as) -> Just False _ -> Nothing -- multiple amounts with different signs -- | Does this mixed amount appear to be zero when rendered with its diff --git a/tests/journal/parse-errors.test b/tests/journal/parse-errors.test index c33f7c29c..7cb731d8d 100644 --- a/tests/journal/parse-errors.test +++ b/tests/journal/parse-errors.test @@ -131,3 +131,27 @@ real postings all have the same sign b 1B >=1 + +# 12. Typical "hledger equity --close" transaction does not trigger sign error. +< +2019-01-01 opening balances + assets:a1 $3 + assets:a2 £10 + equity:opening/closing balances + +2019-12-31 closing balances + assets:a1 $-3 = $0.00 + assets:a2 £-10 = £0.00 + equity:opening/closing balances +$ hledger -f- print +2019-01-01 opening balances + assets:a1 $3 + assets:a2 £10 + equity:opening/closing balances + +2019-12-31 closing balances + assets:a1 $-3 = $0 + assets:a2 £-10 = £0 + equity:opening/closing balances + +>=0