{-# LANGUAGE Safe #-}
module Test.DefinedCategory (tests) where
import System.FilePath
import Text.Parsec
import Base.CompileError
import Base.CompileInfo
import Parser.DefinedCategory ()
import Test.Common
import Types.DefinedCategory
tests :: [IO (CompileInfo ())]
tests :: [IO (CompileInfo ())]
tests = [
String -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"definitions.0rx"),
String -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"internal_inheritance.0rx"),
String -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"internal_params.0rx"),
String -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"internal_filters.0rx")
]
checkParseSuccess :: String -> IO (CompileInfo ())
checkParseSuccess :: String -> IO (CompileInfo ())
checkParseSuccess String
f = do
String
contents <- String -> IO String
loadFile String
f
let parsed :: CompileInfo [DefinedCategory SourcePos]
parsed = String -> String -> CompileInfo [DefinedCategory SourcePos]
forall a. ParseFromSource a => String -> String -> CompileInfo [a]
readMulti String
f String
contents :: CompileInfo [DefinedCategory SourcePos]
CompileInfo () -> IO (CompileInfo ())
forall (m :: * -> *) a. Monad m => a -> m a
return (CompileInfo () -> IO (CompileInfo ()))
-> CompileInfo () -> IO (CompileInfo ())
forall a b. (a -> b) -> a -> b
$ CompileInfo [DefinedCategory SourcePos] -> CompileInfo ()
forall (m :: * -> *) a. CompileErrorM m => CompileInfo a -> m ()
check CompileInfo [DefinedCategory SourcePos]
parsed
where
check :: CompileInfo a -> m ()
check CompileInfo a
c
| CompileInfo a -> Bool
forall a. CompileInfo a -> Bool
isCompileError CompileInfo a
c = String -> m ()
forall (m :: * -> *) a. CompileErrorM m => String -> m a
compileErrorM (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"Parse " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
":\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ CompileMessage -> String
forall a. Show a => a -> String
show (CompileInfo a -> CompileMessage
forall a. CompileInfo a -> CompileMessage
getCompileError CompileInfo a
c)
| Bool
otherwise = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkParseFail :: String -> IO (CompileInfo ())
checkParseFail :: String -> IO (CompileInfo ())
checkParseFail String
f = do
String
contents <- String -> IO String
loadFile String
f
let parsed :: CompileInfo [DefinedCategory SourcePos]
parsed = String -> String -> CompileInfo [DefinedCategory SourcePos]
forall a. ParseFromSource a => String -> String -> CompileInfo [a]
readMulti String
f String
contents :: CompileInfo [DefinedCategory SourcePos]
CompileInfo () -> IO (CompileInfo ())
forall (m :: * -> *) a. Monad m => a -> m a
return (CompileInfo () -> IO (CompileInfo ()))
-> CompileInfo () -> IO (CompileInfo ())
forall a b. (a -> b) -> a -> b
$ CompileInfo [DefinedCategory SourcePos] -> CompileInfo ()
forall (m :: * -> *) a.
(CompileErrorM m, Show a) =>
CompileInfo a -> m ()
check CompileInfo [DefinedCategory SourcePos]
parsed
where
check :: CompileInfo a -> m ()
check CompileInfo a
c
| CompileInfo a -> Bool
forall a. CompileInfo a -> Bool
isCompileError CompileInfo a
c = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = String -> m ()
forall (m :: * -> *) a. CompileErrorM m => String -> m a
compileErrorM (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"Parse " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": Expected failure but got\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
a -> String
forall a. Show a => a -> String
show (CompileInfo a -> a
forall a. CompileInfo a -> a
getCompileSuccess CompileInfo a
c) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"