Skip to content

Commit

Permalink
tests for bucket posting appending logic, bucket directive
Browse files Browse the repository at this point in the history
  • Loading branch information
jneubrand committed Aug 22, 2023
1 parent e12f36c commit aebcd11
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions hledger-lib/Hledger/Read/JournalReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit aebcd11

Please sign in to comment.