diff --git a/tests/Main.hs b/tests/Main.hs index 12a8ee3..61e1709 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -5,7 +5,9 @@ import Data.Aeson (eitherDecode, decode, toJSON, parseJSON, Result(..)) import Data.Aeson.Types (parse) import Data.Text import Data.Maybe +import Data.Either import Data.Function ((&)) +import Control.Exception (try) import Test.HUnit import qualified System.Exit as Exit @@ -77,11 +79,20 @@ testInstrs = TestCase $ do (eitherDecode "{\"op\": \"br\", \"labels\": [\"a\", \"b\"], \"args\": [\"z\"]}") (Right $ B.EffectInstr B.Br ["z"] [] ["a", "b"]) +testProgramFromFiles :: Test +testProgramFromFiles = TestCase $ do + res <- try $ (B.parseBrilFromPath "bril-sources/add.json") :: IO (Either IOError (Either String B.Program)) + case res of + (Right parseResult) -> assertBool "parse add.json" $ isRight parseResult + _ -> assertFailure "cannot open file" + + tests :: Test tests = TestList [ TestLabel "bril parser: type" testTypes, TestLabel "bril parser: literal" testLiterals, - TestLabel "bril parser: instruction" testInstrs + TestLabel "bril parser: instruction" testInstrs, + TestLabel "bril parser: parse files" testProgramFromFiles ] main :: IO ()