core: fix switch in loop (fix #52)

This commit is contained in:
Skylot
2015-03-01 18:15:44 +03:00
parent 46d3992b41
commit f366eac7eb
2 changed files with 55 additions and 6 deletions
@@ -0,0 +1,44 @@
package jadx.tests.integration.switches;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import org.junit.Test;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class TestSwitchInLoop extends IntegrationTest {
public static class TestCls {
public int test(int k) {
int a = 0;
while (true) {
switch (k) {
case 0:
return a;
default:
a++;
k >>= 1;
}
}
}
public void check() {
assertEquals(1, test(1));
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("switch (k) {"));
assertThat(code, containsOne("case 0:"));
assertThat(code, containsOne("return a;"));
assertThat(code, containsOne("default:"));
assertThat(code, containsOne("a++;"));
assertThat(code, containsOne("k >>= 1;"));
}
}