Skip to content

Commit

Permalink
misc: Replace \t spacing in test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jan 19, 2024
1 parent a4f8b93 commit b4b268e
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.util.stream.Collectors;

public class SampleCompilerTest {
private static final String PATH_PREFIX = "src/test/resources/samples/jasm/";
private static final String PATH_ILLEGAL_PREFIX = "src/test/resources/samples/jasm-illegal/";
private static final String PATH_PREFIX = "src/test/resources/samples/jasm/";
private static final String PATH_ILLEGAL_PREFIX = "src/test/resources/samples/jasm-illegal/";

@Nested
class Variables {
Expand Down Expand Up @@ -135,34 +135,34 @@ void fieldLookup() throws Throwable {
}
}

@Nested
class Illegal {
@Test
void intAndObjectStackMerge() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-object-int-stack-merge.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processAnalysisFailJvm(source, options, result -> {
@Nested
class Illegal {
@Test
void intAndObjectStackMerge() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-object-int-stack-merge.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processAnalysisFailJvm(source, options, result -> {

});
}
}
});
}
}

@Nested
class Regresssion {
@Test
void newArrayPopsSizeOffStack() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-anewarray.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
AnalysisResults results = result.analysisLookup().allResults().values().iterator().next();
assertNull(results.getAnalysisFailure());
assertFalse(results.terminalFrames().isEmpty());
});
}
@Test
void newArrayPopsSizeOffStack() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-anewarray.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
AnalysisResults results = result.analysisLookup().allResults().values().iterator().next();
assertNull(results.getAnalysisFailure());
assertFalse(results.terminalFrames().isEmpty());
});
}

@Test
void athrowDoesNotAllowFlowThroughToNextFrameAndClearsStack() throws Throwable {
Expand All @@ -177,101 +177,101 @@ void athrowDoesNotAllowFlowThroughToNextFrameAndClearsStack() throws Throwable {
});
}

@Test
void checkcastChangesType() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-checkcast.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.inheritanceChecker(ReflectiveInheritanceChecker.INSTANCE);
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
AnalysisResults results = result.analysisLookup().allResults().values().iterator().next();
assertNull(results.getAnalysisFailure());
assertFalse(results.terminalFrames().isEmpty());
@Test
void checkcastChangesType() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-checkcast.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.inheritanceChecker(ReflectiveInheritanceChecker.INSTANCE);
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
AnalysisResults results = result.analysisLookup().allResults().values().iterator().next();
assertNull(results.getAnalysisFailure());
assertFalse(results.terminalFrames().isEmpty());

Frame endFrame = results.terminalFrames().lastEntry().getValue();
if (endFrame instanceof ValuedFrame valuedEndFrame) {
Value returnValue = valuedEndFrame.peek();
assertEquals(Types.instanceType(List.class), returnValue.type());
} else {
fail("Wrong return value");
}
});
}
Frame endFrame = results.terminalFrames().lastEntry().getValue();
if (endFrame instanceof ValuedFrame valuedEndFrame) {
Value returnValue = valuedEndFrame.peek();
assertEquals(Types.instanceType(List.class), returnValue.type());
} else {
fail("Wrong return value");
}
});
}
}

@Nested
class RoundTrip {
@ParameterizedTest
@MethodSource("getSources")
void all(TestArgument arg) throws Throwable {
String source = arg.source.get();
processJvm(source, new TestJvmCompilerOptions(), result -> {
if (source.contains("SKIP-ROUND-TRIP-EQUALITY"))
return;
@Nested
class RoundTrip {
@ParameterizedTest
@MethodSource("getSources")
void all(TestArgument arg) throws Throwable {
String source = arg.source.get();
processJvm(source, new TestJvmCompilerOptions(), result -> {
if (source.contains("SKIP-ROUND-TRIP-EQUALITY"))
return;

JvmClassPrinter newPrinter = new JvmClassPrinter(result.representation().classFile());
PrintContext<?> newCtx = new PrintContext<>(" ");
newPrinter.print(newCtx);
String newPrinted = newCtx.toString();
JvmClassPrinter newPrinter = new JvmClassPrinter(result.representation().classFile());
PrintContext<?> newCtx = new PrintContext<>(" ");
newPrinter.print(newCtx);
String newPrinted = newCtx.toString();

assertEquals(
normalize(source), normalize(newPrinted),
"There was an unexpected difference in unmodified class: " + arg.name
);
});
}
assertEquals(
normalize(source), normalize(newPrinted),
"There was an unexpected difference in unmodified class: " + arg.name
);
});
}

@Test
void supportInfinity() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-infinity.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
JvmClassPrinter newPrinter = new JvmClassPrinter(result.representation().classFile());
PrintContext<?> newCtx = new PrintContext<>(" ");
newPrinter.print(newCtx);
String newPrinted = newCtx.toString();
@Test
void supportInfinity() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-infinity.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
JvmClassPrinter newPrinter = new JvmClassPrinter(result.representation().classFile());
PrintContext<?> newCtx = new PrintContext<>(" ");
newPrinter.print(newCtx);
String newPrinted = newCtx.toString();

assertEquals(normalize(source.replace("InfinityD", "Infinity").replace("+", "")), normalize(newPrinted));
});
}
assertEquals(normalize(source.replace("InfinityD", "Infinity").replace("+", "")), normalize(newPrinted));
});
}

