From 4d1c4e28b8d8368a105717e142f8e920cbf4ea0f Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 6 Oct 2020 22:39:14 +0200 Subject: eval: properly break out of switch/case on return/continue/exception Signed-off-by: Jo-Philipp Wich --- tests/02_runtime/04_switch_case | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'tests') diff --git a/tests/02_runtime/04_switch_case b/tests/02_runtime/04_switch_case index 9a871fd..bc8b80e 100644 --- a/tests/02_runtime/04_switch_case +++ b/tests/02_runtime/04_switch_case @@ -177,3 +177,96 @@ true print(x, "\n"); %} -- End -- + + +8. Ensure that `return` breaks out of switch statements. + +-- Expect stdout -- +one +two +-- End -- + +-- Testcase -- +{% + function test(n) { + switch (n) { + case 1: + return "one"; + + case 2: + return "two"; + + default: + return "three"; + } + } + + print(test(1), "\n"); + print(test(2), "\n"); +%} +-- End -- + + +9. Ensure that `continue` breaks out of switch statements. + +-- Expect stdout -- +one +two +-- End -- + +-- Testcase -- +{% + for (n in [1,2]) { + switch (n) { + case 1: + print("one\n"); + continue; + + case 2: + print("two\n"); + continue; + + default: + print("three\n"); + } + } +%} +-- End -- + + +10. Ensure that exceptions break out of switch statements. + +-- Expect stdout -- +one +-- End -- + +-- Expect stderr -- +Died +In line 6, byte 7: + + ` die();` + Near here ------^ + + +-- End -- + +-- Testcase -- +{% + function test(n) { + switch (n) { + case 1: + print("one\n"); + die(); + + case 2: + print("two\n"); + die(); + + default: + print("three\n"); + } + } + + print(test(1), "\n"); +%} +-- End -- -- cgit v1.2.3