diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-08-21 16:26:56 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-08-21 16:26:56 +0100 |
commit | 14386b44f3b5c5f10fa40e6666e90aef30a5fff2 (patch) | |
tree | a5a77604ef5e7c5dcf18bf243eeaa9f36d875342 | |
parent | cbedc425b810dd887da2a52d2f33df2bced0f831 (diff) | |
download | micro-lang-hs-14386b44f3b5c5f10fa40e6666e90aef30a5fff2.tar.gz micro-lang-hs-14386b44f3b5c5f10fa40e6666e90aef30a5fff2.zip |
Test for binary number parsing
-rw-r--r-- | test/Language.hs | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/test/Language.hs b/test/Language.hs index 96fde41..a6a5aa6 100644 --- a/test/Language.hs +++ b/test/Language.hs @@ -32,11 +32,20 @@ expectError input etyp = do Right _ -> assertFailure "expected error, didn't happen" testCase1 = + TestLabel "parse binary number" $ + TestCase $ + assertAst + "module main\n0b100000;" + [ A.Module "main" $ newPos "test" 1 1, + A.Num 32 $ newPos "test" 2 1 + ] + +testCase2 = TestLabel "parse module" $ TestCase $ assertAst "module main" [A.Module "main" $ newPos "test" 1 1] -testCase2 = +testCase3 = TestLabel "parse a function" $ TestCase $ @@ -47,7 +56,7 @@ testCase2 = A.Func "fn" [] Nothing [] False False $ newPos "test" 2 1 ] -testCase3 = +testCase4 = TestLabel "parse a function with parameters" $ TestCase $ @@ -58,7 +67,7 @@ testCase3 = A.Func "fn" [("a", A.Type "u8", newPos "test" 2 8)] Nothing [] False False $ newPos "test" 2 1 ] -testCase4 = +testCase5 = TestLabel "parse a function with return value" $ TestCase $ @@ -70,7 +79,7 @@ testCase4 = 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 = +testCase6 = TestLabel "parse a function call" $ TestCase $ @@ -83,7 +92,7 @@ testCase5 = A.Call (A.Var "fn" $ newPos "test" 3 1) [] $ newPos "test" 3 1 ] -testCase6 = +testCase7 = TestLabel "parse a function call with arguments" $ TestCase $ @@ -96,7 +105,7 @@ testCase6 = A.Call (A.Var "fn" $ newPos "test" 3 1) [A.Num 10 $ newPos "test" 3 4] $ newPos "test" 3 1 ] -testCase7 = +testCase8 = TestLabel "parse empty return on a function" $ TestCase $ @@ -108,7 +117,7 @@ testCase7 = A.Func "fn" [] Nothing [A.Return Nothing $ newPos "test" 3 1] False False $ newPos "test" 2 1 ] -testCase8 = +testCase9 = TestLabel "parse a recursive function" $ TestCase $ @@ -120,7 +129,7 @@ testCase8 = A.Func "fn" [] Nothing [A.Call (A.Var "fn" $ newPos "test" 3 1) [] $ newPos "test" 3 1] False False $ newPos "test" 2 1 ] -testCase9 = +testCase10 = TestLabel "parse a function with a function parameter" $ TestCase $ @@ -144,7 +153,7 @@ testCase9 = A.Call (A.Var "fn2" $ newPos "test" 5 1) [A.Var "fn1" $ newPos "test" 5 5] $ newPos "test" 5 1 ] -testCase10 = +testCase11 = TestLabel "parse a function with a function parameter (lambda)" $ TestCase $ @@ -165,7 +174,7 @@ testCase10 = 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 = +testCase12 = TestLabel "parse a call to lambda" $ TestCase $ assertAst @@ -177,7 +186,7 @@ testCase11 = -- test errors -testCase12 = +testCase13 = TestLabel "invalid return value (empty return)" $ TestCase $ expectError @@ -185,7 +194,7 @@ testCase12 = \def fn(): u8 { return; }" E.TypeError -testCase13 = +testCase14 = TestLabel "invalid return value" $ TestCase $ expectError @@ -193,7 +202,7 @@ testCase13 = \def fn(): u16 { return 1; }" E.TypeError -testCase14 = +testCase15 = TestLabel "return without function" $ TestCase $ expectError @@ -201,7 +210,7 @@ testCase14 = \return;" E.UnexpectedReturn -testCase15 = +testCase16 = TestLabel "symbol already defined" $ TestCase $ expectError @@ -210,7 +219,7 @@ testCase15 = \def fn() { }" E.AlreadyDefined -testCase16 = +testCase17 = TestLabel "parameter already defined" $ TestCase $ expectError @@ -218,7 +227,7 @@ testCase16 = \def fn(a: u8, a: u8) { }\n" E.AlreadyDefined -testCase17 = +testCase18 = TestLabel "call on non callable" $ TestCase $ expectError @@ -226,7 +235,7 @@ testCase17 = \def fn(a: u8): u8 { return a(); }\n" E.NonCallable -testCase18 = +testCase19 = TestLabel "undefined variable" $ TestCase $ expectError @@ -234,7 +243,7 @@ testCase18 = \def fn(a: u8): u8 { return undef; }\n" E.Undefined -testCase19 = +testCase20 = TestLabel "lambdas can use local variables only" $ TestCase $ expectError @@ -245,8 +254,7 @@ testCase19 = E.Undefined language = - [ testCase1, - testCase2, + [ testCase2, testCase3, testCase4, testCase5, @@ -263,5 +271,6 @@ language = testCase16, testCase17, testCase18, - testCase19 + testCase19, + testCase20 ] |