@@ -90,7 +90,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
9090
9191 test ({
9292 FAILURE,
93- " invalid type type " ,
93+ " invalid type" ,
9494 R"""( {
9595 "type": 123
9696 })""" ,
@@ -193,21 +193,27 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
193193 });
194194
195195 test ({
196- FAILURE ,
196+ SUCCESS ,
197197 " non-string const" ,
198198 R"""( {
199199 "const": 123
200200 })""" ,
201- " "
201+ R"""(
202+ root ::= "123"
203+ space ::= " "?
204+ )"""
202205 });
203206
204207 test ({
205- FAILURE ,
208+ SUCCESS ,
206209 " non-string enum" ,
207210 R"""( {
208- "enum": [123 ]
211+ "enum": ["red", "amber", "green", null, 42, ["foo"] ]
209212 })""" ,
210- " "
213+ R"""(
214+ root ::= "\"red\"" | "\"amber\"" | "\"green\"" | "null" | "42" | "[\"foo\"]"
215+ space ::= " "?
216+ )"""
211217 });
212218
213219 test ({
@@ -378,28 +384,27 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
378384
379385 test ({
380386 SUCCESS,
381- " required props" ,
387+ " required props in original order " ,
382388 R"""( {
383389 "type": "object",
384390 "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"}
391394 },
392395 "required": [
393396 "a",
394- "b"
397+ "b",
398+ "c"
395399 ],
396400 "additionalProperties": false,
397401 "definitions": {}
398402 })""" ,
399403 R"""(
400404 a-kv ::= "\"a\"" space ":" space string
401405 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
403408 space ::= " "?
404409 string ::= "\"" (
405410 [^"\\] |
@@ -458,13 +463,13 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
458463
459464 test ({
460465 SUCCESS,
461- " required + optional props" ,
466+ " required + optional props each in original order " ,
462467 R"""( {
463468 "properties": {
464- "a": {"type": "string"},
465469 "b": {"type": "string"},
466- "c": {"type": "string"},
467- "d": {"type": "string"}
470+ "a": {"type": "string"},
471+ "d": {"type": "string"},
472+ "c": {"type": "string"}
468473 },
469474 "required": ["a", "b"],
470475 "additionalProperties": false
@@ -473,14 +478,14 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
473478 a-kv ::= "\"a\"" space ":" space string
474479 b-kv ::= "\"b\"" space ":" space string
475480 c-kv ::= "\"c\"" space ":" space string
476- c-rest ::= ( "," space d-kv )?
477481 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
479484 space ::= " "?
480485 string ::= "\"" (
481486 [^"\\] |
482487 "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
483- )* "\"" space
488+ )* "\"" space
484489 )"""
485490 });
486491
@@ -648,16 +653,16 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
648653 "$ref": "#/definitions/MyType",
649654 "definitions": {
650655 "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
661666 }
662667 }
663668 })""" ,
@@ -683,10 +688,10 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
683688 ],
684689 "definitions": {
685690 "foo": {
686- "properties": {"a": {"type": "number"}}
691+ "properties": {"a": {"type": "number"}}
687692 },
688693 "bar": {
689- "properties": {"b": {"type": "number"}}
694+ "properties": {"b": {"type": "number"}}
690695 }
691696 },
692697 "type": "object"
@@ -720,16 +725,16 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
720725 ],
721726 "definitions": {
722727 "foo": {
723- "properties": {"a": {"type": "number"}}
728+ "properties": {"a": {"type": "number"}}
724729 },
725730 "bar": {
726- "properties": {"b": {"type": "number"}}
731+ "properties": {"b": {"type": "number"}}
727732 },
728733 "bam": {
729- "properties": {"c": {"type": "number"}}
734+ "properties": {"c": {"type": "number"}}
730735 },
731736 "baz": {
732- "properties": {"d": {"type": "number"}}
737+ "properties": {"d": {"type": "number"}}
733738 }
734739 },
735740 "type": "object"
@@ -757,15 +762,15 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
757762 "properties": {
758763 "number": {
759764 "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
769774 }
770775 },
771776 "required": [
@@ -796,7 +801,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
796801int main () {
797802 test_all (" C++" , [](const TestCase & tc) {
798803 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 )));
800805 tc.verify_status (SUCCESS);
801806 } catch (const std::runtime_error & ex) {
802807 fprintf (stderr, " Error: %s\n " , ex.what ());
0 commit comments