{-# 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 = [
checkParseSuccess ("testfiles" </> "definitions.0rx"),
checkParseSuccess ("testfiles" </> "internal_inheritance.0rx"),
checkParseSuccess ("testfiles" </> "internal_params.0rx"),
checkParseSuccess ("testfiles" </> "internal_filters.0rx")
]
checkParseSuccess :: String -> IO (CompileInfo ())
checkParseSuccess f = do
contents <- loadFile f
let parsed = readMulti f contents :: CompileInfo [DefinedCategory SourcePos]
return $ check parsed
where
check c
| isCompileError c = compileErrorM $ "Parse " ++ f ++ ":\n" ++ show (getCompileError c)
| otherwise = return ()
checkParseFail :: String -> IO (CompileInfo ())
checkParseFail f = do
contents <- loadFile f
let parsed = readMulti f contents :: CompileInfo [DefinedCategory SourcePos]
return $ check parsed
where
check c
| isCompileError c = return ()
| otherwise = compileErrorM $ "Parse " ++ f ++ ": Expected failure but got\n" ++
show (getCompileSuccess c) ++ "\n"