diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-08-16 20:53:25 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-08-16 20:53:25 +0100 |
commit | 8965c22df1dd198b0b82f5a8e924dfc413ff6844 (patch) | |
tree | 986fc656a44a0dca3dff25dbd3545c2455f02945 /test | |
parent | fcf8a0771a090777774e96082118d9bdf5191052 (diff) | |
download | micro-lang-hs-8965c22df1dd198b0b82f5a8e924dfc413ff6844.tar.gz micro-lang-hs-8965c22df1dd198b0b82f5a8e924dfc413ff6844.zip |
Split in test cases
Diffstat (limited to 'test')
-rw-r--r-- | test/Language.hs | 119 |
1 files changed, 68 insertions, 51 deletions
diff --git a/test/Language.hs b/test/Language.hs index a9da577..9590b8d 100644 --- a/test/Language.hs +++ b/test/Language.hs @@ -15,55 +15,72 @@ assertAst tcase input expected = do Left e -> assertFailure $ show e Right ast -> assertEqual tcase ast expected -testCase = TestCase $ do - assertAst "parse module" "module main" [A.Module "main" $ newPos "test" 1 1] - assertAst - "parse a function" - "module main\n\ - \def fn() { }" - [ A.Module "main" $ newPos "test" 1 1, - A.Func "fn" [] Nothing [] False False $ newPos "test" 2 1 - ] - assertAst - "parse a function with parameters" - "module main\n\ - \def fn(a: u8) { }" - [ A.Module "main" $ newPos "test" 1 1, - A.Func "fn" [("a", A.Type "u8", newPos "test" 2 8)] Nothing [] False False $ newPos "test" 2 1 - ] - assertAst - "parse a function with return value" - "module main\n\ - \def fn(): u8 {\n\ - \return 1; }" - [ A.Module "main" $ newPos "test" 1 1, - A.Func "fn" [] (Just $ A.Type "u8") [A.Return (Just $ A.Num 1 $ newPos "test" 3 8) $ newPos "test" 3 1] False False $ newPos "test" 2 1 - ] - assertAst - "parse a function call" - "module main\n\ - \def fn() { }\n\ - \fn();" - [ A.Module "main" $ newPos "test" 1 1, - A.Func "fn" [] Nothing [] False False $ newPos "test" 2 1, - A.Call (A.Var "fn" $ newPos "test" 3 1) [] $ newPos "test" 3 1 - ] - assertAst - "parse a function call with arguments" - "module main\n\ - \def fn(a: u8) { }\n\ - \fn(10);" - [ A.Module "main" $ newPos "test" 1 1, - A.Func "fn" [("a", A.Type "u8", newPos "test" 2 8)] Nothing [] False False $ newPos "test" 2 1, - A.Call (A.Var "fn" $ newPos "test" 3 1) [A.Num 10 $ newPos "test" 3 4] $ newPos "test" 3 1 - ] - assertAst - "parse empty return on a function" - "module main\n\ - \def fn() {\n\ - \return; }" - [ A.Module "main" $ newPos "test" 1 1, - A.Func "fn" [] Nothing [A.Return Nothing $ newPos "test" 3 1] False False $ newPos "test" 2 1 - ] +testCase1 = TestCase $ assertAst "parse module" "module main" [A.Module "main" $ newPos "test" 1 1] -language = [testCase] +testCase2 = + TestCase $ + assertAst + "parse a function" + "module main\n\ + \def fn() { }" + [ A.Module "main" $ newPos "test" 1 1, + A.Func "fn" [] Nothing [] False False $ newPos "test" 2 1 + ] + +testCase3 = + TestCase $ + assertAst + "parse a function with parameters" + "module main\n\ + \def fn(a: u8) { }" + [ A.Module "main" $ newPos "test" 1 1, + A.Func "fn" [("a", A.Type "u8", newPos "test" 2 8)] Nothing [] False False $ newPos "test" 2 1 + ] + +testCase4 = + TestCase $ + assertAst + "parse a function with return value" + "module main\n\ + \def fn(): u8 {\n\ + \return 1; }" + [ A.Module "main" $ newPos "test" 1 1, + A.Func "fn" [] (Just $ A.Type "u8") [A.Return (Just $ A.Num 1 $ newPos "test" 3 8) $ newPos "test" 3 1] False False $ newPos "test" 2 1 + ] + +testCase5 = + TestCase $ + assertAst + "parse a function call" + "module main\n\ + \def fn() { }\n\ + \fn();" + [ A.Module "main" $ newPos "test" 1 1, + A.Func "fn" [] Nothing [] False False $ newPos "test" 2 1, + A.Call (A.Var "fn" $ newPos "test" 3 1) [] $ newPos "test" 3 1 + ] + +testCase6 = + TestCase $ + assertAst + "parse a function call with arguments" + "module main\n\ + \def fn(a: u8) { }\n\ + \fn(10);" + [ A.Module "main" $ newPos "test" 1 1, + A.Func "fn" [("a", A.Type "u8", newPos "test" 2 8)] Nothing [] False False $ newPos "test" 2 1, + A.Call (A.Var "fn" $ newPos "test" 3 1) [A.Num 10 $ newPos "test" 3 4] $ newPos "test" 3 1 + ] + +testCase7 = + TestCase $ + assertAst + "parse empty return on a function" + "module main\n\ + \def fn() {\n\ + \return; }" + [ A.Module "main" $ newPos "test" 1 1, + A.Func "fn" [] Nothing [A.Return Nothing $ newPos "test" 3 1] False False $ newPos "test" 2 1 + ] + +language = [testCase1, testCase2, testCase3, testCase4, testCase5, testCase6, testCase7] |