Parse add.json in tests

This commit is contained in:
Enrico Lumetti 2024-10-05 18:04:58 +02:00
parent 4376596afd
commit 7874b384a5
1 changed files with 12 additions and 1 deletions

View File

@ -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 ()