diff options
| author | Mustafa Quraish <[email protected]> | 2022-01-29 17:37:00 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-01-29 17:37:00 -0500 |
| commit | a9683512b29abd53814bf834e23f752a8999a679 (patch) | |
| tree | 033d76dbf7b1249354d2967b9de53fd6af20b7cb /tests/variables.sh | |
| parent | Add i64{max,min} helper functions (diff) | |
| download | cup-a9683512b29abd53814bf834e23f752a8999a679.tar.xz cup-a9683512b29abd53814bf834e23f752a8999a679.zip | |
Implement blocks (lexically scoped) and conditionals
Diffstat (limited to 'tests/variables.sh')
| -rwxr-xr-x | tests/variables.sh | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/variables.sh b/tests/variables.sh index 0c88784..7b44fe7 100755 --- a/tests/variables.sh +++ b/tests/variables.sh @@ -29,7 +29,6 @@ EOF echo " OK" echo -n "- Multiple variable: " - assert_exit_status_stdin 2 <<EOF fn main() { let x: int = 1; @@ -59,4 +58,46 @@ fn main() { } EOF +assert_exit_status_stdin 18 <<EOF +fn main() { + let x: int = 5; + let y: int; + let z: int = (y = x + 3) + 2; + return z + y; +} +EOF +echo " OK" + +echo -n "- Short-circuiting assignments: " +assert_exit_status_stdin 5 <<EOF +fn main() { + let x: int = 5; + let y: int = (1 || (x = 10)); + return x; +} +EOF + +assert_exit_status_stdin 10 <<EOF +fn main() { + let x: int = 5; + let y: int = (0 || (x = 10)); + return x; +} +EOF + +assert_exit_status_stdin 5 <<EOF +fn main() { + let x: int = 5; + let y: int = (0 && (x = 10)); + return x; +} +EOF + +assert_exit_status_stdin 10 <<EOF +fn main() { + let x: int = 5; + let y: int = (1 && (x = 10)); + return x; +} +EOF echo " OK" |