diff options
Diffstat (limited to 'libtests/json.cc')
-rw-r--r-- | libtests/json.cc | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/libtests/json.cc b/libtests/json.cc index 9c5720f4..ef9188c5 100644 --- a/libtests/json.cc +++ b/libtests/json.cc @@ -162,7 +162,9 @@ test_schema() "x": "ecks" }, "s": [ - "esses" + { + "ss": "esses" + } ] } }, @@ -177,7 +179,11 @@ test_schema() "z": "ebra", "o": "ptional" } - } + }, + "four": [ + { "first": "first element" }, + { "second": "second element" } + ] } )"); @@ -225,17 +231,30 @@ test_schema() "else": { "z": "okay" } - } + }, + "four": [ + {"first": "missing second"} + ] } )"); check_schema(b, schema, 0, false, "missing items"); - check_schema(a, a, 0, false, "top-level schema array error"); - check_schema(b, b, 0, false, "lower-level schema array error"); JSON bad_schema = JSON::parse(R"({"a": true, "b": "potato?"})"); check_schema(bad_schema, bad_schema, 0, false, "bad schema field type"); + JSON c = JSON::parse(R"( +{ + "four": [ + { "first": 1 }, + { "oops": [2] } + ] +} +)"); + check_schema(c, schema, JSON::f_optional, false, "array element mismatch"); + + // "two" exercises the case of the JSON containing a single + // element where the schema has an array. JSON good = JSON::parse(R"( { "one": { @@ -245,22 +264,24 @@ test_schema() "x": [1, null] }, "s": [ - null, - "anything" + {"ss": null}, + {"ss": "anything"} ] } }, - "two": [ - { - "glarp": "enspliel", - "goose": 3.14 - } - ], + "two": { + "glarp": "enspliel", + "goose": 3.14 + }, "three": { "<objid>": { "z": "ebra" } - } + }, + "four": [ + { "first": 1 }, + { "second": [2] } + ] } )"); check_schema(good, schema, 0, false, "not optional"); |