aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-06 22:22:32 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-06 22:22:32 +0100
commitd08042be1e0ae158f124bb6848f5843a804a6544 (patch)
tree71ffa63234c13f3bf7d31fe3c0a3876839cae2e8 /test
parentf8dfbfc1604aea626a6502b9f6d06ea1299a0cdb (diff)
downloadmicro-lang-hs-d08042be1e0ae158f124bb6848f5843a804a6544.tar.gz
micro-lang-hs-d08042be1e0ae158f124bb6848f5843a804a6544.zip
Assignation
Diffstat (limited to 'test')
-rw-r--r--test/Language.hs35
1 files changed, 34 insertions, 1 deletions
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
]