Skip to content

Commit 3c41c37

Browse files
committed
GROOVY-9272
1 parent 236be56 commit 3c41c37

File tree

1 file changed

+108
-4
lines changed
  • base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic

1 file changed

+108
-4
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java

+108-4
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ public void testAbstractClass_GRE274_2() {
30533053
public void testSwitchCases1() {
30543054
//@formatter:off
30553055
String[] sources = {
3056-
"X.groovy",
3056+
"Main.groovy",
30573057
"def foo(p) {\n" +
30583058
" switch (p) {\n" +
30593059
" case 1:\n" +
@@ -3083,7 +3083,7 @@ public void testSwitchCases1() {
30833083
public void testSwitchCases2() {
30843084
//@formatter:off
30853085
String[] sources = {
3086-
"X.groovy",
3086+
"Main.groovy",
30873087
"def foo(p) {\n" +
30883088
" switch (p) {\n" +
30893089
" case 1:\n" +
@@ -3110,7 +3110,7 @@ public void testSwitchCases2() {
31103110
public void testSwitchCases3() {
31113111
//@formatter:off
31123112
String[] sources = {
3113-
"X.groovy",
3113+
"Main.groovy",
31143114
"def foo(x,y) {\n" +
31153115
" switch (x) {\n" +
31163116
" case 'x1':\n" +
@@ -3132,11 +3132,115 @@ public void testSwitchCases3() {
31323132
runConformTest(sources, "r1");
31333133
}
31343134

3135+
@Test // GROOVY-9272
3136+
public void testSwitchCases4() {
3137+
assumeTrue(isParrotParser() && isAtLeastGroovy(40));
3138+
3139+
//@formatter:off
3140+
String[] sources = {
3141+
"Main.groovy",
3142+
"def s = 'Bar'\n" +
3143+
"int yield = switch (s) {\n" +
3144+
" case 'Foo':\n" +
3145+
" yield 1\n" +
3146+
" case 'Bar':\n" +
3147+
" print 2\n" +
3148+
" case 'Baz':\n" +
3149+
" yield 3\n" +
3150+
" default:\n" +
3151+
" yield 0\n" +
3152+
"}\n" +
3153+
"print yield\n",
3154+
};
3155+
//@formatter:on
3156+
3157+
runConformTest(sources, "23");
3158+
}
3159+
3160+
@Test // GROOVY-9272
3161+
public void testSwitchCases5() {
3162+
assumeTrue(isParrotParser() && isAtLeastGroovy(40));
3163+
3164+
//@formatter:off
3165+
String[] sources = {
3166+
"Main.groovy",
3167+
"import java.time.DayOfWeek\n" +
3168+
"import static java.time.DayOfWeek.*\n" +
3169+
"\n" +
3170+
"void test(DayOfWeek day) {\n" +
3171+
" int letterCount = switch (day) {\n" +
3172+
" case MONDAY, FRIDAY, SUNDAY -> 6\n" +
3173+
" case TUESDAY -> 7\n" +
3174+
" case THURSDAY, SATURDAY -> { 8 }\n" +
3175+
" case WEDNESDAY -> { yield 9 }\n" +
3176+
" default -> throw new IllegalStateException(\"Invalid day: $day\")\n" +
3177+
" }\n" +
3178+
" print letterCount\n" +
3179+
"}\n" +
3180+
"test(WEDNESDAY)\n",
3181+
};
3182+
//@formatter:on
3183+
3184+
runConformTest(sources, "9");
3185+
}
3186+
3187+
@Test // GROOVY-9272
3188+
public void testSwitchCases6() {
3189+
assumeTrue(isParrotParser() && isAtLeastGroovy(40));
3190+
3191+
//@formatter:off
3192+
String[] sources = {
3193+
"Main.groovy",
3194+
"import java.time.DayOfWeek\n" +
3195+
"import static java.time.DayOfWeek.*\n" +
3196+
"\n" +
3197+
"void test(DayOfWeek day) {\n" +
3198+
" int letterCount = switch (day) {\n" +
3199+
" case MONDAY, FRIDAY, SUNDAY: yield 6\n" +
3200+
" case TUESDAY : yield 7\n" +
3201+
" case THURSDAY, SATURDAY : yield 8\n" +
3202+
" case WEDNESDAY : { yield 9 }\n" +
3203+
" default : throw new IllegalStateException(\"Invalid day: $day\")\n" +
3204+
" }\n" +
3205+
" print letterCount\n" +
3206+
"}\n" +
3207+
"test(WEDNESDAY)\n",
3208+
};
3209+
//@formatter:on
3210+
3211+
runConformTest(sources, "9");
3212+
}
3213+
3214+
@Test // GROOVY-9272
3215+
public void testSwitchCases7() {
3216+
assumeTrue(isParrotParser() && isAtLeastGroovy(40));
3217+
3218+
//@formatter:off
3219+
String[] sources = {
3220+
"Main.groovy",
3221+
"import java.time.DayOfWeek\n" +
3222+
"import static java.time.DayOfWeek.*\n" +
3223+
"\n" +
3224+
"void test(DayOfWeek day) {\n" +
3225+
" print(switch (day) {\n" +
3226+
" case MONDAY..FRIDAY : yield 'work day'\n" +
3227+
" case [SATURDAY, SUNDAY]: yield 'weekend'\n" +
3228+
" })\n" +
3229+
"}\n" +
3230+
"test(SUNDAY)\n" +
3231+
"print ' '\n" +
3232+
"test(WEDNESDAY)\n",
3233+
};
3234+
//@formatter:on
3235+
3236+
runConformTest(sources, "weekend work day");
3237+
}
3238+
31353239
@Test // GROOVY-9880
31363240
public void testBreakAfterIf() {
31373241
//@formatter:off
31383242
String[] sources = {
3139-
"X.groovy",
3243+
"Main.groovy",
31403244
"switch ('value') {\n" +
31413245
" case 'value':\n" +
31423246
" print 'foo'\n" +

0 commit comments

Comments
 (0)