aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
Diffstat (limited to 'libtests')
-rw-r--r--libtests/json.cc49
-rw-r--r--libtests/libtests.testcov4
-rw-r--r--libtests/qtest/json/json.out14
3 files changed, 43 insertions, 24 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");
diff --git a/libtests/libtests.testcov b/libtests/libtests.testcov
index 21def9f3..2ceef541 100644
--- a/libtests/libtests.testcov
+++ b/libtests/libtests.testcov
@@ -36,8 +36,6 @@ Pl_PNGFilter decodePaeth 0
Pl_TIFFPredictor processRow 1
JSON wanted dictionary 0
JSON key missing in object 0
-JSON wanted array 0
-JSON schema array error 0
JSON key extra in object 0
QPDFArgParser read args from stdin 0
QPDFArgParser read args from file 0
@@ -93,3 +91,5 @@ JSON 16 high high 0
JSON 16 low not after high 0
JSON 16 dangling high 0
JSON parse duplicate key 0
+JSON schema array for single item 0
+JSON schema array length mismatch 0
diff --git a/libtests/qtest/json/json.out b/libtests/qtest/json/json.out
index c7cb85a7..f346daa6 100644
--- a/libtests/qtest/json/json.out
+++ b/libtests/qtest/json/json.out
@@ -2,9 +2,11 @@
top-level object is supposed to be a dictionary
---
--- missing items
+json key ".four" is supposed to be an array of length 2
json key ".one.a": key "q" is present in schema but missing in object
json key ".one.a.r" is supposed to be a dictionary
-json key ".one.a.s" is supposed to be an array
+json key ".one.a.s": key "ss" is present in schema but missing in object
+json key ".one.a.s": key "z" is not present in schema but appears in object
json key ".one.a": key "t" is not present in schema but appears in object
json key ".three.anything": key "z" is present in schema but missing in object
json key ".three.anything": key "x" is not present in schema but appears in object
@@ -14,16 +16,12 @@ json key ".two.1": key "flarp" is not present in schema but appears in object
json key ".two.2" is supposed to be a dictionary
json key ".two.3" is supposed to be a dictionary
---
---- top-level schema array error
-top-level object schema array contains other than one item
----
---- lower-level schema array error
-json key ".one.a.r" schema array contains other than one item
-json key ".two" schema array contains other than one item
----
--- bad schema field type
json key ".a" schema value is not dictionary, array, or string
---
+--- array element mismatch
+json key ".four.1": key "oops" is not present in schema but appears in object
+---
--- not optional
json key ".three.<objid>": key "o" is present in schema but missing in object
---