module Test.DefinedCategory (tests) where
import System.FilePath
import Base.CompilerError
import Base.TrackedErrors
import Parser.DefinedCategory ()
import Parser.TextParser (SourceContext)
import Test.Common
import Types.DefinedCategory
tests :: [IO (TrackedErrors ())]
tests :: [IO (TrackedErrors ())]
tests = [
String -> IO (TrackedErrors ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"definitions.0rx"),
String -> IO (TrackedErrors ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"internal_inheritance.0rx")
]
checkParseSuccess :: String -> IO (TrackedErrors ())
checkParseSuccess :: String -> IO (TrackedErrors ())
checkParseSuccess String
f = do
String
contents <- String -> IO String
loadFile String
f
let parsed :: TrackedErrors [DefinedCategory SourceContext]
parsed = forall a.
ParseFromSource a =>
String -> String -> TrackedErrors [a]
readMulti String
f String
contents :: TrackedErrors [DefinedCategory SourceContext]
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall {m :: * -> *} {a}.
ErrorContextM m =>
TrackedErrorsT Identity a -> m ()
check TrackedErrors [DefinedCategory SourceContext]
parsed
where
check :: TrackedErrorsT Identity a -> m ()
check TrackedErrorsT Identity a
c
| forall (t :: (* -> *) -> * -> *) a.
(ErrorContextT t, ErrorContextM (t Identity)) =>
t Identity a -> Bool
isCompilerError TrackedErrorsT Identity a
c = forall (m :: * -> *) a. ErrorContextM m => String -> m a
compilerErrorM forall a b. (a -> b) -> a -> b
$ String
"Parse " forall a. [a] -> [a] -> [a]
++ String
f forall a. [a] -> [a] -> [a]
++ String
":\n" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (forall a. TrackedErrors a -> CompilerMessage
getCompilerError TrackedErrorsT Identity a
c)
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkParseFail :: String -> IO (TrackedErrors ())
checkParseFail :: String -> IO (TrackedErrors ())
checkParseFail String
f = do
String
contents <- String -> IO String
loadFile String
f
let parsed :: TrackedErrors [DefinedCategory SourceContext]
parsed = forall a.
ParseFromSource a =>
String -> String -> TrackedErrors [a]
readMulti String
f String
contents :: TrackedErrors [DefinedCategory SourceContext]
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall {m :: * -> *} {a}.
(ErrorContextM m, Show a) =>
TrackedErrorsT Identity a -> m ()
check TrackedErrors [DefinedCategory SourceContext]
parsed
where
check :: TrackedErrorsT Identity a -> m ()
check TrackedErrorsT Identity a
c
| forall (t :: (* -> *) -> * -> *) a.
(ErrorContextT t, ErrorContextM (t Identity)) =>
t Identity a -> Bool
isCompilerError TrackedErrorsT Identity a
c = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = forall (m :: * -> *) a. ErrorContextM m => String -> m a
compilerErrorM forall a b. (a -> b) -> a -> b
$ String
"Parse " forall a. [a] -> [a] -> [a]
++ String
f forall a. [a] -> [a] -> [a]
++ String
": Expected failure but got\n" forall a. [a] -> [a] -> [a]
++
forall a. Show a => a -> String
show (forall a. TrackedErrors a -> a
getCompilerSuccess TrackedErrorsT Identity a
c) forall a. [a] -> [a] -> [a]
++ String
"\n"