aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-01-29 00:20:09 -0500
committerMustafa Quraish <[email protected]>2022-01-29 00:42:58 -0500
commit08056428cec5d1e63e471590ac09d82dcbfcab93 (patch)
treee71c34fb2a47780a6e01d8fa0a2af4b3bd3e7130 /tests
parentAdd some arithmetic binary operations into lex+parse+generation (diff)
downloadcup-08056428cec5d1e63e471590ac09d82dcbfcab93.tar.xz
cup-08056428cec5d1e63e471590ac09d82dcbfcab93.zip
Add relational and logical operators + refactor binop parser
We now support OR and AND with short circuiting! (Yet to be tested since we don't yet have local variables to play with). The binop parser took a bit of an overhaul factoring out the common code so that it's easier to describe the operator precendence relationships without being overly repetitive.
Diffstat (limited to 'tests')
-rw-r--r--tests/basics.sh35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/basics.sh b/tests/basics.sh
index 9ef3bf4..cab2462 100644
--- a/tests/basics.sh
+++ b/tests/basics.sh
@@ -20,7 +20,7 @@ assert_exit_status 'fn main() { return !-1; }' 0
assert_exit_status 'fn main() { return ~34; }' 221
echo " OK"
-echo -n "- Testing Binary ops: "
+echo -n "- Testing Arith Binary ops: "
assert_exit_status 'fn main() { return 1 + 1; }' 2
assert_exit_status 'fn main() { return 1 + 100; }' 101
assert_exit_status 'fn main() { return 100 + 1; }' 101
@@ -36,4 +36,37 @@ assert_exit_status 'fn main() { return 100 / 1; }' 100
assert_exit_status 'fn main() { return 100 / 7; }' 14
assert_exit_status 'fn main() { return 100 / 100; }' 1
assert_exit_status 'fn main() { return 100 / -1; }' 156
+echo " OK"
+
+echo -n "- Testing Relational ops: "
+assert_exit_status 'fn main() { return 1 == 1; }' 1
+assert_exit_status 'fn main() { return 1 == 2; }' 0
+assert_exit_status 'fn main() { return 1 != 1; }' 0
+assert_exit_status 'fn main() { return 1 != 2; }' 1
+
+assert_exit_status 'fn main() { return 1 < 2; }' 1
+assert_exit_status 'fn main() { return 2 < 2; }' 0
+
+assert_exit_status 'fn main() { return 1 <= 2; }' 1
+assert_exit_status 'fn main() { return 2 <= 2; }' 1
+assert_exit_status 'fn main() { return 3 <= 2; }' 0
+
+assert_exit_status 'fn main() { return 2 > 2; }' 0
+assert_exit_status 'fn main() { return 3 > 2; }' 1
+
+assert_exit_status 'fn main() { return 1 >= 2; }' 0
+assert_exit_status 'fn main() { return 2 >= 2; }' 1
+assert_exit_status 'fn main() { return 3 >= 2; }' 1
+echo " OK"
+
+echo -n "- Testing simple logical ops: "
+assert_exit_status 'fn main() { return 0 && 0; }' 0
+assert_exit_status 'fn main() { return 0 && 5; }' 0
+assert_exit_status 'fn main() { return 5 && 0; }' 0
+assert_exit_status 'fn main() { return 5 && 1; }' 1
+
+assert_exit_status 'fn main() { return 0 || 0; }' 0
+assert_exit_status 'fn main() { return 5 || 0; }' 1
+assert_exit_status 'fn main() { return 0 || 3; }' 1
+assert_exit_status 'fn main() { return 2 || 1; }' 1
echo " OK" \ No newline at end of file