Skip to content

Commit

Permalink
add a goofy test for the DDCM parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Nov 3, 2024
1 parent feb521f commit 06ca607
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package daomephsta.unpick.tests;

import daomephsta.unpick.api.IClassResolver;
import daomephsta.unpick.api.constantmappers.ConstantMappers;
import daomephsta.unpick.api.constantresolvers.ConstantResolvers;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class TestDataDrivenConstantMapperParsing {
private final Path validSyntax;

public TestDataDrivenConstantMapperParsing() throws URISyntaxException {
Path dir = getResource("/v2_test_definitions");
validSyntax = dir.resolve("valid_syntax.unpick");
}

private static Path getResource(String name) throws URISyntaxException {
return Paths.get(TestDataDrivenConstantMapperParsing.class.getResource(name).toURI());
}

@Test
void testDDCMParseV2() throws IOException {
File file = validSyntax.toFile();

try (InputStream stream = Files.newInputStream(file.toPath())) {
// once classes begin being resolved, we know we have successfully parsed the definitions
assertThrows(IClassResolver.ClassResolutionException.class, () -> ConstantMappers.dataDriven(new IClassResolver() {
@Override
public ClassReader resolveClassReader(String binaryName) throws ClassResolutionException {
throw new ClassResolutionException(binaryName);
}

@Override
public ClassNode resolveClassNode(String binaryName) throws ClassResolutionException {
throw new ClassResolutionException(binaryName);
}
}, ConstantResolvers.bytecodeAnalysis(new MethodMockingClassResolver()), stream));
}
}
}
7 changes: 7 additions & 0 deletions src/test/resources/v2_test_definitions/valid_syntax.unpick
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
v2

constant flag org/quiltmc/Gaming GAMING
constant flag org/quiltmc/Gaming NOT_GAMING

target_method org/quiltmc/Gaming getFlag (I)Z
param 0 flag
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void validateVersion(InputStreamReader definitionStream) throws IOExcept
}
}
else
throw new UnpickSyntaxException(1, "Missing or invalid version (version chars: '" + Arrays.toString(versionChars) + "')");
throw new UnpickSyntaxException(1, "Missing or invalid version (version chars: " + Arrays.toString(versionChars) + ")");
}

private void visitParameterConstantGroupDefinition(Visitor visitor, String[] tokens, int lineNumber)
Expand Down

0 comments on commit 06ca607

Please sign in to comment.