Add tests/Parse.Helpers to cabal file

This commit is contained in:
Robin Heggelund Hansen 2022-09-09 10:09:20 +02:00
parent d955f899cd
commit 21d90c4a32
2 changed files with 25 additions and 30 deletions

View File

@ -239,6 +239,7 @@ Test-Suite gren-tests
other-modules:
Helpers.Instances
Parse.Helpers
-- tests
Parse.SpaceSpec

View File

@ -1,47 +1,41 @@
{-# LANGUAGE OverloadedStrings #-}
module Parse.Helpers
( checkParse
, checkSuccessfulParse
, checkParseError
)
module Parse.Helpers
( checkParse,
checkSuccessfulParse,
checkParseError,
)
where
import Data.ByteString qualified as BS
import Parse.Space qualified as Space
import Parse.Primitives qualified as P
import Parse.Space qualified as Space
import Reporting.Annotation qualified as A
import Test.Hspec (Spec, describe, it)
import Test.Hspec qualified as Hspec
checkParse :: (Show error, Show target) => Space.Parser error (A.Located target) -> (P.Row -> P.Col -> error) -> (Either error (A.Located target, A.Position) -> Bool) -> BS.ByteString -> IO ()
checkParse parser toBadEnd checkResult str =
Hspec.shouldSatisfy
( P.fromByteString parser toBadEnd str)
checkResult
Hspec.shouldSatisfy
(P.fromByteString parser toBadEnd str)
checkResult
checkSuccessfulParse :: (Show error, Show target) => Space.Parser error (A.Located target) -> (P.Row -> P.Col -> error) -> (target -> Bool) -> BS.ByteString -> IO ()
checkSuccessfulParse parser toBadEnd checkTarget =
let checkResult result =
case result of
Right (A.At _ target, _) ->
checkTarget target
Left _ ->
False
in
checkParse parser toBadEnd checkResult
let checkResult result =
case result of
Right (A.At _ target, _) ->
checkTarget target
Left _ ->
False
in checkParse parser toBadEnd checkResult
checkParseError :: (Show error, Show target)=> Space.Parser error (A.Located target) -> (P.Row -> P.Col -> error) -> (error -> Bool) -> BS.ByteString -> IO ()
checkParseError :: (Show error, Show target) => Space.Parser error (A.Located target) -> (P.Row -> P.Col -> error) -> (error -> Bool) -> BS.ByteString -> IO ()
checkParseError parser toBadEnd checkError =
let checkResult result =
case result of
Left error ->
checkError error
Right _ ->
False
in
checkParse parser toBadEnd checkResult
let checkResult result =
case result of
Left error ->
checkError error
Right _ ->
False
in checkParse parser toBadEnd checkResult