tests: port CsvReader tests to easytest
This commit is contained in:
parent
1fced57c81
commit
d1cff46ba7
@ -59,7 +59,7 @@ import Hledger.Read.JournalReader as JournalReader
|
|||||||
-- import qualified Hledger.Read.LedgerReader as LedgerReader
|
-- import qualified Hledger.Read.LedgerReader as LedgerReader
|
||||||
import qualified Hledger.Read.TimedotReader as TimedotReader
|
import qualified Hledger.Read.TimedotReader as TimedotReader
|
||||||
import qualified Hledger.Read.TimeclockReader as TimeclockReader
|
import qualified Hledger.Read.TimeclockReader as TimeclockReader
|
||||||
import qualified Hledger.Read.CsvReader as CsvReader
|
import Hledger.Read.CsvReader as CsvReader
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
import Prelude hiding (getContents, writeFile)
|
import Prelude hiding (getContents, writeFile)
|
||||||
|
|
||||||
@ -345,8 +345,6 @@ samplejournal = readJournal' $ T.unlines
|
|||||||
tests_Hledger_Read = TestList $
|
tests_Hledger_Read = TestList $
|
||||||
tests_readJournal'
|
tests_readJournal'
|
||||||
++ [
|
++ [
|
||||||
CsvReader.tests_Hledger_Read_CsvReader,
|
|
||||||
|
|
||||||
"journal" ~: do
|
"journal" ~: do
|
||||||
r <- runExceptT $ parseWithState mempty JournalReader.journalp ""
|
r <- runExceptT $ parseWithState mempty JournalReader.journalp ""
|
||||||
assertBool "journalp should parse an empty file" (isRight $ r)
|
assertBool "journalp should parse an empty file" (isRight $ r)
|
||||||
@ -357,5 +355,6 @@ tests_Hledger_Read = TestList $
|
|||||||
|
|
||||||
easytests_Read = tests "Read" [
|
easytests_Read = tests "Read" [
|
||||||
easytests_Common
|
easytests_Common
|
||||||
|
,easytests_CsvReader
|
||||||
,easytests_JournalReader
|
,easytests_JournalReader
|
||||||
]
|
]
|
||||||
|
|||||||
@ -25,7 +25,7 @@ module Hledger.Read.CsvReader (
|
|||||||
expandIncludes,
|
expandIncludes,
|
||||||
transactionFromCsvRecord,
|
transactionFromCsvRecord,
|
||||||
-- * Tests
|
-- * Tests
|
||||||
tests_Hledger_Read_CsvReader
|
easytests_CsvReader,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Prelude ()
|
import Prelude ()
|
||||||
@ -832,67 +832,24 @@ parseDateWithFormatOrDefaultFormats mformat s = firstJust $ map parsewith format
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- tests
|
-- tests
|
||||||
|
|
||||||
tests_Hledger_Read_CsvReader = TestList (test_parser)
|
easytests_CsvReader = tests "CsvReader" [
|
||||||
-- ++ test_description_parsing)
|
tests "rulesp" [
|
||||||
|
test "empty file" $
|
||||||
|
expectEq' (Right rules) (parseCsvRules "unknown" "")
|
||||||
|
|
||||||
-- test_description_parsing = [
|
,test "trailing comments" $
|
||||||
-- "description-field 1" ~: assertParseDescription "description-field 1\n" [FormatField False Nothing Nothing (FieldNo 1)]
|
expectEq' (Right rules{rdirectives = [("skip","")]}) (parseWithState' rules rulesp "skip\n# \n#\n")
|
||||||
-- , "description-field 1 " ~: assertParseDescription "description-field 1 \n" [FormatField False Nothing Nothing (FieldNo 1)]
|
|
||||||
-- , "description-field %(1)" ~: assertParseDescription "description-field %(1)\n" [FormatField False Nothing Nothing (FieldNo 1)]
|
|
||||||
-- , "description-field %(1)/$(2)" ~: assertParseDescription "description-field %(1)/%(2)\n" [
|
|
||||||
-- FormatField False Nothing Nothing (FieldNo 1)
|
|
||||||
-- , FormatLiteral "/"
|
|
||||||
-- , FormatField False Nothing Nothing (FieldNo 2)
|
|
||||||
-- ]
|
|
||||||
-- ]
|
|
||||||
-- where
|
|
||||||
-- assertParseDescription string expected = do assertParseEqual (parseDescription string) (rules {descriptionField = expected})
|
|
||||||
-- parseDescription :: String -> Either ParseError CsvRules
|
|
||||||
-- parseDescription x = runParser descriptionfieldWrapper rules "(unknown)" x
|
|
||||||
-- descriptionfieldWrapper :: GenParser Char CsvRules CsvRules
|
|
||||||
-- descriptionfieldWrapper = do
|
|
||||||
-- descriptionfield
|
|
||||||
-- r <- getState
|
|
||||||
-- return r
|
|
||||||
|
|
||||||
test_parser = [
|
,test "trailing blank lines" $
|
||||||
|
expectEq' (Right rules{rdirectives = [("skip","")]}) (parseWithState' rules rulesp "skip\n\n \n")
|
||||||
|
|
||||||
"convert rules parsing: empty file" ~: do
|
,test "no final newline" $
|
||||||
-- let assertMixedAmountParse parseresult mixedamount =
|
expectEq' (Right rules{rdirectives=[("skip","")]}) (parseWithState' rules rulesp "skip")
|
||||||
-- (either (const "parse error") showMixedAmountDebug parseresult) ~?= (showMixedAmountDebug mixedamount)
|
|
||||||
assertParseEqual (parseCsvRules "unknown" "") rules
|
|
||||||
|
|
||||||
-- ,"convert rules parsing: accountrule" ~: do
|
,test "assignment with empty value" $
|
||||||
-- assertParseEqual (parseWithState rules accountrule "A\na\n") -- leading blank line required
|
expectEq'
|
||||||
-- ([("A",Nothing)], "a")
|
(Right rules{rassignments = [("account1","")], rconditionalblocks = [([["foo"]],[("account2","foo")])]})
|
||||||
|
(parseWithState' rules rulesp "account1 \nif foo\n account2 foo\n")
|
||||||
,"convert rules parsing: trailing comments" ~: do
|
|
||||||
assertParse (parseWithState' rules rulesp "skip\n# \n#\n")
|
|
||||||
|
|
||||||
,"convert rules parsing: trailing blank lines" ~: do
|
|
||||||
assertParse (parseWithState' rules rulesp "skip\n\n \n")
|
|
||||||
|
|
||||||
,"convert rules parsing: empty field value" ~: do
|
|
||||||
assertParse (parseWithState' rules rulesp "account1 \nif foo\n account2 foo\n")
|
|
||||||
|
|
||||||
-- not supported
|
|
||||||
-- ,"convert rules parsing: no final newline" ~: do
|
|
||||||
-- assertParse (parseWithState rules csvrulesfile "A\na")
|
|
||||||
-- assertParse (parseWithState rules csvrulesfile "A\na\n# \n#")
|
|
||||||
-- assertParse (parseWithState rules csvrulesfile "A\na\n\n ")
|
|
||||||
|
|
||||||
-- (rules{
|
|
||||||
-- -- dateField=Maybe FieldPosition,
|
|
||||||
-- -- statusField=Maybe FieldPosition,
|
|
||||||
-- -- codeField=Maybe FieldPosition,
|
|
||||||
-- -- descriptionField=Maybe FieldPosition,
|
|
||||||
-- -- amountField=Maybe FieldPosition,
|
|
||||||
-- -- currencyField=Maybe FieldPosition,
|
|
||||||
-- -- baseCurrency=Maybe String,
|
|
||||||
-- -- baseAccount=AccountName,
|
|
||||||
-- accountRules=[
|
|
||||||
-- ([("A",Nothing)], "a")
|
|
||||||
-- ]
|
|
||||||
-- })
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user