diff options
| author | Mustafa Quraish <[email protected]> | 2022-01-29 13:52:58 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-01-29 13:53:57 -0500 |
| commit | e403475bbf6f70b3e79b6f4503dbadcc3dad504c (patch) | |
| tree | 40c77638cf96048328358e601c541ab31fb2b23a /tests/variables.sh | |
| parent | Add some tests for local variables (diff) | |
| download | cup-e403475bbf6f70b3e79b6f4503dbadcc3dad504c.tar.xz cup-e403475bbf6f70b3e79b6f4503dbadcc3dad504c.zip | |
Allow uninitialized variable declarations
Diffstat (limited to 'tests/variables.sh')
| -rwxr-xr-x | tests/variables.sh | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/variables.sh b/tests/variables.sh index 94010d7..0c88784 100755 --- a/tests/variables.sh +++ b/tests/variables.sh @@ -5,9 +5,27 @@ set -e echo -n "- One variable: " -assert_exit_status 'fn main() { let x: int = 45; return 1; }' 1 +assert_exit_status 'fn main() { let x: int; x = 45; return x; }' 45 assert_exit_status 'fn main() { let x: int = 45; return x; }' 45 assert_exit_status 'fn main() { let x: int = 45; return x+x; }' 90 + +assert_exit_status_stdin 5 <<EOF +fn main() { + let x: int; + x = 3; + x = 5; + return x; +} +EOF + +assert_exit_status_stdin 5 <<EOF +fn main() { + let x: int = 3; + x = x + x - 1; + return x; +} +EOF + echo " OK" echo -n "- Multiple variable: " @@ -31,4 +49,14 @@ fn main() { } EOF +assert_exit_status_stdin 2 <<EOF +fn main() { + let x: int = 1; + let y: int = x + x; + y = y + x; + x = (x + x) * y; + return x / y; +} +EOF + echo " OK" |