[java] SwitchStmtsShouldHaveDefault - test for multiple case constants

This commit is contained in:
Andreas Dangel 2024-10-08 17:15:18 +02:00
parent 59403fc9e1
commit ff1b9b2cdd
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3

View File

@ -329,6 +329,39 @@ public class SwitchWithRecordPattern {
}
}
}
]]></code>
</test-code>
<test-code>
<description>Multiple Case Constants</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
enum MyEnum { A, B, C }
public class SwitchMultipleCaseConstants {
public void switchLabels(MyEnum e) {
switch(e) {
case A,B: System.out.println("a or b"); break;
case C: System.out.println("c");
}
String s = switch(e) {
case A,B: yield "a or b";
case C: yield "c";
};
System.out.println(s);
}
public void switchRules(MyEnum e) {
switch(e) {
case A,B -> System.out.println("a or b");
case C -> System.out.println("c");
}
String s = switch(e) {
case A,B -> "a or b";
case C -> "c";
};
System.out.println(s);
}
}
]]></code>
</test-code>
</test-data>