diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/control_flow.cpp | 48 | ||||
-rw-r--r-- | test/control_flow.post.js | 4 | ||||
-rw-r--r-- | test/control_flow.txt | 28 |
3 files changed, 80 insertions, 0 deletions
diff --git a/test/control_flow.cpp b/test/control_flow.cpp index 871e21281..504db2646 100644 --- a/test/control_flow.cpp +++ b/test/control_flow.cpp @@ -65,5 +65,53 @@ int EMSCRIPTEN_KEEPALIVE check_while_forever(int x) { return x; } +int EMSCRIPTEN_KEEPALIVE check_switch(int x) { + switch (x) { + case 1: return 10; + case 3: return 20; + case 5: return 30; + case 10: return 40; + case 11: return 50; + default: return 60; + } + return 70; +} + +int EMSCRIPTEN_KEEPALIVE check_switch_nodefault(int x) { + switch (x) { + case 1: return 10; + case 3: return 20; + case 5: return 30; + case 10: return 40; + case 11: return 50; + } + return 70; +} + +int EMSCRIPTEN_KEEPALIVE check_switch_rdefault(int x) { + switch (x) { + default: return -60; + case 1: return 10; + case 3: return 20; + case 5: return 30; + case 10: return 40; + case 11: return 50; + } + return 70; +} + +int EMSCRIPTEN_KEEPALIVE check_switch_fallthrough(int x) { + switch (x) { + case 1: return 10; + case 2: + case 3: x++; + case 5: return x; + case 10: return 40; + case 11: return 50; + default: return 60; + } + return 70; +} + } diff --git a/test/control_flow.post.js b/test/control_flow.post.js index 839806fe9..823580e7b 100644 --- a/test/control_flow.post.js +++ b/test/control_flow.post.js @@ -19,4 +19,8 @@ test('loop_continue'); test('do_loop'); test('do_once'); test('while_forever'); +test('switch'); +test('switch_nodefault'); +test('switch_rdefault'); +test('switch_fallthrough'); diff --git a/test/control_flow.txt b/test/control_flow.txt index c541546a6..68ee62bcd 100644 --- a/test/control_flow.txt +++ b/test/control_flow.txt @@ -47,3 +47,31 @@ while_forever 4 ==> 1922 11 ==> 1346 90 ==> 1426 +switch + 1 ==> 10 + 2 ==> 60 + 3 ==> 20 + 4 ==> 60 + 11 ==> 50 + 90 ==> 60 +switch_nodefault + 1 ==> 10 + 2 ==> 70 + 3 ==> 20 + 4 ==> 70 + 11 ==> 50 + 90 ==> 70 +switch_rdefault + 1 ==> 10 + 2 ==> -60 + 3 ==> 20 + 4 ==> -60 + 11 ==> 50 + 90 ==> -60 +switch_fallthrough + 1 ==> 10 + 2 ==> 3 + 3 ==> 4 + 4 ==> 60 + 11 ==> 50 + 90 ==> 60 |