@@ -90,7 +90,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
90
90
91
91
test ({
92
92
FAILURE,
93
- " invalid type type " ,
93
+ " invalid type" ,
94
94
R"""( {
95
95
"type": 123
96
96
})""" ,
@@ -193,21 +193,27 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
193
193
});
194
194
195
195
test ({
196
- FAILURE ,
196
+ SUCCESS ,
197
197
" non-string const" ,
198
198
R"""( {
199
199
"const": 123
200
200
})""" ,
201
- " "
201
+ R"""(
202
+ root ::= "123"
203
+ space ::= " "?
204
+ )"""
202
205
});
203
206
204
207
test ({
205
- FAILURE ,
208
+ SUCCESS ,
206
209
" non-string enum" ,
207
210
R"""( {
208
- "enum": [123 ]
211
+ "enum": ["red", "amber", "green", null, 42, ["foo"] ]
209
212
})""" ,
210
- " "
213
+ R"""(
214
+ root ::= "\"red\"" | "\"amber\"" | "\"green\"" | "null" | "42" | "[\"foo\"]"
215
+ space ::= " "?
216
+ )"""
211
217
});
212
218
213
219
test ({
@@ -378,28 +384,27 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
378
384
379
385
test ({
380
386
SUCCESS,
381
- " required props" ,
387
+ " required props in original order " ,
382
388
R"""( {
383
389
"type": "object",
384
390
"properties": {
385
- "a": {
386
- "type": "string"
387
- },
388
- "b": {
389
- "type": "string"
390
- }
391
+ "b": {"type": "string"},
392
+ "c": {"type": "string"},
393
+ "a": {"type": "string"}
391
394
},
392
395
"required": [
393
396
"a",
394
- "b"
397
+ "b",
398
+ "c"
395
399
],
396
400
"additionalProperties": false,
397
401
"definitions": {}
398
402
})""" ,
399
403
R"""(
400
404
a-kv ::= "\"a\"" space ":" space string
401
405
b-kv ::= "\"b\"" space ":" space string
402
- root ::= "{" space a-kv "," space b-kv "}" space
406
+ c-kv ::= "\"c\"" space ":" space string
407
+ root ::= "{" space b-kv "," space c-kv "," space a-kv "}" space
403
408
space ::= " "?
404
409
string ::= "\"" (
405
410
[^"\\] |
@@ -458,13 +463,13 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
458
463
459
464
test ({
460
465
SUCCESS,
461
- " required + optional props" ,
466
+ " required + optional props each in original order " ,
462
467
R"""( {
463
468
"properties": {
464
- "a": {"type": "string"},
465
469
"b": {"type": "string"},
466
- "c": {"type": "string"},
467
- "d": {"type": "string"}
470
+ "a": {"type": "string"},
471
+ "d": {"type": "string"},
472
+ "c": {"type": "string"}
468
473
},
469
474
"required": ["a", "b"],
470
475
"additionalProperties": false
@@ -473,14 +478,14 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
473
478
a-kv ::= "\"a\"" space ":" space string
474
479
b-kv ::= "\"b\"" space ":" space string
475
480
c-kv ::= "\"c\"" space ":" space string
476
- c-rest ::= ( "," space d-kv )?
477
481
d-kv ::= "\"d\"" space ":" space string
478
- root ::= "{" space a-kv "," space b-kv ( "," space ( c-kv c-rest | d-kv ) )? "}" space
482
+ d-rest ::= ( "," space c-kv )?
483
+ root ::= "{" space b-kv "," space a-kv ( "," space ( d-kv d-rest | c-kv ) )? "}" space
479
484
space ::= " "?
480
485
string ::= "\"" (
481
486
[^"\\] |
482
487
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
483
- )* "\"" space
488
+ )* "\"" space
484
489
)"""
485
490
});
486
491
@@ -648,16 +653,16 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
648
653
"$ref": "#/definitions/MyType",
649
654
"definitions": {
650
655
"MyType": {
651
- "type": "object",
652
- "properties": {
653
- "a": {
654
- "type": "string"
655
- }
656
- },
657
- "required": [
658
- "a"
659
- ],
660
- "additionalProperties": false
656
+ "type": "object",
657
+ "properties": {
658
+ "a": {
659
+ "type": "string"
660
+ }
661
+ },
662
+ "required": [
663
+ "a"
664
+ ],
665
+ "additionalProperties": false
661
666
}
662
667
}
663
668
})""" ,
@@ -683,10 +688,10 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
683
688
],
684
689
"definitions": {
685
690
"foo": {
686
- "properties": {"a": {"type": "number"}}
691
+ "properties": {"a": {"type": "number"}}
687
692
},
688
693
"bar": {
689
- "properties": {"b": {"type": "number"}}
694
+ "properties": {"b": {"type": "number"}}
690
695
}
691
696
},
692
697
"type": "object"
@@ -720,16 +725,16 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
720
725
],
721
726
"definitions": {
722
727
"foo": {
723
- "properties": {"a": {"type": "number"}}
728
+ "properties": {"a": {"type": "number"}}
724
729
},
725
730
"bar": {
726
- "properties": {"b": {"type": "number"}}
731
+ "properties": {"b": {"type": "number"}}
727
732
},
728
733
"bam": {
729
- "properties": {"c": {"type": "number"}}
734
+ "properties": {"c": {"type": "number"}}
730
735
},
731
736
"baz": {
732
- "properties": {"d": {"type": "number"}}
737
+ "properties": {"d": {"type": "number"}}
733
738
}
734
739
},
735
740
"type": "object"
@@ -757,15 +762,15 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
757
762
"properties": {
758
763
"number": {
759
764
"type": "object",
760
- "properties": {
761
- "root": {
762
- "type": "number"
763
- }
764
- },
765
- "required": [
766
- "root"
767
- ],
768
- "additionalProperties": false
765
+ "properties": {
766
+ "root": {
767
+ "type": "number"
768
+ }
769
+ },
770
+ "required": [
771
+ "root"
772
+ ],
773
+ "additionalProperties": false
769
774
}
770
775
},
771
776
"required": [
@@ -796,7 +801,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
796
801
int main () {
797
802
test_all (" C++" , [](const TestCase & tc) {
798
803
try {
799
- tc.verify (json_schema_to_grammar (nlohmann::json ::parse (tc.schema )));
804
+ tc.verify (json_schema_to_grammar (nlohmann::ordered_json ::parse (tc.schema )));
800
805
tc.verify_status (SUCCESS);
801
806
} catch (const std::runtime_error & ex) {
802
807
fprintf (stderr, " Error: %s\n " , ex.what ());
0 commit comments