From 2f543468cabf67b9edd54ef0e1745ffa62df8470 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Wed, 4 Dec 2024 20:18:18 -0600 Subject: [PATCH] another test for good measure --- .../enigma/command/DropInvalidMappingsTest.java | 14 ++++++++++++++ .../expected/DiscardInnerClass.mapping | 4 ++++ .../expected/EmptyMappings.mapping | 4 ---- .../input/DiscardInnerClass.mapping | 6 ++++++ .../impl/translation/mapping/MappingsChecker.java | 6 +++--- 5 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping create mode 100644 enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping diff --git a/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java b/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java index 7d1a492e4..0ad911a7d 100644 --- a/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java +++ b/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java @@ -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 { @@ -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); + } } diff --git a/enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping new file mode 100644 index 000000000..f7672f72e --- /dev/null +++ b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping @@ -0,0 +1,4 @@ +CLASS f + CLASS a + CLASS a + FIELD a q I diff --git a/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping index 7b003e3fe..e69de29bb 100644 --- a/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping +++ b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping @@ -1,4 +0,0 @@ -CLASS a - CLASS b - METHOD b (Ljava/lang/String;)V - ARG 2 nonEmpty diff --git a/enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping b/enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping new file mode 100644 index 000000000..a5d770a26 --- /dev/null +++ b/enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping @@ -0,0 +1,6 @@ +CLASS f + CLASS a + CLASS a + FIELD a q I + CLASS a + FIELD a I diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java b/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java index 71fe89bfb..6660261ef 100644 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java +++ b/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java @@ -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 {