Skip to content

Commit 45bda8b

Browse files
some tests for keywords added in later drafts
these are mostly the same as tests from draft2019-09, with the results adjusted to accomodate for the keywords not being recognized. In most cases this results in validation always being true, but in some cases (such as contains + minContains) the results from existing keywords change their outcomes as well.
1 parent c3f4319 commit 45bda8b

File tree

3 files changed

+933
-0
lines changed

3 files changed

+933
-0
lines changed
+346
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
[
2+
{
3+
"description": "$anchor: location-independent identifier",
4+
"schema": {
5+
"allOf": [{
6+
"$ref": "#foo"
7+
}],
8+
"$defs": {
9+
"A": {
10+
"$anchor": "foo",
11+
"type": "integer"
12+
}
13+
}
14+
},
15+
"tests": [
16+
{
17+
"data": 1,
18+
"description": "cannot match: $ref is not found",
19+
"valid": false
20+
},
21+
{
22+
"data": "a",
23+
"description": "mismatch",
24+
"valid": false
25+
}
26+
]
27+
},
28+
{
29+
"description": "$id: Location-independent identifier",
30+
"schema": {
31+
"allOf": [{
32+
"$ref": "#foo"
33+
}],
34+
"$defs": {
35+
"A": {
36+
"$id": "#foo",
37+
"type": "integer"
38+
}
39+
}
40+
},
41+
"tests": [
42+
{
43+
"data": 1,
44+
"description": "match",
45+
"valid": true
46+
},
47+
{
48+
"data": "a",
49+
"description": "mismatch",
50+
"valid": false
51+
}
52+
]
53+
},
54+
{
55+
"description": "dependentSchemas: single dependency",
56+
"schema": {
57+
"dependentSchemas": {
58+
"bar": {
59+
"properties": {
60+
"foo": {"type": "integer"},
61+
"bar": {"type": "integer"}
62+
}
63+
}
64+
}
65+
},
66+
"tests": [
67+
{
68+
"description": "valid",
69+
"data": {"foo": 1, "bar": 2},
70+
"valid": true
71+
},
72+
{
73+
"description": "no dependency",
74+
"data": {"foo": "quux"},
75+
"valid": true
76+
},
77+
{
78+
"description": "wrong type",
79+
"data": {"foo": "quux", "bar": 2},
80+
"valid": true
81+
},
82+
{
83+
"description": "wrong type other",
84+
"data": {"foo": 2, "bar": "quux"},
85+
"valid": true
86+
},
87+
{
88+
"description": "wrong type both",
89+
"data": {"foo": "quux", "bar": "quux"},
90+
"valid": true
91+
}
92+
]
93+
},
94+
{
95+
"description": "dependentRequired: single dependency",
96+
"schema": {"dependentRequired": {"bar": ["foo"]}},
97+
"tests": [
98+
{
99+
"description": "neither",
100+
"data": {},
101+
"valid": true
102+
},
103+
{
104+
"description": "nondependant",
105+
"data": {"foo": 1},
106+
"valid": true
107+
},
108+
{
109+
"description": "with dependency",
110+
"data": {"foo": 1, "bar": 2},
111+
"valid": true
112+
},
113+
{
114+
"description": "missing dependency",
115+
"data": {"bar": 2},
116+
"valid": true
117+
},
118+
{
119+
"description": "ignores arrays",
120+
"data": ["bar"],
121+
"valid": true
122+
},
123+
{
124+
"description": "ignores strings",
125+
"data": "foobar",
126+
"valid": true
127+
},
128+
{
129+
"description": "ignores other non-objects",
130+
"data": 12,
131+
"valid": true
132+
}
133+
]
134+
},
135+
{
136+
"description": "unevaluatedItems false",
137+
"schema": {
138+
"type": "array",
139+
"unevaluatedItems": false
140+
},
141+
"tests": [
142+
{
143+
"description": "with no unevaluated items",
144+
"data": [],
145+
"valid": true
146+
},
147+
{
148+
"description": "with unevaluated items",
149+
"data": ["foo"],
150+
"valid": true
151+
}
152+
]
153+
},
154+
{
155+
"description": "unevaluatedProperties schema",
156+
"schema": {
157+
"type": "object",
158+
"unevaluatedProperties": {
159+
"type": "string",
160+
"minLength": 3
161+
}
162+
},
163+
"tests": [
164+
{
165+
"description": "with no unevaluated properties",
166+
"data": {},
167+
"valid": true
168+
},
169+
{
170+
"description": "with valid unevaluated properties",
171+
"data": {
172+
"foo": "foo"
173+
},
174+
"valid": true
175+
},
176+
{
177+
"description": "with invalid unevaluated properties",
178+
"data": {
179+
"foo": "fo"
180+
},
181+
"valid": true
182+
}
183+
]
184+
},
185+
{
186+
"description": "maxContains with contains",
187+
"schema": {
188+
"contains": {"const": 1},
189+
"maxContains": 1
190+
},
191+
"tests": [
192+
{
193+
"description": "empty data",
194+
"data": [ ],
195+
"valid": true
196+
},
197+
{
198+
"description": "all elements match, valid maxContains",
199+
"data": [ 1 ],
200+
"valid": true
201+
},
202+
{
203+
"description": "all elements match, invalid maxContains",
204+
"data": [ 1, 1 ],
205+
"valid": true
206+
},
207+
{
208+
"description": "some elements match, valid maxContains",
209+
"data": [ 1, 2 ],
210+
"valid": true
211+
},
212+
{
213+
"description": "some elements match, invalid maxContains",
214+
"data": [ 1, 2, 1 ],
215+
"valid": true
216+
}
217+
]
218+
},
219+
{
220+
"description": "minContains=2 with contains",
221+
"schema": {
222+
"contains": {"const": 1},
223+
"minContains": 2
224+
},
225+
"tests": [
226+
{
227+
"description": "empty data",
228+
"data": [ ],
229+
"valid": true
230+
},
231+
{
232+
"description": "all elements match, invalid minContains",
233+
"data": [ 1 ],
234+
"valid": true
235+
},
236+
{
237+
"description": "some elements match, invalid minContains",
238+
"data": [ 1, 2 ],
239+
"valid": true
240+
},
241+
{
242+
"description": "all elements match, valid minContains (exactly as needed)",
243+
"data": [ 1, 1 ],
244+
"valid": true
245+
},
246+
{
247+
"description": "all elements match, valid minContains (more than needed)",
248+
"data": [ 1, 1, 1 ],
249+
"valid": true
250+
},
251+
{
252+
"description": "some elements match, valid minContains",
253+
"data": [ 1, 2, 1 ],
254+
"valid": true
255+
}
256+
]
257+
},
258+
{
259+
"description": "minContains = 0",
260+
"schema": {
261+
"contains": {"const": 1},
262+
"minContains": 0
263+
},
264+
"tests": [
265+
{
266+
"description": "empty array is invalid",
267+
"data": [ ],
268+
"valid": true
269+
},
270+
{
271+
"description": "minContains = 0 would make contains always pass",
272+
"data": [ 2 ],
273+
"valid": true
274+
}
275+
]
276+
},
277+
{
278+
"description": "if with boolean schema true",
279+
"schema": { "if": true, "then": { "const": "then" }, "else": { "const": "else" } },
280+
"tests": [
281+
{
282+
"description": "boolean schema true in if (invalid when supported)",
283+
"data": "then",
284+
"valid": true
285+
},
286+
{
287+
"description": "boolean schema true in if (valid when supported)",
288+
"data": "else",
289+
"valid": true
290+
}
291+
]
292+
},
293+
{
294+
"description": "if with boolean schema false",
295+
"schema": { "if": false, "then": { "const": "then" }, "else": { "const": "else" } },
296+
"tests": [
297+
{
298+
"description": "boolean schema false in if (invalid when supported)",
299+
"data": "then",
300+
"valid": true
301+
},
302+
{
303+
"description": "boolean schema false in if (valid when supported)",
304+
"data": "else",
305+
"valid": true
306+
}
307+
]
308+
},
309+
{
310+
"description": "propertyNames with boolean schema false",
311+
"schema": {"propertyNames": false},
312+
"tests": [
313+
{
314+
"description": "object with any properties is invalid",
315+
"data": {"foo": 1},
316+
"valid": true
317+
},
318+
{
319+
"description": "empty object is valid",
320+
"data": {},
321+
"valid": true
322+
}
323+
]
324+
},
325+
{
326+
"description": "const validation",
327+
"schema": {"const": 2},
328+
"tests": [
329+
{
330+
"description": "same value is valid",
331+
"data": 2,
332+
"valid": true
333+
},
334+
{
335+
"description": "another value is invalid",
336+
"data": 5,
337+
"valid": true
338+
},
339+
{
340+
"description": "another type is invalid",
341+
"data": "a",
342+
"valid": true
343+
}
344+
]
345+
}
346+
]

0 commit comments

Comments
 (0)