aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-08-16 22:34:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-08-16 22:34:52 +0100
commit55692e10192968ae7f040ceb9a8469b6ce2412c4 (patch)
tree9a3d842c8bde8db010e0b452a243b22a7f010ec3
parent8965c22df1dd198b0b82f5a8e924dfc413ff6844 (diff)
downloadmicro-lang-hs-55692e10192968ae7f040ceb9a8469b6ce2412c4.tar.gz
micro-lang-hs-55692e10192968ae7f040ceb9a8469b6ce2412c4.zip
Added more tests
-rw-r--r--test/Language.hs68
1 files changed, 66 insertions, 2 deletions
diff --git a/test/Language.hs b/test/Language.hs
index 9590b8d..c804035 100644
--- a/test/Language.hs
+++ b/test/Language.hs
@@ -13,7 +13,7 @@ assertAst tcase input expected = do
r <- return $ runParser (scan parse) () "test" input
case r of
Left e -> assertFailure $ show e
- Right ast -> assertEqual tcase ast expected
+ Right ast -> assertEqual tcase expected ast
testCase1 = TestCase $ assertAst "parse module" "module main" [A.Module "main" $ newPos "test" 1 1]
@@ -83,4 +83,68 @@ testCase7 =
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]
+testCase8 =
+ TestCase $
+ assertAst
+ "parse a recursive function"
+ "module main\n\
+ \def fn() {\n\
+ \fn(); }"
+ [ A.Module "main" $ newPos "test" 1 1,
+ A.Func "fn" [] Nothing [A.Call (A.Var "fn" $ newPos "test" 3 1) [] $ newPos "test" 3 1] False False $ newPos "test" 2 1
+ ]
+
+testCase9 =
+ TestCase $
+ assertAst
+ "parse a function with a function parameter"
+ "module main\n\
+ \def fn1() { }\n\
+ \def fn2(f: ()) {\n\
+ \f(); }\n\
+ \fn2(fn1);"
+ [ A.Module "main" $ newPos "test" 1 1,
+ A.Func "fn1" [] Nothing [] False False $ newPos "test" 2 1,
+ A.Func
+ "fn2"
+ [("f", A.FuncType [] Nothing, newPos "test" 3 9)]
+ Nothing
+ [ A.Call (A.Var "f" $ newPos "test" 4 1) [] $ newPos "test" 4 1
+ ]
+ False
+ False
+ $ newPos "test" 3 1,
+ A.Call (A.Var "fn2" $ newPos "test" 5 1) [A.Var "fn1" $ newPos "test" 5 5] $ newPos "test" 5 1
+ ]
+
+testCase10 =
+ TestCase $
+ assertAst
+ "parse a function with a function parameter (lambda)"
+ "module main\n\
+ \def fn(f: ()) {\n\
+ \f(); }\n\
+ \fn(() { });"
+ [ A.Module "main" $ newPos "test" 1 1,
+ A.Func
+ "fn"
+ [("f", A.FuncType [] Nothing, newPos "test" 2 8)]
+ Nothing
+ [A.Call (A.Var "f" $ newPos "test" 3 1) [] $ newPos "test" 3 1]
+ False
+ False
+ $ newPos "test" 2 1,
+ A.Call (A.Var "fn" $ newPos "test" 4 1) [A.Func "lambda@4,4" [] Nothing [] True True $ newPos "test" 4 4] $ newPos "test" 4 1
+ ]
+
+testCase11 =
+ TestCase $
+ assertAst
+ "parse a call to lambda"
+ "module main\n\
+ \() { }();"
+ [ A.Module "main" $ newPos "test" 1 1,
+ A.Call (A.Func "lambda@2,1" [] Nothing [] True True $ newPos "test" 2 1) [] $ newPos "test" 2 1
+ ]
+
+language = [testCase1, testCase2, testCase3, testCase4, testCase5, testCase6, testCase7, testCase8, testCase9, testCase10, testCase11]