aboutsummaryrefslogtreecommitdiff
path: root/tests/operators.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-26 20:20:12 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-26 20:20:38 -0800
commit90c56d31352a0eeccd382ef5921baf3af4971040 (patch)
tree5167eafb5785c94b48458b18b0454222ca70c749 /tests/operators.nom
parentd5aa4e52983712f9f4c5b23528d0c2dab12b0b33 (diff)
Added a ton of tests for virtually all the functionality. Helped me find
and fix a lot of latent problems.
Diffstat (limited to 'tests/operators.nom')
-rw-r--r--tests/operators.nom76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/operators.nom b/tests/operators.nom
new file mode 100644
index 0000000..e3bd0b9
--- /dev/null
+++ b/tests/operators.nom
@@ -0,0 +1,76 @@
+#..
+ Tests for the stuff defined in lib/operators.nom
+
+use "lib/core.nom"
+
+assume (({x:5}'s "x") = 5) or barf "indexing doesn't work."
+try: % <- ({}'s "[[[\n]]]")
+..and if it barfs: barf "failed to index a table literal with a string containing brackets n stuff"
+
+<-{%x:10,%y:20}
+assume ((%x = 10) and (%y = 20)) or barf "mutli-assignment failed."
+<-{%x:%y, %y:%x}
+assume ((%y = 10) and (%x = 20)) or barf "swapping vars failed."
+
+% <- [%x < %y, %x <= %y, %x > %y, %x >= %y, %x = %y, %x is %y, %x != %y, %x isn't %y, %x is not %y]
+
+assume ({} is {}) or barf "Equality check failed."
+assume (({}'s id) is not ({}'s id)) or barf "Identity check failed."
+
+<-{%x:"outer",%y:"outer"}
+action [set global x local y]
+ export %x <- "inner"
+ %y <- "inner"
+set global x local y
+assume ((%x = "inner") and (%y = "outer")) or barf "export failed."
+
+<-{%x:"outer",%y:"outer"}
+action [set global x local y]
+ exporting [%x]
+ %x <- "inner"
+ %y <- "inner"
+set global x local y
+assume ((%x = "inner") and (%y = "outer")) or barf "export failed."
+
+<-{%x:1,%y:2}
+with [%z, %x<-999]
+ %z <- 999
+ assume (%z = 999) or barf "'with' failed."
+ assume (%x = 999) or barf "'with' assignment failed."
+assume (%x = 1) or barf "'with' scoping failed"
+assume (%z = (nil)) or barf "'with' scoping failed"
+
+assume ((1+2*3-4/2^2) = 6) or barf "math expressions not working properly"
+assume ((5 wrapped around 2) = 1) or barf "mod not working"
+assume (1 <= 2 < 3) or barf "chained operator fail."
+%value <- -999
+action [flipflop]
+ export %value <- (-%value)
+ return %value
+assume (not (1 < (flipflop) < 1)) or barf "3-way inequality evaluated middle term twice"
+assume (((yes) and (yes)) = (yes))
+action [barfer]
+ barf "short circuiting failed"
+assume (((no) and (barfer)) = (no))
+assume ((no) or (yes))
+assume ((yes) or (barfer))
+
+assume ((1 OR 2) = 3)
+assume ((3 XOR 2) = 1)
+assume ((3 AND 2) = 2)
+assume ((NOT (NOT 6)) = 6)
+assume ((1<<1) = 2)
+assume ((2>>1) = 1)
+assume ((2>>>1) = 1)
+#.. Ugh, Lua is stupid when it comes to bitwise arithmetic on negative numbers, so I'm
+ skipping the tests for those.
+
+assume ((-(5)) = -5)
+assume ((not (yes)) = (no))
+%x <- 1
+%x +<- 1
+assume (%x = 2) or barf "+<- failed"
+%x *<- 2
+assume (%x = 4) or barf "*<- failed"
+wrap %x around 3
+assume (%x = 1) or barf "wrap around failed"