Skip to content

Commit

Permalink
Be a bit more chatty
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhat committed Jun 5, 2024
1 parent 89d70ce commit 80fd6df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dhall/src/Dhall/Parser/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ instance Text.Megaparsec.MonadParsec Void Text Parser where

updateParserState f = Parser (Text.Megaparsec.updateParserState f)

#if MIN_VERSION_megaparsec(9,4,0)
mkParsec f = Parser (Text.Megaparsec.mkParsec f)
#endif

instance Semigroup a => Semigroup (Parser a) where
(<>) = liftA2 (<>)

Expand Down
17 changes: 13 additions & 4 deletions dhall/tests/Dhall/Test/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,21 @@ shouldNotParse path = do

let pathString = Text.unpack path

Test.Util.testCase path expectedFailures (do
Test.Util.testCase path expectedFailures $ do
bytes <- ByteString.readFile pathString

case Text.Encoding.decodeUtf8' bytes of
Left _ -> return ()
Right text ->
case Parser.exprFromText mempty text of
Left _ -> return ()
Right _ -> Tasty.HUnit.assertFailure "Unexpected successful parse" )
Right expression -> do
let strippedExpression :: Expr Void Import
strippedExpression = Core.denote expression

let message = "Unexpected successful parse: " ++
show strippedExpression
Tasty.HUnit.assertFailure message

shouldDecode :: Text -> TestTree
shouldDecode pathText = do
Expand Down Expand Up @@ -212,9 +218,12 @@ shouldNotDecode pathText = do

let pathString = Text.unpack pathText

Test.Util.testCase pathText expectedFailures (do
Test.Util.testCase pathText expectedFailures $ do
bytes <- ByteString.Lazy.readFile (pathString <> ".dhallb")

case Binary.decodeExpression bytes :: Either Binary.DecodingFailure (Expr Void Import) of
Left _ -> return ()
Right _ -> Tasty.HUnit.assertFailure "Unexpected successful decode" )
Right expression -> do
let message = "Unexpected successful decode: " ++
show expression
Tasty.HUnit.assertFailure message

0 comments on commit 80fd6df

Please sign in to comment.