Skip to content

Commit

Permalink
another test for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Dec 5, 2024
1 parent eddc324 commit 2f54346
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class DropInvalidMappingsTest extends CommandTest {
private static final Path EMPTY_MAPPINGS_EXPECTED = EXPECTED_DIR.resolve("EmptyMappings.mapping");
private static final Path MAPPING_SAVE_INPUT = INPUT_DIR.resolve("MappingSave.mapping");
private static final Path MAPPING_SAVE_EXPECTED = EXPECTED_DIR.resolve("MappingSave.mapping");
private static final Path DISCARD_INNER_CLASS_INPUT = INPUT_DIR.resolve("DiscardInnerClass.mapping");
private static final Path DISCARD_INNER_CLASS_EXPECTED = EXPECTED_DIR.resolve("DiscardInnerClass.mapping");

@Test
public void testInvalidMappings() throws Exception {
Expand Down Expand Up @@ -55,4 +57,16 @@ public void testMappingSave() throws Exception {

Assertions.assertEquals(expectedLines, actualLines);
}

@Test
public void testDiscardInnerClass() throws Exception {
Path resultFile = Files.createTempFile("discardInnerClass", ".mapping");

DropInvalidMappingsCommand.run(INNER_JAR, DISCARD_INNER_CLASS_INPUT, resultFile);

String expectedLines = Files.readString(DISCARD_INNER_CLASS_EXPECTED);
String actualLines = Files.readString(resultFile);

Assertions.assertEquals(expectedLines, actualLines);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CLASS f
CLASS a
CLASS a
FIELD a q I
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
CLASS a
CLASS b
METHOD b (Ljava/lang/String;)V
ARG 2 nonEmpty
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CLASS f
CLASS a
CLASS a
FIELD a q I
CLASS a
FIELD a I
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ private boolean hasNoMappedChildren(Entry<?> entry, Dropped dropped) {
if (!children.isEmpty()) {
for (Entry<?> child : children) {
var mapping = this.mappings.get(child);
if (!dropped.getDroppedMappings().containsKey(child)
&& mapping != null && mapping.tokenType() != TokenType.OBFUSCATED
if ((!dropped.getDroppedMappings().containsKey(child)
&& mapping != null && mapping.tokenType() != TokenType.OBFUSCATED)
|| !this.hasNoMappedChildren(child, dropped)) {
return false;
}
}
}

return children.isEmpty();
return true;
}

public static class Dropped {
Expand Down

0 comments on commit 2f54346

Please sign in to comment.