Skip to content

Commit 94d9f67

Browse files
Use toml-test-for-java for compliance tests (#684)
Co-authored-by: multicode <multicode@yawk.at>
1 parent be5d105 commit 94d9f67

5 files changed

Lines changed: 21 additions & 108 deletions

File tree

.github/workflows/toml-compliance.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

toml/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<version>20.1.0</version>
4444
<scope>test</scope>
4545
</dependency>
46+
<dependency>
47+
<groupId>at.yawk.toml.test</groupId>
48+
<artifactId>toml-test-for-java</artifactId>
49+
<version>0.1.0-2.2.0</version>
50+
<scope>test</scope>
51+
</dependency>
4652
</dependencies>
4753

4854
<build>

toml/src/test/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
requires tools.jackson.databind;
99

1010
// Additional test lib/framework dependencies
11+
requires at.yawk.toml.test;
1112
requires org.assertj.core;
1213
requires org.junit.jupiter.api;
1314
requires org.junit.jupiter.params;
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package tools.jackson.dataformat.toml;
22

3-
import java.nio.file.Path;
4-
import java.util.stream.Stream;
5-
63
import org.junit.jupiter.params.ParameterizedTest;
7-
import org.junit.jupiter.params.provider.Arguments;
84
import org.junit.jupiter.params.provider.MethodSource;
95

6+
import at.yawk.toml.test.TomlTestCase;
7+
108
import tools.jackson.databind.ObjectMapper;
119

1210
import static org.junit.jupiter.api.Assertions.assertThrows;
13-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1411

1512
public class ComplianceInvalidTest extends TomlMapperTestBase
1613
{
@@ -19,18 +16,8 @@ public class ComplianceInvalidTest extends TomlMapperTestBase
1916
.build();
2017

2118
@ParameterizedTest
22-
@MethodSource("data")
23-
public void tomlTestInvalidCorpus(Path path) {
24-
assumeTrue(path != null, "Set -Dtoml.corpus.dir=/path/to/toml-test to run TOML corpus tests");
25-
assertThrows(TomlStreamReadException.class, () -> MAPPER.readTree(path.toFile()));
26-
}
27-
28-
public static Stream<Arguments> data() throws Exception {
29-
Path corpusRoot = ComplianceValidTest.corpusRoot();
30-
if (corpusRoot == null) {
31-
return Stream.of(Arguments.of((Path) null));
32-
}
33-
return ComplianceValidTest.corpusFiles(corpusRoot, "invalid/").stream()
34-
.map(Arguments::of);
19+
@MethodSource("at.yawk.toml.test.TomlTestSuite#invalidToml100")
20+
public void tomlTestInvalidCorpus(TomlTestCase test) {
21+
assertThrows(TomlStreamReadException.class, () -> MAPPER.readTree(test.tomlBytes()));
3522
}
3623
}

toml/src/test/java/tools/jackson/dataformat/toml/ComplianceValidTest.java

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package tools.jackson.dataformat.toml;
22

3-
import java.io.IOException;
43
import java.math.BigDecimal;
54
import java.math.BigInteger;
6-
import java.nio.file.*;
75
import java.time.*;
8-
import java.util.*;
9-
import java.util.stream.Stream;
6+
import java.util.Map;
107

118
import org.junit.jupiter.params.ParameterizedTest;
12-
import org.junit.jupiter.params.provider.Arguments;
139
import org.junit.jupiter.params.provider.MethodSource;
1410

11+
import at.yawk.toml.test.TomlTestCase;
12+
1513
import tools.jackson.core.io.NumberInput;
1614
import tools.jackson.databind.JsonNode;
1715
import tools.jackson.databind.ObjectMapper;
@@ -21,7 +19,6 @@
2119
import tools.jackson.databind.node.ObjectNode;
2220

2321
import static org.junit.jupiter.api.Assertions.*;
24-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2522

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

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

38-
JsonNode expected = mapFromComplianceNode(JSON_MAPPER.readTree(json.toFile()));
39-
JsonNode actual = TOML_MAPPER.readTree(toml.toFile());
36+
JsonNode expected = mapFromComplianceNode(JSON_MAPPER.readTree(expectedJson));
37+
JsonNode actual = TOML_MAPPER.readTree(test.tomlBytes());
4038
assertTrue(semanticallyEquals(expected, actual),
4139
"expected=" + expected + " actual=" + actual);
4240
}
4341

44-
public static Stream<Arguments> data() throws Exception {
45-
Path corpusRoot = corpusRoot();
46-
if (corpusRoot == null) {
47-
return Stream.of(Arguments.of(null, null));
48-
}
49-
return corpusFiles(corpusRoot, "valid/").stream()
50-
.map(toml -> Arguments.of(toml, expectedJson(toml)))
51-
.filter(args -> Files.isRegularFile((Path) args.get()[1]));
52-
}
53-
54-
static Path corpusRoot() {
55-
String root = System.getProperty("toml.corpus.dir");
56-
if (root == null || root.isBlank()) {
57-
return null;
58-
}
59-
return Paths.get(root);
60-
}
61-
62-
static List<Path> corpusFiles(Path corpusRoot, String prefix) throws IOException {
63-
Path testsRoot = corpusRoot.resolve("tests");
64-
Path fileList = testsRoot.resolve(System.getProperty("toml.corpus.fileList", "files-toml-1.0.0"));
65-
List<Path> files = new ArrayList<>();
66-
for (String line : Files.readAllLines(fileList)) {
67-
if (line.isBlank() || line.startsWith("#") || !line.endsWith(".toml") || !line.startsWith(prefix)) {
68-
continue;
69-
}
70-
files.add(testsRoot.resolve(line));
71-
}
72-
return files;
73-
}
74-
75-
private static Path expectedJson(Path toml) {
76-
String fileName = toml.getFileName().toString();
77-
return toml.resolveSibling(fileName.substring(0, fileName.length() - 5) + ".json");
78-
}
79-
8042
private static JsonNode mapFromComplianceNode(JsonNode expected) {
8143
final JsonNodeCreator nodeF = JsonMapper.shared().createObjectNode();
8244
if (expected.isObject()) {

0 commit comments

Comments
 (0)