From d471a41369690a9d2d9b8862ea5ff0ae9cbe40fc Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Tue, 1 Feb 2022 04:08:59 -0500 Subject: Add basic `defer` implementation. We don't have any closures yet, so it's essentially the same as just moving the statement after the `defer` keyword to the end of the block/ right before returning from the function. --- tests/core.sh | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100755 tests/core.sh (limited to 'tests/core.sh') diff --git a/tests/core.sh b/tests/core.sh new file mode 100755 index 0000000..71c539d --- /dev/null +++ b/tests/core.sh @@ -0,0 +1,189 @@ +#!/bin/bash + +. tests/common.sh + +set -e + +echo -n "- Basic return: " +assert_exit_status 'fn main() { return 0; }' 0 +assert_exit_status 'fn main() { return 1; }' 1 +assert_exit_status 'fn main() { return 100; }' 100 +echo " OK" + +echo -n "- Unary ops: " +assert_exit_status 'fn main() { return -1; }' 255 +assert_exit_status 'fn main() { return -100; }' 156 +assert_exit_status 'fn main() { return !0; }' 1 +assert_exit_status 'fn main() { return !1; }' 0 +assert_exit_status 'fn main() { return !34; }' 0 +assert_exit_status 'fn main() { return !-1; }' 0 +assert_exit_status 'fn main() { return ~34; }' 221 +echo " OK" + +echo -n "- 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 +assert_exit_status 'fn main() { return 1 - 1; }' 0 +assert_exit_status 'fn main() { return 1 - 100; }' 157 +assert_exit_status 'fn main() { return 100 - 1; }' 99 +assert_exit_status 'fn main() { return 1 * 1; }' 1 +assert_exit_status 'fn main() { return 1 * 100; }' 100 +assert_exit_status 'fn main() { return 100 * 1; }' 100 +assert_exit_status 'fn main() { return 7 * 3; }' 21 +assert_exit_status 'fn main() { return 1 / 1; }' 1 +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 "- 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 "- 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" + +echo -n "- Short-circuiting: " +assert_exit_status_stdin 5 <