From 7874b384a5e92c0a00b770b1d557f0dd436520a1 Mon Sep 17 00:00:00 2001 From: Enrico Lumetti Date: Sat, 5 Oct 2024 18:04:58 +0200 Subject: [PATCH] Parse add.json in tests --- tests/Main.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 ()