-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add primitive cast in ternary for byte and short (PR #601)
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 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
61 changes: 61 additions & 0 deletions
61
jadx-core/src/test/java/jadx/tests/integration/conditions/TestCast.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,61 @@ | ||
package jadx.tests.integration.conditions; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
public class TestCast extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
|
||
byte myByte; | ||
short myShort; | ||
|
||
public void test1(boolean a) { | ||
write(a ? (byte) 0 : 1); | ||
} | ||
|
||
public void test2(boolean a) { | ||
write(a ? 0 : myByte); | ||
} | ||
|
||
public void test3(boolean a) { | ||
write(a ? 0 : Byte.MAX_VALUE); | ||
} | ||
|
||
public void test4(boolean a) { | ||
write(a ? (short) 0 : 1); | ||
} | ||
|
||
public void test5(boolean a) { | ||
write(a ? myShort : 0); | ||
} | ||
|
||
public void test6(boolean a) { | ||
write(a ? Short.MIN_VALUE : 0); | ||
} | ||
|
||
public void write(byte b) { | ||
} | ||
public void write(short b) { | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsString("write(a ? (byte) 0 : 1);")); | ||
assertThat(code, containsString("write(a ? 0 : this.myByte);")); | ||
assertThat(code, containsString("write(a ? 0 : Byte.MAX_VALUE);")); | ||
|
||
assertThat(code, containsString("write(a ? (short) 0 : 1);")); | ||
assertThat(code, containsString("write(a ? this.myShort : 0);")); | ||
assertThat(code, containsString("write(a ? Short.MIN_VALUE : 0);")); | ||
} | ||
} |