-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support "fall-through to default" case in switch-over-string (PR #…
- Loading branch information
Showing
3 changed files
with
78 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchOverStrings2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package jadx.tests.integration.switches; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestSwitchOverStrings2 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
|
||
public int test(String str) { | ||
switch (str) { | ||
case "branch1": | ||
case "branch2": | ||
return 1; | ||
case "branch3": | ||
case "branch4": | ||
default: | ||
return 0; | ||
} | ||
} | ||
|
||
public void check() { | ||
assertThat(test("branch1")).isEqualTo(1); | ||
assertThat(test("branch2")).isEqualTo(1); | ||
assertThat(test("branch3")).isEqualTo(0); | ||
assertThat(test("branch4")).isEqualTo(0); | ||
assertThat(test("other")).isEqualTo(0); | ||
assertThat(test("other2")).isEqualTo(0); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.countString(4, "case ") | ||
.countString(1, "default:") | ||
.countString(2, "return "); | ||
} | ||
} |