tests: port Read tests to easytest

This commit is contained in:
Simon Michael 2018-09-03 15:42:24 -07:00
parent d1cff46ba7
commit f3709f241d
3 changed files with 34 additions and 47 deletions

View File

@ -17,7 +17,6 @@ tests_Hledger = TestList
[ [
tests_Hledger_Data tests_Hledger_Data
,tests_Hledger_Query ,tests_Hledger_Query
,tests_Hledger_Read
,tests_Hledger_Reports ,tests_Hledger_Reports
,tests_Hledger_Utils ,tests_Hledger_Utils
] ]

View File

@ -29,7 +29,6 @@ module Hledger.Read (
module Hledger.Read.Common, module Hledger.Read.Common,
-- * Tests -- * Tests
tests_Hledger_Read,
easytests_Read, easytests_Read,
) where ) where
@ -148,12 +147,6 @@ newJournalContent = do
readJournal' :: Text -> IO Journal readJournal' :: Text -> IO Journal
readJournal' t = readJournal def Nothing t >>= either error' return readJournal' t = readJournal def Nothing t >>= either error' return
tests_readJournal' = [
"readJournal' parses sample journal" ~: do
_ <- samplejournal
assertBool "" True
]
-- | @findReader mformat mpath@ -- | @findReader mformat mpath@
-- --
-- Find the reader named by @mformat@, if provided. -- Find the reader named by @mformat@, if provided.
@ -314,47 +307,37 @@ tryReaders iopts mpath readers txt = firstSuccessOrFirstError [] readers
-- tests -- tests
samplejournal = readJournal' $ T.unlines
["2008/01/01 income"
," assets:bank:checking $1"
," income:salary"
,""
,"comment"
,"multi line comment here"
,"for testing purposes"
,"end comment"
,""
,"2008/06/01 gift"
," assets:bank:checking $1"
," income:gifts"
,""
,"2008/06/02 save"
," assets:bank:saving $1"
," assets:bank:checking"
,""
,"2008/06/03 * eat & shop"
," expenses:food $1"
," expenses:supplies $1"
," assets:cash"
,""
,"2008/12/31 * pay off"
," liabilities:debts $1"
," assets:bank:checking"
]
tests_Hledger_Read = TestList $
tests_readJournal'
++ [
"journal" ~: do
r <- runExceptT $ parseWithState mempty JournalReader.journalp ""
assertBool "journalp should parse an empty file" (isRight $ r)
jE <- readJournal def Nothing "" -- don't know how to get it from journal
either error' (assertBool "journalp parsing an empty file should give an empty journal" . null . jtxns) jE
]
easytests_Read = tests "Read" [ easytests_Read = tests "Read" [
easytests_Common easytests_Common
,easytests_CsvReader ,easytests_CsvReader
,easytests_JournalReader ,easytests_JournalReader
] ]
--samplejournal = readJournal' $ T.unlines
-- ["2008/01/01 income"
-- ," assets:bank:checking $1"
-- ," income:salary"
-- ,""
-- ,"comment"
-- ,"multi line comment here"
-- ,"for testing purposes"
-- ,"end comment"
-- ,""
-- ,"2008/06/01 gift"
-- ," assets:bank:checking $1"
-- ," income:gifts"
-- ,""
-- ,"2008/06/02 save"
-- ," assets:bank:saving $1"
-- ," assets:bank:checking"
-- ,""
-- ,"2008/06/03 * eat & shop"
-- ," expenses:food $1"
-- ," expenses:supplies $1"
-- ," assets:cash"
-- ,""
-- ,"2008/12/31 * pay off"
-- ," liabilities:debts $1"
-- ," assets:bank:checking"
-- ]

View File

@ -826,4 +826,9 @@ easytests_JournalReader = tests "JournalReader" [
expectParse endtagdirectivep "end tag \n" expectParse endtagdirectivep "end tag \n"
expectParse endtagdirectivep "pop \n" expectParse endtagdirectivep "pop \n"
,tests "journalp" [
test "empty file" $ expectParseEq journalp "" nulljournal
]
] ]