diff --git a/Ledger/Parse.hs b/Ledger/Parse.hs index 1f2faa5b7..1005d44d1 100644 --- a/Ledger/Parse.hs +++ b/Ledger/Parse.hs @@ -85,9 +85,9 @@ parseLedger reftime inname intxt = do ledgerFile :: GenParser Char LedgerFileCtx (ErrorT String IO (RawLedger -> RawLedger)) -ledgerFile = do items <- many1 ledgerItem +ledgerFile = do items <- many ledgerItem eof - return $ liftM (foldr1 (.)) $ sequence items + return $ liftM (foldr (.) id) $ sequence items where -- As all ledger line types can be distinguished by the first -- character, excepting transactions versus empty (blank or diff --git a/Tests.hs b/Tests.hs index f480d245c..6840f8b49 100644 --- a/Tests.hs +++ b/Tests.hs @@ -558,6 +558,15 @@ tests = [ (ltdate $ head $ ledger_txns rl) `is` fromGregorian 2009 1 1 return () + ,"ledgerFile" ~: do + let now = getCurrentLocalTime + assertBool "ledgerFile should parse an empty file" $ (isRight $ parseWithCtx ledgerFile "") + r <- rawLedgerFromString "" -- don't know how to get it from ledgerFile + assertBool "ledgerFile parsing an empty file should give an empty ledger" $ null $ ledger_txns r + + ,"ledgerHistoricalPrice" ~: do + parseWithCtx ledgerHistoricalPrice price1_str `parseis` price1 + ,"ledgerTransaction" ~: do parseWithCtx ledgerTransaction entry1_str `parseis` entry1 assertBool "ledgerTransaction should not parse just a date" @@ -566,10 +575,7 @@ tests = [ $ isLeft $ parseWithCtx ledgerTransaction "2009/1/1 a\n" let t = parseWithCtx ledgerTransaction "2009/1/1 a ;comment\n b 1\n" assertBool "ledgerTransaction should not include a comment in the description" - $ either (const False) ((== "a") . ltdescription) p - - ,"ledgerHistoricalPrice" ~: do - parseWithCtx ledgerHistoricalPrice price1_str `parseis` price1 + $ either (const False) ((== "a") . ltdescription) t ,"ledgerposting" ~: do parseWithCtx ledgerposting rawposting1_str `parseis` rawposting1