Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional switch test cases #215

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/test/java/jd/core/test/EnumSwitch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package jd.core.test;
/*
* A test input for the enum switch pattern.
*/
public class EnumSwitch {

static enum Digit {
_0, _1, _2, _3, _4, _5, _6, _7, _8, _9
}

void stringSwitch(Digit inputValue) {
switch (inputValue) {
case _1:
System.out.println("One");

break;

case _2:
System.out.println("Two");

break;

case _4:
System.out.println("Four");

break;

case _8:
System.out.println("Eight");

break;
case _3: case _5: case _6:
case _7: default:
throw new IllegalArgumentException();
}
}
}
17 changes: 14 additions & 3 deletions src/test/java/jd/core/test/StringSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ void stringSwitch(String inputValue) {
switch (inputValue) {
case "1":
System.out.println("One");

break;

case "2":
System.out.println("Two");

break;

case "4":
System.out.println("Four");

break;
case "3":
System.out.println("Three");

case "8":
System.out.println("Eight");

break;
default:
case "3": case "5": case "6":
case "7": default:
throw new IllegalArgumentException();
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/jd/core/test/SwitchEnumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public void testSwitchEnum() throws Exception {
assertEquals(IOUtils.toString(getClass().getResource("SwitchEnum.txt"), StandardCharsets.UTF_8), output);
}

@Test
public void testEnumSwitch() throws Exception {
String internalClassName = "jd/core/test/EnumSwitch";
String output = decompile(internalClassName);
assertEquals(IOUtils.toString(getClass().getResource("EnumSwitch.txt"), StandardCharsets.UTF_8), output);
}

@Test
public void testSwitchEnumJDK180() throws Exception {
try (InputStream in = getClass().getResourceAsStream("/switch-enum-jdk1.8.0_331.jar")) {
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/jd/core/test/TableSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,58 @@ void tableSwitch() {
throw new IllegalArgumentException();
}
}

public void tableSwitch2(int value) {
switch (value) {
case 1:
System.out.println("One");

break;

case 2:
System.out.println("Two");

break;

case 4:
System.out.println("Four");

break;

case 8:
System.out.println("Eight");

break;
case 3: case 5: case 6:
case 7: default:
throw new IllegalArgumentException();
}
}

public void tableSwitch3(char value) {
switch (value) {
case '1':
System.out.println("One");

break;

case '2':
System.out.println("Two");

break;

case '4':
System.out.println("Four");

break;

case '8':
System.out.println("Eight");

break;
case '3': case '5': case '6':
case '7': default:
throw new IllegalArgumentException();
}
}
}
37 changes: 37 additions & 0 deletions src/test/resources/jd/core/test/EnumSwitch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* */ package jd.core.test;
/* */
/* */
/* */ public class EnumSwitch
/* */ {
/* */ static enum Digit
/* */ {
/* 8 */ _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
/* */ }
/* */
/* */ void stringSwitch(Digit inputValue) {
/* 12 */ switch (inputValue) {
/* */ case _1:
/* 14 */ System.out.println("One");
/* */
/* 16 */ break;
/* */
/* */ case _2:
/* 19 */ System.out.println("Two");
/* */
/* 21 */ break;
/* */
/* */ case _4:
/* 24 */ System.out.println("Four");
/* */
/* 26 */ break;
/* */
/* */ case _8:
/* 29 */ System.out.println("Eight");
/* */
/* 31 */ break;
/* */ case _3: case _5: case _6:
/* */ case _7: default:
/* 34 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */ }
25 changes: 18 additions & 7 deletions src/test/resources/jd/core/test/StringSwitch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@
/* 8 */ switch (inputValue) {
/* */ case "1":
/* 10 */ System.out.println("One");
/* 11 */ break;
/* */
/* 12 */ break;
/* */
/* */ case "2":
/* 13 */ System.out.println("Two");
/* 14 */ break;
/* */ case "3":
/* 16 */ System.out.println("Three");
/* 15 */ System.out.println("Two");
/* */
/* 17 */ break;
/* */ default:
/* 19 */ throw new IllegalArgumentException();
/* */
/* */ case "4":
/* 20 */ System.out.println("Four");
/* */
/* 22 */ break;
/* */
/* */ case "8":
/* 25 */ System.out.println("Eight");
/* */
/* 27 */ break;
/* */ case "3": case "5": case "6":
/* */ case "7": default:
/* 30 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */ }
54 changes: 54 additions & 0 deletions src/test/resources/jd/core/test/TableSwitch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,58 @@
/* 21 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */
/* */ public void tableSwitch2(int value) {
/* 26 */ switch (value) {
/* */ case 1:
/* 28 */ System.out.println("One");
/* */
/* 30 */ break;
/* */
/* */ case 2:
/* 33 */ System.out.println("Two");
/* */
/* 35 */ break;
/* */
/* */ case 4:
/* 38 */ System.out.println("Four");
/* */
/* 40 */ break;
/* */
/* */ case 8:
/* 43 */ System.out.println("Eight");
/* */
/* 45 */ break;
/* */ case 3: case 5: case 6:
/* */ case 7: default:
/* 48 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */
/* */ public void tableSwitch3(char value) {
/* 53 */ switch (value) {
/* */ case '1':
/* 55 */ System.out.println("One");
/* */
/* 57 */ break;
/* */
/* */ case '2':
/* 60 */ System.out.println("Two");
/* */
/* 62 */ break;
/* */
/* */ case '4':
/* 65 */ System.out.println("Four");
/* */
/* 67 */ break;
/* */
/* */ case '8':
/* 70 */ System.out.println("Eight");
/* */
/* 72 */ break;
/* */ case '3': case '5': case '6':
/* */ case '7': default:
/* 75 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */ }
Binary file modified src/test/resources/jdk7-features.jar
Binary file not shown.