aboutsummaryrefslogtreecommitdiff
path: root/test/Language.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-08-17 22:31:00 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-08-17 22:31:00 +0100
commit7dbd39e6e5d77b332f7b0b534eddddbd116e00b6 (patch)
tree60f3ac45126ce98fd77d0a1d93dc4229070f4f64 /test/Language.hs
parent593d78ebd7e2d10c609a4e5e363ed89386ab27cf (diff)
downloadmicro-lang-hs-7dbd39e6e5d77b332f7b0b534eddddbd116e00b6.tar.gz
micro-lang-hs-7dbd39e6e5d77b332f7b0b534eddddbd116e00b6.zip
More error tests
Diffstat (limited to 'test/Language.hs')
-rw-r--r--test/Language.hs49
1 files changed, 45 insertions, 4 deletions
diff --git a/test/Language.hs b/test/Language.hs
index 9da3124..392fcb7 100644
--- a/test/Language.hs
+++ b/test/Language.hs
@@ -172,8 +172,10 @@ testCase11 =
A.Call (A.Func "lambda@2,1" [] Nothing [] True True $ newPos "test" 2 1) [] $ newPos "test" 2 1
]
+-- test errors
+
testCase12 =
- TestLabel "invalid return value" $
+ TestLabel "invalid return value (empty return)" $
TestCase $ do
e <-
expectError
@@ -181,9 +183,20 @@ testCase12 =
\def fn(): u8 { return; }"
case e of
Nothing -> assertFailure "expected error, didn't happen"
- Just (E.TypeError _ _) -> return $ ()
+ Just (E.Error E.TypeError _ _) -> return $ ()
testCase13 =
+ TestLabel "invalid return value" $
+ TestCase $ do
+ e <-
+ expectError
+ "module main\n\
+ \def fn(): u16 { return 1; }"
+ case e of
+ Nothing -> assertFailure "expected error, didn't happen"
+ Just (E.Error E.TypeError _ _) -> return $ ()
+
+testCase14 =
TestLabel "return without function" $
TestCase $ do
e <-
@@ -192,7 +205,32 @@ testCase13 =
\return;"
case e of
Nothing -> assertFailure "expected error, didn't happen"
- Just (E.UnexpectedReturn _ _) -> return $ ()
+ Just (E.Error E.UnexpectedReturn _ _) -> return $ ()
+
+testCase15 =
+ TestLabel "symbol defined" $
+ TestCase $ do
+ e <-
+ expectError
+ "module main\n\
+ \def fn() { }\n\
+ \def fn() { }"
+ case e of
+ Nothing -> assertFailure "expected error, didn't happen"
+ Just (E.Error E.AlreadyDefined _ pos) ->
+ if pos /= (newPos "test" 3 1) then assertFailure ("error position didn't match: " ++ show pos) else return $ ()
+
+testCase16 =
+ TestLabel "symbol defined" $
+ TestCase $ do
+ e <-
+ expectError
+ "module main\n\
+ \def fn(a: u8, a: u8) { }\n"
+ case e of
+ Nothing -> assertFailure "expected error, didn't happen"
+ Just (E.Error E.AlreadyDefined _ pos) ->
+ if pos /= (newPos "test" 2 15) then assertFailure ("error position didn't match: " ++ show pos) else return $ ()
language =
[ testCase1,
@@ -207,5 +245,8 @@ language =
testCase10,
testCase11,
testCase12,
- testCase13
+ testCase13,
+ testCase14,
+ testCase15,
+ testCase16
]