aboutsummaryrefslogtreecommitdiff
path: root/tests/variables.sh
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-01-29 13:52:58 -0500
committerMustafa Quraish <[email protected]>2022-01-29 13:53:57 -0500
commite403475bbf6f70b3e79b6f4503dbadcc3dad504c (patch)
tree40c77638cf96048328358e601c541ab31fb2b23a /tests/variables.sh
parentAdd some tests for local variables (diff)
downloadcup-e403475bbf6f70b3e79b6f4503dbadcc3dad504c.tar.xz
cup-e403475bbf6f70b3e79b6f4503dbadcc3dad504c.zip
Allow uninitialized variable declarations
Diffstat (limited to 'tests/variables.sh')
-rwxr-xr-xtests/variables.sh30
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"