aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/json.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-07-24 22:44:51 +0200
committerJay Berkenbilt <ejb@ql.org>2022-07-24 22:44:51 +0200
commit4674c04cb80e0a50cde1b97464642e2778f9522f (patch)
tree9a79072f17c0053e576d754fb7d22ac046b4f4b4 /libtests/json.cc
parentf8d1ab946205440ed3c44511ef42e5ad13fb9e5e (diff)
downloadqpdf-4674c04cb80e0a50cde1b97464642e2778f9522f.tar.zst
JSON schema: support multi-element array validation
Diffstat (limited to 'libtests/json.cc')
-rw-r--r--libtests/json.cc29
1 files changed, 24 insertions, 5 deletions
diff --git a/libtests/json.cc b/libtests/json.cc
index a509c2be..ef9188c5 100644
--- a/libtests/json.cc
+++ b/libtests/json.cc
@@ -179,7 +179,11 @@ test_schema()
"z": "ebra",
"o": "ptional"
}
- }
+ },
+ "four": [
+ { "first": "first element" },
+ { "second": "second element" }
+ ]
}
)");
@@ -227,17 +231,28 @@ 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"(
@@ -262,7 +277,11 @@ test_schema()
"<objid>": {
"z": "ebra"
}
- }
+ },
+ "four": [
+ { "first": 1 },
+ { "second": [2] }
+ ]
}
)");
check_schema(good, schema, 0, false, "not optional");