mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-18 17:57:11 +03:00
refactor assertParse/assertParseEqual
This commit is contained in:
parent
d4965b87ff
commit
08607362b0
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
||||
# hledger project makefile
|
||||
|
||||
# optional features described in MANUAL, comment out if you don't have the libs
|
||||
OPTFLAGS=-DCHART -DVTY -DWEB
|
||||
OPTFLAGS= #-DCHART -DVTY -DWEB
|
||||
#OPTFLAGS=-DCHART -DVTY -DWEBHAPPSTACK
|
||||
|
||||
# command to run during "make ci"
|
||||
|
10
Tests.hs
10
Tests.hs
@ -437,10 +437,10 @@ tests = TestList [
|
||||
assertBool "ledgerFile parsing an empty file should give an empty ledger" $ null $ jtxns r
|
||||
|
||||
,"ledgerHistoricalPrice" ~:
|
||||
assertParse (parseWithCtx emptyCtx ledgerHistoricalPrice price1_str) price1
|
||||
assertParseEqual (parseWithCtx emptyCtx ledgerHistoricalPrice price1_str) price1
|
||||
|
||||
,"ledgerTransaction" ~: do
|
||||
assertParse (parseWithCtx emptyCtx ledgerTransaction entry1_str) entry1
|
||||
assertParseEqual (parseWithCtx emptyCtx ledgerTransaction entry1_str) entry1
|
||||
assertBool "ledgerTransaction should not parse just a date"
|
||||
$ isLeft $ parseWithCtx emptyCtx ledgerTransaction "2009/1/1\n"
|
||||
assertBool "ledgerTransaction should require some postings"
|
||||
@ -456,7 +456,7 @@ tests = TestList [
|
||||
assertBool "ledgeraccountname rejects an empty trailing component" (isLeft $ parsewith ledgeraccountname "a:b:")
|
||||
|
||||
,"ledgerposting" ~:
|
||||
assertParse (parseWithCtx emptyCtx ledgerposting rawposting1_str) rawposting1
|
||||
assertParseEqual (parseWithCtx emptyCtx ledgerposting rawposting1_str) rawposting1
|
||||
|
||||
,"normaliseMixedAmount" ~: do
|
||||
normaliseMixedAmount (Mixed []) ~?= Mixed [nullamt]
|
||||
@ -842,8 +842,8 @@ tests = TestList [
|
||||
-- ]
|
||||
|
||||
,"postingamount" ~: do
|
||||
assertParse (parseWithCtx emptyCtx postingamount " $47.18") (Mixed [dollars 47.18])
|
||||
assertParse (parseWithCtx emptyCtx postingamount " $1.")
|
||||
assertParseEqual (parseWithCtx emptyCtx postingamount " $47.18") (Mixed [dollars 47.18])
|
||||
assertParseEqual (parseWithCtx emptyCtx postingamount " $1.")
|
||||
(Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} 1 Nothing])
|
||||
|
||||
]
|
||||
|
@ -290,9 +290,13 @@ tfilter _ t = t
|
||||
is :: (Eq a, Show a) => a -> a -> Assertion
|
||||
a `is` e = assertEqual "" e a
|
||||
|
||||
-- | Assert a parse result is some expected value, or print a parse error.
|
||||
assertParse :: (Show a, Eq a) => (Either ParseError a) -> a -> Assertion
|
||||
assertParse parse expected = either (assertFailure.show) (`is` expected) parse
|
||||
-- | Assert a parse result is successful, printing the parse error on failure.
|
||||
assertParse :: (Either ParseError a) -> Assertion
|
||||
assertParse parse = either (assertFailure.show) (const (return ())) parse
|
||||
|
||||
-- | Assert a parse result is some expected value, printing the parse error on failure.
|
||||
assertParseEqual :: (Show a, Eq a) => (Either ParseError a) -> a -> Assertion
|
||||
assertParseEqual parse expected = either (assertFailure.show) (`is` expected) parse
|
||||
|
||||
printParseError :: (Show a) => a -> IO ()
|
||||
printParseError e = do putStr "parse error at "; print e
|
||||
|
Loading…
Reference in New Issue
Block a user