From d08042be1e0ae158f124bb6848f5843a804a6544 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 6 Sep 2022 22:22:32 +0100 Subject: Assignation --- test/Language.hs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/Language.hs b/test/Language.hs index 5c1bb57..0b7d6ac 100644 --- a/test/Language.hs +++ b/test/Language.hs @@ -228,6 +228,18 @@ testCase16 = A.Var "b" (A.Type "bool") (A.Bool' True $ newPos "test" 3 11) True $ newPos "test" 3 1 ] +testCase17 = + TestLabel "parse assignation" $ + TestCase $ + assertAst + "module main\n\ + \var a: u8 = 0;\n\ + \a = 10;" + [ A.Module "main" $ newPos "test" 1 1, + A.Var "a" (A.Type "u8") (A.Num 0 $ newPos "test" 2 13) False $ newPos "test" 2 5, + A.BinOp A.Assign (newPos "test" 3 5) (A.Variable "a" $ newPos "test" 3 1) (A.Num 10 $ newPos "test" 3 5) + ] + -- test errors testCaseE1 = @@ -349,6 +361,24 @@ testCaseE14 = \var a: bool = (a:u8): u8 { return a; };\n" E.TypeError +testCaseE15 = + TestLabel "invalid assignation target" $ + TestCase $ + expectError + "module main\n\ + \def fn() { return; }\n\ + \fn() = 10;" + E.InvalidTarget + +testCaseE16 = + TestLabel "type mismatch in assignation" $ + TestCase $ + expectError + "module main\n\ + \var a: u8 = 0;\n\ + \a = false;" + E.TypeError + language = [ testCase2, testCase3, @@ -365,6 +395,7 @@ language = testCase14, testCase15, testCase16, + testCase17, -- errors testCaseE1, testCaseE2, @@ -379,5 +410,7 @@ language = testCaseE11, testCaseE12, testCaseE13, - testCaseE14 + testCaseE14, + testCaseE15, + testCaseE16 ] -- cgit v1.2.3