diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-10-04 15:33:07 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-10-04 15:33:10 +0900 |
| commit | 46e79e69ae866df88cb9442a7329c72662ed2db3 (patch) | |
| tree | 13561c1e7273ed0311da37957e4a82d15b243ba4 /tests/for_loops.sh | |
| parent | 7e11675136edf8136f812c85cd45bc88ba405533 (diff) | |
| download | ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.tar.gz ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.tar.zst ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.zip | |
refactor: rename test files
Diffstat (limited to 'tests/for_loops.sh')
| -rw-r--r-- | tests/for_loops.sh | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/tests/for_loops.sh b/tests/for_loops.sh new file mode 100644 index 0000000..2e3205f --- /dev/null +++ b/tests/for_loops.sh @@ -0,0 +1,141 @@ +test_exit_code 45 <<'EOF' +int main() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 10; i = i + 1) { + ret = ret + i; + } + return ret; +} +EOF + +test_exit_code 25 <<'EOF' +int main() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 10; i = i + 1) { + if (i % 2 == 0) { + continue; + } + ret = ret + i; + } + return ret; +} +EOF + +test_exit_code 66 <<'EOF' +int main() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 100; i = i + 1) { + if (i == 12) { + break; + } + ret = ret + i; + } + return ret; +} +EOF + +cat <<'EOF' > expected +0 +1 +2 +3 +4 +10 +11 +12 +13 +14 +20 +21 +22 +23 +24 +25 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + int i = 0; + for (; i < 5; i = i + 1) { + printf("%d\n", i); + } + for (i = 10; i < 15; ) { + printf("%d\n", i); + i = i + 1; + } + for (i = 20; ; i = i + 1) { + printf("%d\n", i); + if (i == 25) break; + } + + return 0; +} +EOF + +cat <<'EOF' > expected +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + for (int i = 0; i < 10; i++) { + printf("%d\n", i); + } +} +EOF + +cat <<'EOF' > expected +0 +1 +2 +3 +4 +0 +1 +2 +3 +4 +43 +42 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + for (int i = 0; i < 5; i++) { + printf("%d\n", i); + } + for (int i = 0; i < 5; i++) { + printf("%d\n", i); + } + int x = 42; + { + int x = 43; + printf("%d\n", x); + } + printf("%d\n", x); +} +EOF + |
