Skip to content

Commit

Permalink
basic testing for V2 reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Oct 26, 2024
1 parent 31d7558 commit bbe7cd9
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
asm = "9.7"
log4j = "2.19.0"
junit = "5.9.3"

[libraries]
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
Expand All @@ -10,3 +11,5 @@ asm_util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }

log4j_api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
log4j_core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }

junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
3 changes: 3 additions & 0 deletions unpick-format-utils/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
testImplementation(libs.junit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package daomephsta.unpick.tests;

import daomephsta.unpick.constantmappers.datadriven.parser.UnpickSyntaxException;
import daomephsta.unpick.constantmappers.datadriven.parser.v2.UnpickV2Reader;
import daomephsta.unpick.constantmappers.datadriven.parser.v2.UnpickV2Writer;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
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 TestV2Reader {
private final Path missingHeader;
private final Path validSyntax;
private final Path invalidKeyword;

public TestV2Reader() throws URISyntaxException {
Path dir = getResource("/v2_test_files");
missingHeader = dir.resolve("missing_header.unpick");
validSyntax = dir.resolve("valid_syntax.unpick");
invalidKeyword = dir.resolve("invalid_keyword.unpick");
}

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

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

try (UnpickV2Reader reader = new UnpickV2Reader(Files.newInputStream(file.toPath()))) {
reader.accept(new UnpickV2Writer());
}
}

@Test
void testMissingHeader() throws IOException {
File file = missingHeader.toFile();

try (UnpickV2Reader reader = new UnpickV2Reader(Files.newInputStream(file.toPath()))) {
assertThrows(UnpickSyntaxException.class, () -> reader.accept(new UnpickV2Writer()));
}
}

@Test
void testInvalidKeyword() throws IOException {
File file = invalidKeyword.toFile();

try (UnpickV2Reader reader = new UnpickV2Reader(Files.newInputStream(file.toPath()))) {
assertThrows(UnpickSyntaxException.class, () -> reader.accept(new UnpickV2Writer()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
v2

gaming flag org/quiltmc/Gaming GAMING
gaming 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
@@ -0,0 +1,5 @@
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
@@ -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

0 comments on commit bbe7cd9

Please sign in to comment.