Skip to content

Commit

Permalink
Add more tests for arrow and multi-case switch statements in MissingC…
Browse files Browse the repository at this point in the history
…asesInEnumSwitchTest

PiperOrigin-RevId: 655288858
  • Loading branch information
cushon authored and Error Prone Team committed Jul 23, 2024
1 parent 996d09c commit 7b58ec9
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,63 @@ public void empty() {
"}")
.doTest();
}

@Test
public void nonExhaustive_arrowStatement() {
assumeTrue(RuntimeVersion.isAtLeast14());
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" enum Case { ONE, TWO }",
" void m(Case c) {",
" // BUG: Diagnostic contains: TWO",
" switch (c) {",
" case ONE -> {",
" System.err.println(\"found it!\");",
" }",
" }",
" }",
"}")
.doTest();
}

@Test
public void nonExhaustive_multi() {
assumeTrue(RuntimeVersion.isAtLeast14());
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" enum Case { ONE, TWO, THREE }",
" void m(Case c) {",
" // BUG: Diagnostic contains: THREE",
" switch (c) {",
" case ONE, TWO:",
" System.err.println(\"found it!\");",
" }",
" }",
"}")
.doTest();
}

@Test
public void nonExhaustive_multiArrow() {
assumeTrue(RuntimeVersion.isAtLeast14());
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" enum Case { ONE, TWO, THREE }",
" void m(Case c) {",
" // BUG: Diagnostic contains: THREE",
" switch (c) {",
" case ONE, TWO -> {",
" System.err.println(\"found it!\");",
" }",
" }",
" }",
"}")
.doTest();
}
}

0 comments on commit 7b58ec9

Please sign in to comment.