From aebcd1179d2ff737133b93f5058b70c01ab9fd15 Mon Sep 17 00:00:00 2001 From: Jay Neubrand Date: Tue, 22 Aug 2023 23:15:15 +0200 Subject: [PATCH] tests for bucket posting appending logic, bucket directive --- hledger-lib/Hledger/Read/JournalReader.hs | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 3efe06bd0c2..f3f661900ca 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -1100,6 +1100,39 @@ tests_JournalReader = testGroup "JournalReader" [ (length . tpostings) 2 + ,test "unbalanced simple transaction within bucketed context" $ do + ep <- parseWithState nulljournal{jparsedefaultaccount=Just "b"} transactionp + (T.unlines + ["2009/1/1 x" + ," a -1" + ]) + assertRight ep + let (Right x) = ep + length (tpostings x) @?= 2 + (tpostings x !! 1) @?= nullposting{paccount="b", pamount=missingmixedamt} + + ,test "multi-leg transaction within bucketed context" $ do + ep <- parseWithState nulljournal{jparsedefaultaccount=Just "b"} transactionp + (T.unlines + ["2009/1/1 x" + ," a -2" + ," c 1" + ]) + assertRight ep + let (Right x) = ep + length (tpostings x) @?= 3 + (tpostings x !! 2) @?= nullposting{paccount="b", pamount=missingmixedamt} + + ,test "self-balancing transaction within bucketed context" $ do + ep <- parseWithState nulljournal{jparsedefaultaccount=Just "b"} transactionp + (T.unlines + ["2009/1/1 x" + ," a -2" + ," c" + ]) + assertRight ep + let (Right x) = ep + length (tpostings x) @?= 2 ] -- directives @@ -1169,6 +1202,12 @@ tests_JournalReader = testGroup "JournalReader" [ testCase "empty file" $ assertParseEqE journalp "" nulljournal ] + ,tests "bucketdirectivep" [ + test "affects state" $ assertParseStateOn bucketdirectivep "bucket a:b" + jparsedefaultaccount + (Just "a:b") + ] + -- these are defined here rather than in Common so they can use journalp ,testCase "parseAndFinaliseJournal" $ do ej <- runExceptT $ parseAndFinaliseJournal journalp definputopts "" "2019-1-1\n"