module Test.Hspec.Parsec
( shouldParse
, shouldFailOn
) where
import GHC.Stack (HasCallStack)
import Text.Parsec
import Test.Hspec.Expectations
shouldParse
:: (HasCallStack, Show a, Eq a)
=> Either ParseError a
-> a
-> Expectation
r `shouldParse` v = case r of
Left e -> expectationFailure $ "expected: " ++ show v ++
"\nbut parsing failed with error:\n" ++ show e
Right x -> x `shouldBe` v
shouldFailOn
:: (HasCallStack, Show a)
=> (s -> Either ParseError a)
-> s
-> Expectation
p `shouldFailOn` s = case p s of
Left _ -> return ()
Right v -> expectationFailure $
"the parser is expected to fail, but it parsed: " ++ show v