diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-11 10:51:22 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-11 10:51:22 +0100 |
commit | ead8764499fe3c094b1e60a1b8464e9e008fc260 (patch) | |
tree | ed7187e07313560d21ed5126c6948931a67ef8b3 /test | |
parent | acab64cc0f21c0ee9fc5b9b08b60e08997818222 (diff) | |
download | micro-lang-hs-ead8764499fe3c094b1e60a1b8464e9e008fc260.tar.gz micro-lang-hs-ead8764499fe3c094b1e60a1b8464e9e008fc260.zip |
Folding constants in addition
Diffstat (limited to 'test')
-rw-r--r-- | test/Language.hs | 22 |
1 files changed, 22 insertions, 0 deletions
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, |