From 7dbd39e6e5d77b332f7b0b534eddddbd116e00b6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 17 Aug 2022 22:31:00 +0100 Subject: More error tests --- test/Language.hs | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'test/Language.hs') 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 ] -- cgit v1.2.3