diff --git a/json-compatibility-suite/pom.xml b/json-compatibility-suite/pom.xml new file mode 100644 index 0000000..f1fb066 --- /dev/null +++ b/json-compatibility-suite/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + + io.github.simbo1905.json + json-java21-parent + 0.1-SNAPSHOT + + + json-compatibility-suite + jar + + JSON Compatibility Suite + + + + io.github.simbo1905.json + json-java21 + ${project.version} + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core + test + + + + + + + com.googlecode.maven-download-plugin + download-maven-plugin + + + download-json-test-suite + generate-test-resources + + wget + + + https://github.com/nst/JSONTestSuite/archive/refs/heads/master.zip + ${project.build.directory}/test-resources + json-test-suite.zip + true + + + + + + + diff --git a/json-compatibility-suite/src/test/java/jdk/sandbox/compatibility/DownloadVerificationTest.java b/json-compatibility-suite/src/test/java/jdk/sandbox/compatibility/DownloadVerificationTest.java new file mode 100644 index 0000000..2a9a176 --- /dev/null +++ b/json-compatibility-suite/src/test/java/jdk/sandbox/compatibility/DownloadVerificationTest.java @@ -0,0 +1,23 @@ +package jdk.sandbox.compatibility; + +import org.junit.jupiter.api.Test; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import static org.assertj.core.api.Assertions.assertThat; + +public class DownloadVerificationTest { + @Test + void testSuiteDownloaded() { + Path testDir = Paths.get("target/test-resources/JSONTestSuite-master/test_parsing"); + assertThat(testDir) + .as("JSON Test Suite should be downloaded and extracted") + .exists() + .isDirectory(); + + // Verify some test files exist + assertThat(testDir.resolve("y_structure_whitespace_array.json")) + .as("Should contain valid test files") + .exists(); + } +} diff --git a/json-compatibility-suite/src/test/java/jdk/sandbox/compatibility/JsonTestSuiteTest.java b/json-compatibility-suite/src/test/java/jdk/sandbox/compatibility/JsonTestSuiteTest.java new file mode 100644 index 0000000..c4878f1 --- /dev/null +++ b/json-compatibility-suite/src/test/java/jdk/sandbox/compatibility/JsonTestSuiteTest.java @@ -0,0 +1,71 @@ +package jdk.sandbox.compatibility; + +import jdk.sandbox.java.util.json.Json; +import jdk.sandbox.java.util.json.JsonParseException; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.*; + +/** + * Runs the JSON Test Suite against our implementation. + * Files are categorized: + * - y_*.json: Valid JSON that MUST parse successfully + * - n_*.json: Invalid JSON that MUST fail to parse + * - i_*.json: Implementation-defined (may accept or reject) + */ +public class JsonTestSuiteTest { + + private static final Path TEST_DIR = Paths.get("target/test-resources/JSONTestSuite-master/test_parsing"); + + @TestFactory + Stream runJsonTestSuite() throws Exception { + if (!Files.exists(TEST_DIR)) { + System.err.println("Test suite not found. Run: mvn test-compile"); + return Stream.empty(); + } + + return Files.walk(TEST_DIR) + .filter(p -> p.toString().endsWith(".json")) + .sorted() + .map(this::createTest); + } + + private DynamicTest createTest(Path file) { + String filename = file.getFileName().toString(); + + return DynamicTest.dynamicTest(filename, () -> { + String content = Files.readString(file); + + if (filename.startsWith("y_")) { + // Valid JSON - must parse successfully + assertThatCode(() -> Json.parse(content)) + .as("File %s should parse successfully", filename) + .doesNotThrowAnyException(); + + } else if (filename.startsWith("n_")) { + // Invalid JSON - must fail to parse + assertThatThrownBy(() -> Json.parse(content)) + .as("File %s should fail to parse", filename) + .isInstanceOf(JsonParseException.class); + + } else if (filename.startsWith("i_")) { + // Implementation defined - just verify no crash + try { + Json.parse(content); + // OK - we accepted it + } catch (JsonParseException e) { + // OK - we rejected it + } catch (Exception e) { + // NOT OK - unexpected exception type + fail("Unexpected exception for %s: %s", filename, e); + } + } + }); + } +} diff --git a/pom.xml b/pom.xml index 4909985..81afde2 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ json-java21 json-java21-api-tracker + json-compatibility-suite @@ -53,6 +54,7 @@ 3.2.5 3.4.2 3.1.2 + 1.7.1 @@ -113,7 +115,12 @@ maven-install-plugin ${maven-install-plugin.version} + + com.googlecode.maven-download-plugin + download-maven-plugin + ${download-maven-plugin.version} + - \ No newline at end of file +