Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .github/workflows/toml-compliance.yml

This file was deleted.

6 changes: 6 additions & 0 deletions toml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<version>20.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>at.yawk.toml.test</groupId>
<artifactId>toml-test-for-java</artifactId>
<version>0.1.0-2.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
1 change: 1 addition & 0 deletions toml/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
requires tools.jackson.databind;

// Additional test lib/framework dependencies
requires at.yawk.toml.test;
requires org.assertj.core;
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package tools.jackson.dataformat.toml;

import java.nio.file.Path;
import java.util.stream.Stream;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import at.yawk.toml.test.TomlTestCase;

import tools.jackson.databind.ObjectMapper;

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

public class ComplianceInvalidTest extends TomlMapperTestBase
{
Expand All @@ -19,18 +16,8 @@ public class ComplianceInvalidTest extends TomlMapperTestBase
.build();

@ParameterizedTest
@MethodSource("data")
public void tomlTestInvalidCorpus(Path path) {
assumeTrue(path != null, "Set -Dtoml.corpus.dir=/path/to/toml-test to run TOML corpus tests");
assertThrows(TomlStreamReadException.class, () -> MAPPER.readTree(path.toFile()));
}

public static Stream<Arguments> data() throws Exception {
Path corpusRoot = ComplianceValidTest.corpusRoot();
if (corpusRoot == null) {
return Stream.of(Arguments.of((Path) null));
}
return ComplianceValidTest.corpusFiles(corpusRoot, "invalid/").stream()
.map(Arguments::of);
@MethodSource("at.yawk.toml.test.TomlTestSuite#invalidToml100")
public void tomlTestInvalidCorpus(TomlTestCase test) {
assertThrows(TomlStreamReadException.class, () -> MAPPER.readTree(test.tomlBytes()));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package tools.jackson.dataformat.toml;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.file.*;
import java.time.*;
import java.util.*;
import java.util.stream.Stream;
import java.util.Map;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import at.yawk.toml.test.TomlTestCase;

import tools.jackson.core.io.NumberInput;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
Expand All @@ -21,7 +19,6 @@
import tools.jackson.databind.node.ObjectNode;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class ComplianceValidTest extends TomlMapperTestBase
{
Expand All @@ -31,52 +28,17 @@ public class ComplianceValidTest extends TomlMapperTestBase
private static final ObjectMapper JSON_MAPPER = JsonMapper.shared();

@ParameterizedTest
@MethodSource("data")
public void tomlTestValidCorpus(Path toml, Path json) throws Exception {
assumeTrue(toml != null, "Set -Dtoml.corpus.dir=/path/to/toml-test to run TOML corpus tests");
@MethodSource("at.yawk.toml.test.TomlTestSuite#validToml100")
public void tomlTestValidCorpus(TomlTestCase test) throws Exception {
String expectedJson = test.expectedJson();
assertNotNull(expectedJson, "valid TOML test must have expected JSON");

JsonNode expected = mapFromComplianceNode(JSON_MAPPER.readTree(json.toFile()));
JsonNode actual = TOML_MAPPER.readTree(toml.toFile());
JsonNode expected = mapFromComplianceNode(JSON_MAPPER.readTree(expectedJson));
JsonNode actual = TOML_MAPPER.readTree(test.tomlBytes());
assertTrue(semanticallyEquals(expected, actual),
"expected=" + expected + " actual=" + actual);
}

public static Stream<Arguments> data() throws Exception {
Path corpusRoot = corpusRoot();
if (corpusRoot == null) {
return Stream.of(Arguments.of(null, null));
}
return corpusFiles(corpusRoot, "valid/").stream()
.map(toml -> Arguments.of(toml, expectedJson(toml)))
.filter(args -> Files.isRegularFile((Path) args.get()[1]));
}

static Path corpusRoot() {
String root = System.getProperty("toml.corpus.dir");
if (root == null || root.isBlank()) {
return null;
}
return Paths.get(root);
}

static List<Path> corpusFiles(Path corpusRoot, String prefix) throws IOException {
Path testsRoot = corpusRoot.resolve("tests");
Path fileList = testsRoot.resolve(System.getProperty("toml.corpus.fileList", "files-toml-1.0.0"));
List<Path> files = new ArrayList<>();
for (String line : Files.readAllLines(fileList)) {
if (line.isBlank() || line.startsWith("#") || !line.endsWith(".toml") || !line.startsWith(prefix)) {
continue;
}
files.add(testsRoot.resolve(line));
}
return files;
}

private static Path expectedJson(Path toml) {
String fileName = toml.getFileName().toString();
return toml.resolveSibling(fileName.substring(0, fileName.length() - 5) + ".json");
}

private static JsonNode mapFromComplianceNode(JsonNode expected) {
final JsonNodeCreator nodeF = JsonMapper.shared().createObjectNode();
if (expected.isObject()) {
Expand Down