fix: improve 'out' block detection in switch (#826)
This commit is contained in:
@@ -10,6 +10,10 @@ public class JadxCodeAssertions extends AbstractStringAssert<JadxCodeAssertions>
|
||||
super(code, JadxCodeAssertions.class);
|
||||
}
|
||||
|
||||
public JadxCodeAssertions containsOne(String substring) {
|
||||
return countString(1, substring);
|
||||
}
|
||||
|
||||
public JadxCodeAssertions countString(int count, String substring) {
|
||||
isNotNull();
|
||||
int actualCount = TestUtils.count(actual, substring);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class TestSwitch2 extends IntegrationTest {
|
||||
boolean isScrolling;
|
||||
float multiTouchZoomOldDist;
|
||||
|
||||
void test(int action) {
|
||||
public void test(int action) {
|
||||
switch (action & 255) {
|
||||
case 0:
|
||||
this.isLongtouchable = true;
|
||||
|
||||
@@ -2,7 +2,6 @@ package jadx.tests.integration.switches;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.NotYetImplemented;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
@@ -12,6 +11,7 @@ public class TestSwitchFallThrough extends IntegrationTest {
|
||||
public static class TestCls {
|
||||
public int r;
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
public void test(int a) {
|
||||
int i = 10;
|
||||
switch (a) {
|
||||
@@ -43,12 +43,14 @@ public class TestSwitchFallThrough extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@NotYetImplemented("switch fallthrough")
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
.containsOnlyOnce("switch");
|
||||
.containsOne("switch (a) {")
|
||||
.containsOne("r = i;")
|
||||
.containsOne("r = -1;")
|
||||
.countString(2, "break;");
|
||||
// code correctness checks done in 'check' method
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public class TestSwitchReturnFromCase extends IntegrationTest {
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsString("switch (a % 10) {"));
|
||||
|
||||
// case 5: removed
|
||||
assertEquals(5, count(code, "case "));
|
||||
assertEquals(3, count(code, "break;"));
|
||||
|
||||
|
||||
+1
@@ -26,6 +26,7 @@ public class TestSwitchWithFallThroughCase extends IntegrationTest {
|
||||
}
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case 2:
|
||||
if (b) {
|
||||
str += "2";
|
||||
|
||||
Reference in New Issue
Block a user