Skip to content

Commit

Permalink
Test cases for elliotchance#693
Browse files Browse the repository at this point in the history
  • Loading branch information
kamphaus authored and christophe-kamphaus-jemmic committed May 14, 2018
1 parent 570d3ad commit b16b421
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion tests/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// CompoundStmt with 12 children.

#include <stdio.h>
#include <stdbool.h>
#include "tests.h"

void match_a_single_case()
Expand Down Expand Up @@ -125,6 +126,42 @@ void fallthrough_several_midway_default()
}
}

void goto_label(bool use_goto)
{
for (;;) {
switch (0)
{
case 3:
continue;
case 0:
if (use_goto) {
goto LABEL;
fail("code should not reach here");
} else if (false) {
goto LABELX;
goto LABELY;
fail("code should not reach here");
}
/* other comment */
// some comment
/* fallthrough */
LABELY:
case 4:
LABEL:
case 1:
pass(__func__);
break;
case 2:
;
LABELX:
default:
fail("code should not reach here");
break;
}
break;
}
}

void scoped_match_a_single_case()
{
switch (1)
Expand Down Expand Up @@ -278,6 +315,51 @@ void scoped_fallthrough_several_midway_default()
}
}


void scoped_goto_label(bool use_goto)
{
for (;;) {
switch (0)
{
case 3:
{
continue;
}
case 0:
{
if (use_goto) {
goto LABEL;
fail("code should not reach here");
} else if (false) {
goto LABELX;
goto LABELY;
fail("code should not reach here");
}
/* other comment */
// some comment
/* fallthrough */
}
LABELY: {}
case 4: {}
LABEL: {}
case 1:
{
pass(__func__);
break;
}
case 2:
{}
LABELX: {}
default:
{
fail("code should not reach here");
break;
}
}
break;
}
}

typedef struct I67 I67;
struct I67{
int x,y;
Expand Down Expand Up @@ -376,14 +458,16 @@ void switch_without_input()

int main()
{
plan(33);
plan(37);

match_a_single_case();
fallthrough_to_next_case();
match_no_cases();
match_default();
fallthrough_several_cases_including_default();
fallthrough_several_midway_default();
goto_label(false);
goto_label(true);

// For each of the tests above there will be identical cases that use scopes
// for the case statements.
Expand All @@ -393,6 +477,8 @@ int main()
scoped_match_default();
scoped_fallthrough_several_cases_including_default();
scoped_fallthrough_several_midway_default();
scoped_goto_label(false);
scoped_goto_label(true);

switch_issue67();
empty_switch();
Expand Down

0 comments on commit b16b421

Please sign in to comment.