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/goto.sh | |
| parent | 7e11675136edf8136f812c85cd45bc88ba405533 (diff) | |
| download | ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.tar.gz ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.tar.zst ducc-46e79e69ae866df88cb9442a7329c72662ed2db3.zip | |
refactor: rename test files
Diffstat (limited to 'tests/goto.sh')
| -rw-r--r-- | tests/goto.sh | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/tests/goto.sh b/tests/goto.sh new file mode 100644 index 0000000..1e28a51 --- /dev/null +++ b/tests/goto.sh @@ -0,0 +1,168 @@ +touch expected +test_diff <<'EOF' +int main() { + goto end; + return 1; +end: + return 0; +} +EOF + +cat <<'EOF' > expected +1 +2 +3 +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int main() { + int i = 0; +loop: + i++; + printf("%d\n", i); + if (i < 3) + goto loop; + return 0; +} +EOF + +cat < /dev/null > expected +test_diff <<'EOF' +int main() { + goto skip; + int x = 5; +skip: + return 0; +} +EOF + +cat <<'EOF' > expected +start +middle +end +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int main() { + printf("start\n"); + goto middle; +first: + printf("first\n"); + goto end; +middle: + printf("middle\n"); + goto end; +last: + printf("last\n"); +end: + printf("end\n"); + return 0; +} +EOF + +cat <<'EOF' > expected +before +after +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int main() { + printf("before\n"); + { + { + goto out; + printf("inside\n"); + } + printf("middle\n"); + } +out: + printf("after\n"); + return 0; +} +EOF + +cat <<'EOF' > expected +x is 5 +x is 10 +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int main() { + int x = 5; + if (x == 5) { + printf("x is 5\n"); + goto next; + } + printf("x is not 5\n"); +next: + x = 10; + printf("x is %d\n", x); + return 0; +} +EOF + +cat <<'EOF' > expected +case 2 +done +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int main() { + int x = 2; + switch (x) { + case 1: + printf("case 1\n"); + break; + case 2: + printf("case 2\n"); + goto done; + case 3: + printf("case 3\n"); + break; + } + printf("after switch\n"); +done: + printf("done\n"); + return 0; +} +EOF + +# cat <<'EOF' > expected +# error: use of undeclared label 'undefined' +# EOF +# test_compile_error <<'EOF' +# int main() { +# goto undefined; +# return 0; +# } +# EOF + +# cat <<'EOF' > expected +# error: redefinition of label 'duplicate' +# EOF +# test_compile_error <<'EOF' +# int main() { +# duplicate: +# ; +# duplicate: +# return 0; +# } +# EOF + +# cat <<'EOF' > expected +# error: label at end of compound statement +# EOF +# test_compile_error <<'EOF' +# int main() { +# { +# goto end; +# end: +# } +# return 0; +# } +# EOF |
