test: switch with fallthrough cases (#826)
This commit is contained in:
@@ -3,6 +3,7 @@ package jadx.core.dex.instructions;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import jadx.core.codegen.CodeWriter;
|
||||
import jadx.core.dex.instructions.args.InsnArg;
|
||||
import jadx.core.dex.nodes.BlockNode;
|
||||
import jadx.core.dex.nodes.InsnNode;
|
||||
@@ -110,15 +111,13 @@ public class SwitchNode extends TargetInsnNode {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder targ = new StringBuilder();
|
||||
targ.append('[');
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString());
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
targ.append(InsnUtils.formatOffset(targets[i]));
|
||||
if (i < targets.length - 1) {
|
||||
targ.append(", ");
|
||||
}
|
||||
sb.append(" case ").append(keys[i])
|
||||
.append(": goto ").append(InsnUtils.formatOffset(targets[i]));
|
||||
sb.append(CodeWriter.NL);
|
||||
}
|
||||
targ.append(']');
|
||||
return super.toString() + " k:" + Arrays.toString(keys) + " t:" + targ;
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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;
|
||||
|
||||
public class TestSwitchFallThrough extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
public int r;
|
||||
|
||||
public void test(int a) {
|
||||
int i = 10;
|
||||
switch (a) {
|
||||
case 1:
|
||||
i = 1000;
|
||||
// fallthrough
|
||||
case 2:
|
||||
r = i;
|
||||
break;
|
||||
|
||||
default:
|
||||
r = -1;
|
||||
break;
|
||||
}
|
||||
r *= 2;
|
||||
System.out.println("in: " + a + ", out: " + r);
|
||||
}
|
||||
|
||||
public int testWrap(int a) {
|
||||
r = 0;
|
||||
test(a);
|
||||
return r;
|
||||
}
|
||||
|
||||
public void check() {
|
||||
assertThat(testWrap(1)).isEqualTo(2000);
|
||||
assertThat(testWrap(2)).isEqualTo(20);
|
||||
assertThat(testWrap(0)).isEqualTo(-2);
|
||||
}
|
||||
}
|
||||
|
||||
@NotYetImplemented("switch fallthrough")
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
.containsOnlyOnce("switch");
|
||||
// code correctness checks done in 'check' method
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user