From e9c5d13ac184f82321b0f8782122f7b50d25cc90 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 16 Aug 2018 06:34:56 +0100 Subject: [PATCH] lib: update old failing amountp/postingp tests, at last (#812) --- hledger-lib/Hledger/Read/Common.hs | 28 +++++++++++++++++++++-- hledger-lib/Hledger/Read/JournalReader.hs | 15 ++++++------ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index a9f04195e..b9924032a 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -1248,7 +1248,31 @@ easytests = scope "Common" $ tests [ scope "amountp" $ tests [ scope "basic" $ expectParseEq amountp "$47.18" (usd 47.18) ,scope "ends-with-decimal-mark" $ expectParseEq amountp "$1." (usd 1 `withPrecision` 0) --- ,scope "unit-price" $ expectParseEq amountp "$10 @ €0.5" (usd 10 `withPrecision` 0 `at` (eur 0.5 `withPrecision` 1)) --- ,scope "total-price" $ expectParseEq amountp "$10 @@ €5" (usd 10 `withPrecision` 0 @@ (eur 5 `withPrecision` 0)) + ,scope "unit-price" $ expectParseEq amountp "$10 @ €0.5" + -- not precise enough: + -- (usd 10 `withPrecision` 0 `at` (eur 0.5 `withPrecision` 1)) -- `withStyle` asdecimalpoint=Just '.' + amount{ + acommodity="$" + ,aquantity=10 -- need to test internal precision with roundTo ? I think not + ,astyle=amountstyle{asprecision=0, asdecimalpoint=Nothing} + ,aprice=UnitPrice $ + amount{ + acommodity="€" + ,aquantity=0.5 + ,astyle=amountstyle{asprecision=1, asdecimalpoint=Just '.'} + } + } + ,scope "total-price" $ expectParseEq amountp "$10 @@ €5" + amount{ + acommodity="$" + ,aquantity=10 + ,astyle=amountstyle{asprecision=0, asdecimalpoint=Nothing} + ,aprice=TotalPrice $ + amount{ + acommodity="€" + ,aquantity=5 + ,astyle=amountstyle{asprecision=0, asdecimalpoint=Nothing} + } + } ] ] diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 5294e991c..ff4f898b8 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -676,25 +676,26 @@ test_postingp = TestCase $ do same "status" pstatus same "account" paccount -- same "amount" pamount --- TODO assertEqual "Posting amount differs!" (showMixedAmountDebug $ pamount ep) (showMixedAmountDebug $ pamount ap) + -- more revealing: + assertEqual "amount differs!" (showMixedAmountDebug $ pamount ep) (showMixedAmountDebug $ pamount ap) same "comment" pcomment same "type" ptype same "tags" ptags same "transaction" ptransaction " expenses:food:dining $10.00 ; a: a a \n ; b: b b \n" `gives` posting{paccount="expenses:food:dining", pamount=Mixed [usd 10], pcomment="a: a a\nb: b b\n", ptags=[("a","a a"), ("b","b b")]} - - " a 1 ; [2012/11/28]\n" `gives` + + " a 1. ; [2012/11/28]\n" `gives` -- trailing decimal point required to match num's asdecimalpoint ("a" `post` num 1){pcomment="[2012/11/28]\n" ,pdate=parsedateM "2012/11/28"} - " a 1 ; a:a, [=2012/11/28]\n" `gives` - ("a" `post` num 1){pcomment="a:a, [=2012/11/28]\n" + " a 2. ; a:a, [=2012/11/28]\n" `gives` + ("a" `post` num 2){pcomment="a:a, [=2012/11/28]\n" ,ptags=[("a","a")] ,pdate=Nothing} - " a 1 ; a:a\n ; [2012/11/28=2012/11/29],b:b\n" `gives` - ("a" `post` num 1){pcomment="a:a\n[2012/11/28=2012/11/29],b:b\n" + " a 3. ; a:a\n ; [2012/11/28=2012/11/29],b:b\n" `gives` + ("a" `post` num 3){pcomment="a:a\n[2012/11/28=2012/11/29],b:b\n" ,ptags=[("a","a"), ("[2012/11/28=2012/11/29],b","b")] -- XXX ugly tag name parsed ,pdate=parsedateM "2012/11/28"}