Skip to content

Commit

Permalink
New tests from @Col-E
Browse files Browse the repository at this point in the history
  • Loading branch information
Janmm14 committed Jan 8, 2025
1 parent d5db816 commit 029abfc
Showing 1 changed file with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,51 @@ void testProguard() {
@Test
void testEnigma() {
String mappingsText = """
COMMENT foo
CLASS test/Greetings rename/Hello
\tFIELD oldField newField Ljava/lang/String;
\tMETHOD say speak ()V""";
\tMETHOD say speak ()V
\tCLASS Inner RenamedInner""";
String mappingsTextWithTrailingNewline = mappingsText + "\n";

// The format spec says there should be a trailing newline, but we'll support both cases
MappingFileFormat format = new EnigmaMappings();
IntermediateMappings mappings = assertDoesNotThrow(() -> format.parse(mappingsText));
assertInheritMap(mappings);
mappings = assertDoesNotThrow(() -> format.parse(mappingsTextWithTrailingNewline));
assertInheritMap(mappings);

// The mapped names are optional, so we should be able to parse a sample with no
// actual target names, and get an empty result.
String mappingsTextWithNoDestinationNames = """
CLASS test/Greetings
\tFIELD oldField Ljava/lang/String;
\tMETHOD say ()V""";
mappings = assertDoesNotThrow(() -> format.parse(mappingsTextWithNoDestinationNames));
MappingFileFormat format = new EnigmaMappings();
IntermediateMappings mappings = assertDoesNotThrow(() -> format.parse(mappingsTextWithNoDestinationNames));
assertTrue(mappings.getClasses().isEmpty());
assertTrue(mappings.getFields().isEmpty());
assertTrue(mappings.getMethods().isEmpty());

// The format spec says there should be a trailing newline, but we'll support both cases
mappings = assertDoesNotThrow(() -> format.parse(mappingsText));
assertInheritMap(mappings);
mappings = assertDoesNotThrow(() -> format.parse(mappingsTextWithTrailingNewline));
assertInheritMap(mappings);
assertEquals("rename/Hello$RenamedInner", mappings.getMappedClassName("test/Greetings$Inner"));

// This is an extreme edge case of comments and newlines spread out randomly
String sampleWithCommentsAndNewlines = """
COMMENT class comment # ignored
# also ignored
\t
CLASS test/Greetings rename/Hello
\t# field comment up next
\t
# not indented but still ignored
\tCOMMENT This is a comment on the field
\t
\tFIELD oldField newField Ljava/lang/String;
\t
\tMETHOD say speak ()V
\t
\t\t# There are no args
\t\tARG noArgsHere""";
mappings = assertDoesNotThrow(() -> format.parse(sampleWithCommentsAndNewlines));
assertInheritMap(mappings);
}

@Test
Expand Down

0 comments on commit 029abfc

Please sign in to comment.