From 4c7013bf5386cb9bad9610c282f24589d8efa647 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 24 Jan 2023 20:07:20 +0200 Subject: [PATCH] Combine for loop and while loop tests into the same file (#135) --- tests/should_succeed/for.jou | 27 -------- .../infinite_loop_but_doesnt_return_void.jou | 10 --- tests/should_succeed/loops.jou | 62 +++++++++++++++++++ tests/should_succeed/while.jou | 35 ----------- 4 files changed, 62 insertions(+), 72 deletions(-) delete mode 100644 tests/should_succeed/for.jou delete mode 100644 tests/should_succeed/infinite_loop_but_doesnt_return_void.jou create mode 100644 tests/should_succeed/loops.jou delete mode 100644 tests/should_succeed/while.jou diff --git a/tests/should_succeed/for.jou b/tests/should_succeed/for.jou deleted file mode 100644 index ff38acf2..00000000 --- a/tests/should_succeed/for.jou +++ /dev/null @@ -1,27 +0,0 @@ -from "stdlib/io.jou" import printf - -def main() -> int: - # Output: 0 - # Output: 1 - # Output: 2 - for i = 0; i < 3; i = i+1: - printf("%d\n", i) - - # Output: 0->1->2->3->end - for i = 0; True; i = i+1: - printf("%d->", i) - if i == 3: - printf("end\n") - break - printf("yooooooo\n") # Warning: this code will never run - - # Output: 0...4...8. - for i = 0; i < 10; i = i+1: - if i % 4 != 0: - printf(".") - continue - printf("yooooooo\n") # Warning: this code will never run - printf("%d", i) - printf("\n") - - return 0 diff --git a/tests/should_succeed/infinite_loop_but_doesnt_return_void.jou b/tests/should_succeed/infinite_loop_but_doesnt_return_void.jou deleted file mode 100644 index 3fc480be..00000000 --- a/tests/should_succeed/infinite_loop_but_doesnt_return_void.jou +++ /dev/null @@ -1,10 +0,0 @@ -from "stdlib/io.jou" import puts - -# No warning or error for missing return statement. -# But we can't call this function as it loops infinitely. -def foo() -> int: - while True: - puts("Hi") - -def main() -> int: - return 0 diff --git a/tests/should_succeed/loops.jou b/tests/should_succeed/loops.jou new file mode 100644 index 00000000..4ecdc64d --- /dev/null +++ b/tests/should_succeed/loops.jou @@ -0,0 +1,62 @@ +from "stdlib/io.jou" import printf + +# No warning or error for missing return statement. +# But we can't call this function as it loops infinitely. +def foo() -> int: + while True: + printf("Hi\n") + +def main() -> int: + # Output: 0 + # Output: 1 + # Output: 2 + i = 0 + while i < 3: + printf("%d\n", i++) + + # Output: 0 + # Output: 1 + # Output: 2 + for i = 0; i < 3; i++: + printf("%d\n", i) + + # Output: 0->1 1->2 2->3 3->end + i = 0 + while True: + printf("%d->", i) + if i == 3: + printf("end\n") + break + printf("yooooooo\n") # Warning: this code will never run + printf("%d ", ++i) + + # Output: 0->1->2->3->end + for i = 0; True; i++: + printf("%d->", i) + if i == 3: + printf("end\n") + break + printf("yooooooo\n") # Warning: this code will never run + + # Output: 0...4...8. + i = 0 + while i < 10: + if i % 4 != 0: + printf(".") + i++ + continue + printf("yooooooo\n") # Warning: this code will never run + printf("%d", i) + i++ + printf("\n") + + # Output: 0...4...8. + for i = 0; i < 10; i++: + if i % 4 != 0: + printf(".") + continue + printf("yooooooo\n") # Warning: this code will never run + printf("%d", i) + printf("\n") + + return 0 diff --git a/tests/should_succeed/while.jou b/tests/should_succeed/while.jou deleted file mode 100644 index 54ad90fc..00000000 --- a/tests/should_succeed/while.jou +++ /dev/null @@ -1,35 +0,0 @@ -from "stdlib/io.jou" import printf - -def main() -> int: - # Output: 0 - # Output: 1 - # Output: 2 - i = 0 - while i < 3: - printf("%d\n", i) - i = i+1 - - # Output: 0->1 1->2 2->3 3->end - i = 0 - while True: - printf("%d->", i) - if i == 3: - printf("end\n") - break - printf("yooooooo\n") # Warning: this code will never run - i = i+1 - printf("%d ", i) - - # Output: 0...4...8. - i = 0 - while i < 10: - if i % 4 != 0: - printf(".") - i = i+1 - continue - printf("yooooooo\n") # Warning: this code will never run - printf("%d", i) - i = i+1 - printf("\n") - - return 0