Skip to content

Commit 530a0f3

Browse files
committed
Finish type tests.
1 parent 4f9cd46 commit 530a0f3

File tree

1 file changed

+152
-8
lines changed

1 file changed

+152
-8
lines changed

tests/draft3/type.json

+152-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"description": "integer type",
3+
"description": "integer type matches integers",
44
"schema": {"type": "integer"},
55
"tests": [
66
{
@@ -41,7 +41,7 @@
4141
]
4242
},
4343
{
44-
"description": "number type",
44+
"description": "number type matches numbers",
4545
"schema": {"type": "number"},
4646
"tests": [
4747
{
@@ -82,7 +82,7 @@
8282
]
8383
},
8484
{
85-
"description": "string type",
85+
"description": "string type matches strings",
8686
"schema": {"type": "string"},
8787
"tests": [
8888
{
@@ -123,7 +123,7 @@
123123
]
124124
},
125125
{
126-
"description": "object type",
126+
"description": "object type matches objects",
127127
"schema": {"type": "object"},
128128
"tests": [
129129
{
@@ -164,7 +164,7 @@
164164
]
165165
},
166166
{
167-
"description": "array type",
167+
"description": "array type matches arrays",
168168
"schema": {"type": "array"},
169169
"tests": [
170170
{
@@ -205,7 +205,7 @@
205205
]
206206
},
207207
{
208-
"description": "boolean type",
208+
"description": "boolean type matches booleans",
209209
"schema": {"type": "boolean"},
210210
"tests": [
211211
{
@@ -246,7 +246,7 @@
246246
]
247247
},
248248
{
249-
"description": "null type",
249+
"description": "null type matches only the null object",
250250
"schema": {"type": "null"},
251251
"tests": [
252252
{
@@ -287,7 +287,7 @@
287287
]
288288
},
289289
{
290-
"description": "any type",
290+
"description": "any type matches any type",
291291
"schema": {"type": "any"},
292292
"tests": [
293293
{
@@ -326,5 +326,149 @@
326326
"valid": true
327327
}
328328
]
329+
},
330+
{
331+
"description": "multiple types can be specified in an array",
332+
"schema": {"type": ["integer", "string"]},
333+
"tests": [
334+
{
335+
"description": "an integer is valid",
336+
"data": 1,
337+
"valid": true
338+
},
339+
{
340+
"description": "a string is valid",
341+
"data": "foo",
342+
"valid": true
343+
},
344+
{
345+
"description": "a float is invalid",
346+
"data": 1.1,
347+
"valid": false
348+
},
349+
{
350+
"description": "an object is invalid",
351+
"data": {},
352+
"valid": false
353+
},
354+
{
355+
"description": "an array is invalid",
356+
"data": [],
357+
"valid": false
358+
},
359+
{
360+
"description": "a boolean is invalid",
361+
"data": true,
362+
"valid": false
363+
},
364+
{
365+
"description": "null is invalid",
366+
"data": null,
367+
"valid": false
368+
}
369+
]
370+
},
371+
{
372+
"description": "types can include schemas",
373+
"schema": {
374+
"type": [
375+
"array",
376+
{"type": "object"}
377+
]
378+
},
379+
"tests": [
380+
{
381+
"description": "an integer is invalid",
382+
"data": 1,
383+
"valid": false
384+
},
385+
{
386+
"description": "a string is invalid",
387+
"data": "foo",
388+
"valid": false
389+
},
390+
{
391+
"description": "a float is invalid",
392+
"data": 1.1,
393+
"valid": false
394+
},
395+
{
396+
"description": "an object is valid",
397+
"data": {},
398+
"valid": true
399+
},
400+
{
401+
"description": "an array is valid",
402+
"data": [],
403+
"valid": true
404+
},
405+
{
406+
"description": "a boolean is invalid",
407+
"data": true,
408+
"valid": false
409+
},
410+
{
411+
"description": "null is invalid",
412+
"data": null,
413+
"valid": false
414+
}
415+
]
416+
},
417+
{
418+
"description":
419+
"when types includes a schema it should fully validate the schema",
420+
"schema": {
421+
"type": [
422+
"integer",
423+
{
424+
"properties": {
425+
"foo": {"type": "null"}
426+
}
427+
}
428+
]
429+
},
430+
"tests": [
431+
{
432+
"description": "an integer is valid",
433+
"data": 1,
434+
"valid": true
435+
},
436+
{
437+
"description": "an object is valid only if it is fully valid",
438+
"data": {"foo": null},
439+
"valid": true
440+
},
441+
{
442+
"description": "an object is invalid otherwise",
443+
"data": {"foo": "bar"},
444+
"valid": false
445+
},
446+
]
447+
},
448+
{
449+
"description": "types from separate schemas are merged",
450+
"schema": {
451+
"type": [
452+
{"type": ["string"]},
453+
{"type": ["array", "null"]},
454+
]
455+
},
456+
"tests": [
457+
{
458+
"description": "an integer is invalid",
459+
"data": 1,
460+
"valid": false
461+
},
462+
{
463+
"description": "a string is valid",
464+
"data": "foo",
465+
"valid": true
466+
},
467+
{
468+
"description": "an array is valid",
469+
"data": [1, 2, 3],
470+
"valid": true
471+
}
472+
]
329473
}
330474
]

0 commit comments

Comments
 (0)