@Test
void supportNan() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-nan.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
JvmClassPrinter newPrinter = new JvmClassPrinter(result.representation().classFile());
PrintContext<?> newCtx = new PrintContext<>(" ");
newPrinter.print(newCtx);
String newPrinted = newCtx.toString();
@Test
void supportNan() throws Throwable {
TestArgument arg = TestArgument.fromName("Example-nan.jasm");
String source = arg.source.get();
TestJvmCompilerOptions options = new TestJvmCompilerOptions();
options.engineProvider(ValuedJvmAnalysisEngine::new);
processJvm(source, options, result -> {
JvmClassPrinter newPrinter = new JvmClassPrinter(result.representation().classFile());
PrintContext<?> newCtx = new PrintContext<>(" ");
newPrinter.print(newCtx);
String newPrinted = newCtx.toString();

assertEquals(normalize(source.replace("NaND", "NaN")), normalize(newPrinted));
});
}
assertEquals(normalize(source.replace("NaND", "NaN")), normalize(newPrinted));
});
}

public static List<TestArgument> getSources() {
try {
BiPredicate<Path, BasicFileAttributes> filter = (path, attrib) -> attrib.isRegularFile()
&& path.toString().endsWith(".jasm");
return Files.find(Paths.get(System.getProperty("user.dir")).resolve("src"), 25, filter)
.map(TestArgument::from).collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public static List<TestArgument> getSources() {
try {
BiPredicate<Path, BasicFileAttributes> filter = (path, attrib) -> attrib.isRegularFile()
&& path.toString().endsWith(".jasm");
return Files.find(Paths.get(System.getProperty("user.dir")).resolve("src"), 25, filter)
.map(TestArgument::from).collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

private record TestArgument(String name, ThrowingSupplier<String> source) {
public static TestArgument fromName(String name) {
Path path = Paths.get(System.getProperty("user.dir")).resolve(PATH_PREFIX).resolve(name);
if (!Files.exists(path))
path = Paths.get(System.getProperty("user.dir")).resolve(PATH_ILLEGAL_PREFIX).resolve(name);
return from(path);
Path path = Paths.get(System.getProperty("user.dir")).resolve(PATH_PREFIX).resolve(name);
if (!Files.exists(path))
path = Paths.get(System.getProperty("user.dir")).resolve(PATH_ILLEGAL_PREFIX).resolve(name);
return from(path);
}

public static TestArgument from(Path path) {
Expand Down
12 changes: 6 additions & 6 deletions jasm-core/src/test/java/me/darknet/assembler/EscapeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public void testStringEscape(String input) {
"0 -10 10f 10.16F 10.161616D 10L 0xDEADBEEF 0E10", ".class public java/lang/HelloWorld", """
@ParameterizedTest
@ValueSource(
strings = {
"epic\\u0020obfuscated\\u0020name",
"{ \\"Hello World\\", type: \\"java/lang/HelloWorld\\" }",
"0 -10 10f 10.16F 10.161616D 10L 0xDEADBEEF 0E10",
".class public java/lang/HelloWorld"
}
strings = {
"epic\\u0020obfuscated\\u0020name",
"{ \\"Hello World\\", type: \\"java/lang/HelloWorld\\" }",
"0 -10 10f 10.16F 10.161616D 10L 0xDEADBEEF 0E10",
".class public java/lang/HelloWorld"
}
)
""" }
)
Expand Down

0 comments on commit b4b268e

Please sign in to comment.