diff --git a/tests/conditionals.bish b/tests/conditionals.bish new file mode 100644 index 0000000..09b9a15 --- /dev/null +++ b/tests/conditionals.bish @@ -0,0 +1,35 @@ +def test() { + x = 0 + y = 1 + if (y == 1) { + x = 2 + } + assert(x == 2) + + if (y == 2) { + x = 3 + } + assert(x == 2) + + if (y == 0) { + x = 0 + } else if (y == 1) { + x = 1 + } + assert(x == 1) + + for (i in 0 .. 3) { + if (i == 0) { + assert(i == 0) + } else if (i == 1) { + assert(i == 1) + } else if (i == 2) { + assert(i == 2) + } else { + assert(i == 3) + } + } + println("Conditional tests passed.") +} + +test() \ No newline at end of file diff --git a/tests/return_vals.bish b/tests/return_vals.bish new file mode 100644 index 0000000..a53b2b1 --- /dev/null +++ b/tests/return_vals.bish @@ -0,0 +1,24 @@ +# Tests for return values. + +def lastchar(x) { + if (x != "") { + y = @(echo -ne "$x" | tail -c 1) + x = "$y" + } + return x +} + +def test() { + h = lastchar("hello") + assert(h == "o") + assert(lastchar("hello") == "o") + assert(lastchar("") == "") + println("Return value tests passed.") +} + +# Include some module-level tests +h = lastchar("hello") +assert(h == "o") +assert(lastchar("hello") == "o") + +test() \ No newline at end of file diff --git a/tests/tests.bish b/tests/tests.bish index 5e61a8e..360cedf 100644 --- a/tests/tests.bish +++ b/tests/tests.bish @@ -46,6 +46,9 @@ def run_all() { import return_vals return_vals.test() + + import conditionals + conditionals.test() } change_dir()