11package tools .jackson .dataformat .toml ;
22
3- import java .io .IOException ;
43import java .math .BigDecimal ;
54import java .math .BigInteger ;
6- import java .nio .file .*;
75import java .time .*;
8- import java .util .*;
9- import java .util .stream .Stream ;
6+ import java .util .Map ;
107
118import org .junit .jupiter .params .ParameterizedTest ;
12- import org .junit .jupiter .params .provider .Arguments ;
139import org .junit .jupiter .params .provider .MethodSource ;
1410
11+ import at .yawk .toml .test .TomlTestCase ;
12+
1513import tools .jackson .core .io .NumberInput ;
1614import tools .jackson .databind .JsonNode ;
1715import tools .jackson .databind .ObjectMapper ;
2119import tools .jackson .databind .node .ObjectNode ;
2220
2321import static org .junit .jupiter .api .Assertions .*;
24- import static org .junit .jupiter .api .Assumptions .assumeTrue ;
2522
2623public 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