parse zero-length input as an empty ledger
This commit is contained in:
parent
69ce8b9a8e
commit
1085d476f1
@ -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
|
||||
|
||||
14
Tests.hs
14
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user