{-# LANGUAGE Safe #-}
module Test.CompileInfo (tests) where
import Base.CompileError
import Base.Mergeable
import Base.CompileInfo
tests :: [IO (CompileInfo ())]
tests = [
checkSuccess 'a' (return 'a'),
checkError "error\n" (compileErrorM "error" :: CompileInfoIO Char),
checkSuccess ['a','b'] (collectAllOrErrorM [return 'a',return 'b']),
checkSuccess [] (collectAllOrErrorM [] :: CompileInfoIO [Char]),
checkError "error1\nerror2\n" (collectAllOrErrorM [compileErrorM "error1",return 'b',compileErrorM "error2"]),
checkSuccess 'a' (collectOneOrErrorM [return 'a',return 'b']),
checkError "" (collectOneOrErrorM [] :: CompileInfoIO Char),
checkSuccess 'b' (collectOneOrErrorM [compileErrorM "error1",return 'b',compileErrorM "error2"]),
checkSuccess ['a','b','c'] (mergeAllM [return ['a'],return ['b','c']]),
checkSuccess [] (mergeAllM [] :: CompileInfoIO [Char]),
checkError "error1\nerror2\n" (mergeAllM [compileErrorM "error1",return ['b'],compileErrorM "error2"]),
checkSuccess ['a','b'] (mergeAnyM [return ['a'],return ['b']]),
checkError "" (mergeAnyM [] :: CompileInfoIO [Char]),
checkSuccess ['b'] (mergeAnyM [compileErrorM "error1",return ['b'],compileErrorM "error2"]),
checkSuccessAndWarnings ["warning1","warning2"] ()
(compileWarningM "warning1" >> return () >> compileWarningM "warning2"),
checkErrorAndWarnings ["warning1"] "error\n"
(compileWarningM "warning1" >> compileErrorM "error" >> compileWarningM "warning2" :: CompileInfoIO ()),
checkSuccess ['a','b'] (sequence [return 'a',return 'b']),
checkSuccess [] (sequence [] :: CompileInfoIO [Char]),
checkError "error1\n" (sequence [compileErrorM "error1",return 'b',compileErrorM "error2"]),
checkSuccess 'a' (return 'a' `reviseErrorM` "message"),
checkError "message\n error\n" (compileErrorM "error" `reviseErrorM` "message" :: CompileInfoIO ()),
checkSuccess 'a' (compileBackgroundM "background" >> return 'a'),
checkError "error\n background\n"
(compileBackgroundM "background" >> compileErrorM "error" :: CompileInfoIO ()),
checkError "error\n background\n"
(collectAllOrErrorM [compileBackgroundM "background"] >> compileErrorM "error" :: CompileInfoIO [()]),
checkError "error\n background\n"
(collectOneOrErrorM [compileBackgroundM "background"] >> compileErrorM "error" :: CompileInfoIO ()),
checkError "error\n background\n"
(mergeAllM [compileBackgroundM "background"] >> compileErrorM "error" :: CompileInfoIO ()),
checkError "error\n background\n"
(mergeAnyM [compileBackgroundM "background"] >> compileErrorM "error" :: CompileInfoIO ()),
checkSuccess 'a' ((resetBackgroundM $ compileBackgroundM "background") >> return 'a'),
checkError "error\n"
((resetBackgroundM $ compileBackgroundM "background") >> compileErrorM "error" :: CompileInfoIO ())
]
checkSuccess :: (Eq a, Show a) => a -> CompileInfoIO a -> IO (CompileInfo ())
checkSuccess x y = do
y' <- toCompileInfo y
if isCompileError y' || getCompileSuccess y' == x
then return $ y' >> return ()
else return $ compileErrorM $ "Expected value " ++ show x ++ " but got value " ++ show (getCompileSuccess y')
checkError :: (Eq a, Show a) => String -> CompileInfoIO a -> IO (CompileInfo ())
checkError e y = do
y' <- toCompileInfo y
if not (isCompileError y')
then return $ compileErrorM $ "Expected error \"" ++ e ++ "\" but got value " ++ show (getCompileSuccess y')
else if show (getCompileError y') == e
then return $ return ()
else return $ compileErrorM $ "Expected error \"" ++ e ++ "\" but got error \"" ++ show (getCompileError y') ++ "\""
checkSuccessAndWarnings :: (Eq a, Show a) => [String] -> a -> CompileInfoIO a -> IO (CompileInfo ())
checkSuccessAndWarnings w x y = do
y' <- toCompileInfo y
outcome <- checkSuccess x y
if getCompileWarnings y' == w
then return $ outcome >> return ()
else return $ compileErrorM $ "Expected warnings " ++ show w ++ " but got warnings " ++ show (getCompileWarnings y')
checkErrorAndWarnings :: (Eq a, Show a) => [String] -> String -> CompileInfoIO a -> IO (CompileInfo ())
checkErrorAndWarnings w e y = do
y' <- toCompileInfo y
outcome <- checkError e y
if getCompileWarnings y' == w
then return $ outcome >> return ()
else return $ compileErrorM $ "Expected warnings " ++ show w ++ " but got warnings " ++ show (getCompileWarnings y')