From ead8764499fe3c094b1e60a1b8464e9e008fc260 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 11 Sep 2022 10:51:22 +0100 Subject: Folding constants in addition --- test/Language.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/Language.hs') diff --git a/test/Language.hs b/test/Language.hs index 83736b2..604b06b 100644 --- a/test/Language.hs +++ b/test/Language.hs @@ -9,6 +9,17 @@ import Micro.Parser (parseFromString) import Test.HUnit import Text.Parsec.Pos (newPos) +assertCompileAst :: String -> [A.Expr] -> Assertion +assertCompileAst input expected = do + r <- return $ parseFromString input + case r of + Left e -> assertFailure $ show e + Right ast -> do + res <- return $ compileToAst ast + case res of + Left e -> assertFailure $ show e + Right ast -> assertEqual "" expected ast + assertAst :: String -> [A.Expr] -> Assertion assertAst input expected = do r <- return $ parseFromString input @@ -238,6 +249,16 @@ testCase17 = A.BinOp A.Assign (newPos "-" 3 5) (A.Variable "a" $ newPos "-" 3 1) (A.Num 10 $ newPos "-" 3 5) ] +testCase18 = + TestLabel "fold constant addition" $ + TestCase $ + assertCompileAst + "module main\n\ + \1 + 2;" + [ A.Module "main" $ newPos "-" 1 1, + A.Num 3 $ newPos "-" 2 5 + ] + -- test errors testCaseE1 = @@ -402,6 +423,7 @@ language = testCase15, testCase16, testCase17, + testCase18, -- errors testCaseE1, testCaseE2, -- cgit v1.2.3