Skip to content

Commit e04b45a

Browse files
committed
chore(test-suite): update official test suite from json-schema-org/JSON-Schema-Test-Suite
1 parent 6e332ca commit e04b45a

18 files changed

Lines changed: 614 additions & 1 deletion

File tree

lib/src/testFixtures/resources/suite-annotation/core.json

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,108 @@
2525
]
2626
}
2727
]
28+
},
29+
{
30+
"description": "`$dynamicRef` resolves to `$dynamicAnchor`",
31+
"compatibility": "2020",
32+
"schema": {
33+
"$dynamicRef": "#foo",
34+
"$defs": {
35+
"foo": {
36+
"$dynamicAnchor": "foo",
37+
"title": "Foo"
38+
}
39+
}
40+
},
41+
"tests": [
42+
{
43+
"instance": "bar",
44+
"assertions": [
45+
{
46+
"location": "",
47+
"keyword": "title",
48+
"expected": {
49+
"#/$defs/foo": "Foo"
50+
}
51+
}
52+
]
53+
}
54+
]
55+
},
56+
{
57+
"description": "`$dynamicRef` resolves to different `$dynamicAnchor`s depending on dynamic path",
58+
"compatibility": "2020",
59+
"schema": {
60+
"$id": "https://test.json-schema.org/dynamic-ref-annotation/main",
61+
"if": {
62+
"properties": { "kindOfList": { "const": "numbers" } },
63+
"required": ["kindOfList"]
64+
},
65+
"then": { "$ref": "numberList" },
66+
"else": { "$ref": "stringList" },
67+
"$defs": {
68+
"genericList": {
69+
"$id": "genericList",
70+
"properties": {
71+
"list": {
72+
"items": { "$dynamicRef": "#itemType" }
73+
}
74+
},
75+
"$defs": {
76+
"defaultItemType": {
77+
"$dynamicAnchor": "itemType"
78+
}
79+
}
80+
},
81+
"numberList": {
82+
"$id": "numberList",
83+
"$defs": {
84+
"itemType": {
85+
"$dynamicAnchor": "itemType",
86+
"title": "Number Item"
87+
}
88+
},
89+
"$ref": "genericList"
90+
},
91+
"stringList": {
92+
"$id": "stringList",
93+
"$defs": {
94+
"itemType": {
95+
"$dynamicAnchor": "itemType",
96+
"title": "String Item"
97+
}
98+
},
99+
"$ref": "genericList"
100+
}
101+
}
102+
},
103+
"tests": [
104+
{
105+
"instance": { "kindOfList": "numbers", "list": [1] },
106+
"assertions": [
107+
{
108+
"location": "/list/0",
109+
"keyword": "title",
110+
"expected": {
111+
"#/$defs/numberList/$defs/itemType": "Number Item"
112+
}
113+
}
114+
]
115+
},
116+
{
117+
"instance": { "kindOfList": "strings", "list": ["foo"] },
118+
"assertions": [
119+
{
120+
"location": "/list/0",
121+
"keyword": "title",
122+
"expected": {
123+
"#/$defs/stringList/$defs/itemType": "String Item"
124+
}
125+
}
126+
]
127+
}
128+
]
28129
}
130+
29131
]
30-
}
132+
}

lib/src/testFixtures/resources/suite/tests/draft2019-09/enum.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,44 @@
354354
"valid": false
355355
}
356356
]
357+
},
358+
{
359+
"description": "empty enum",
360+
"schema": {
361+
"$schema": "https://json-schema.org/draft/2019-09/schema",
362+
"enum": []
363+
},
364+
"tests": [
365+
{
366+
"description": "string is invalid",
367+
"data": "foo",
368+
"valid": false
369+
},
370+
{
371+
"description": "number is invalid",
372+
"data": 42,
373+
"valid": false
374+
},
375+
{
376+
"description": "null is invalid",
377+
"data": null,
378+
"valid": false
379+
},
380+
{
381+
"description": "object is invalid",
382+
"data": {},
383+
"valid": false
384+
},
385+
{
386+
"description": "array is invalid",
387+
"data": [],
388+
"valid": false
389+
},
390+
{
391+
"description": "boolean is invalid",
392+
"data": false,
393+
"valid": false
394+
}
395+
]
357396
}
358397
]

lib/src/testFixtures/resources/suite/tests/draft2019-09/maxContains.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,26 @@
9898
"valid": false
9999
}
100100
]
101+
},
102+
{
103+
"description": "maxContains = 0 with minContains = 0",
104+
"schema": {
105+
"$schema": "https://json-schema.org/draft/2019-09/schema",
106+
"contains": {"const": 1},
107+
"minContains": 0,
108+
"maxContains": 0
109+
},
110+
"tests": [
111+
{
112+
"description": "empty array",
113+
"data": [ ],
114+
"valid": true
115+
},
116+
{
117+
"description": "one matching item",
118+
"data": [ 1 ],
119+
"valid": false
120+
}
121+
]
101122
}
102123
]

lib/src/testFixtures/resources/suite/tests/draft2019-09/optional/format/duration.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
33
"description": "validation of duration strings",
4+
"comment": "RFC 3339 Appendix A defines the ABNF grammar for ISO-8601 durations used by JSON Schema format 'duration'. These tests enforce only the syntax defined by that grammar.",
45
"schema": {
56
"$schema": "https://json-schema.org/draft/2019-09/schema",
67
"format": "duration"
@@ -135,6 +136,87 @@
135136
"description": "element without unit",
136137
"data": "P1",
137138
"valid": false
139+
},
140+
{
141+
"description": "all date and time components",
142+
"data": "P1Y2M3DT4H5M6S",
143+
"valid": true
144+
},
145+
{
146+
"description": "date components only",
147+
"data": "P1Y2M3D",
148+
"valid": true
149+
},
150+
{
151+
"description": "time components only",
152+
"data": "PT1H2M3S",
153+
"valid": true
154+
},
155+
{
156+
"description": "month and day",
157+
"data": "P1M2D",
158+
"valid": true
159+
},
160+
{
161+
"description": "hour and minute",
162+
"data": "PT1H30M",
163+
"valid": true
164+
},
165+
{
166+
"description": "multi-digit values in all components",
167+
"data": "P10Y10M10DT10H10M10S",
168+
"valid": true
169+
},
170+
{
171+
"description": "fractional duration is not allowed by RFC 3339 ABNF",
172+
"comment": "numeric components use 1*DIGIT where DIGIT = %x30-39; '.' is not allowed",
173+
"data": "PT0.5S",
174+
"valid": false
175+
},
176+
{
177+
"description": "leading whitespace is invalid",
178+
"data": " P1D",
179+
"valid": false
180+
},
181+
{
182+
"description": "trailing whitespace is invalid",
183+
"data": "P1D ",
184+
"valid": false
185+
},
186+
{
187+
"description": "empty string is invalid",
188+
"data": "",
189+
"valid": false
190+
},
191+
{
192+
"description": "years and months can appear without days",
193+
"data": "P1Y2M",
194+
"valid": true
195+
},
196+
{
197+
"description": "years and days cannot appear without months",
198+
"data": "P1Y2D",
199+
"valid": false
200+
},
201+
{
202+
"description": "months and days can appear without years",
203+
"data": "P1M2D",
204+
"valid": true
205+
},
206+
{
207+
"description": "hours and minutes can appear without seconds",
208+
"data": "PT1H2M",
209+
"valid": true
210+
},
211+
{
212+
"description": "hours and seconds cannot appear without minutes",
213+
"data": "PT1H2S",
214+
"valid": false
215+
},
216+
{
217+
"description": "minutes and seconds can appear without hour",
218+
"data": "PT1M2S",
219+
"valid": true
138220
}
139221
]
140222
}

lib/src/testFixtures/resources/suite/tests/draft2019-09/optional/format/email.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@
9090
"description": "full \"From\" header is invalid",
9191
"data": "\"Winston Smith\" <winston.smith@recdep.minitrue> (Records Department)",
9292
"valid": false
93+
},
94+
{
95+
"description": "local part is required",
96+
"data": "@example.com",
97+
"valid": false
98+
},
99+
{
100+
"description": "domain is required",
101+
"data": "joe.bloggs@",
102+
"valid": false
103+
},
104+
{
105+
"description": "unquoted space in local part is invalid",
106+
"data": "joe bloggs@example.com",
107+
"valid": false
93108
}
94109
]
95110
}

lib/src/testFixtures/resources/suite/tests/draft2019-09/optional/format/uri.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,36 @@
197197
"comment": "RFC 3986, Section 3.2.2: Fallback to reg-name allows digits and dots.",
198198
"data": "http://999.999.999.999/",
199199
"valid": true
200+
},
201+
{
202+
"description": "invalid percent-encoding with non-hex digits",
203+
"data": "http://example.com/%6G",
204+
"valid": false
205+
},
206+
{
207+
"description": "incomplete percent-encoding triplet",
208+
"data": "http://example.com/%A",
209+
"valid": false
210+
},
211+
{
212+
"description": "lone percent sign is invalid",
213+
"data": "http://example.com/%",
214+
"valid": false
215+
},
216+
{
217+
"description": "scheme must start with a letter",
218+
"data": "1http://example.com",
219+
"valid": false
220+
},
221+
{
222+
"description": "invalid character in scheme",
223+
"data": "ht_tp://example.com",
224+
"valid": false
225+
},
226+
{
227+
"description": "non-numeric port is invalid",
228+
"data": "http://example.com:abc/path",
229+
"valid": false
200230
}
201231
]
202232
}

lib/src/testFixtures/resources/suite/tests/draft2020-12/enum.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,44 @@
354354
"valid": false
355355
}
356356
]
357+
},
358+
{
359+
"description": "empty enum",
360+
"schema": {
361+
"$schema": "https://json-schema.org/draft/2020-12/schema",
362+
"enum": []
363+
},
364+
"tests": [
365+
{
366+
"description": "string is invalid",
367+
"data": "foo",
368+
"valid": false
369+
},
370+
{
371+
"description": "number is invalid",
372+
"data": 42,
373+
"valid": false
374+
},
375+
{
376+
"description": "null is invalid",
377+
"data": null,
378+
"valid": false
379+
},
380+
{
381+
"description": "object is invalid",
382+
"data": {},
383+
"valid": false
384+
},
385+
{
386+
"description": "array is invalid",
387+
"data": [],
388+
"valid": false
389+
},
390+
{
391+
"description": "boolean is invalid",
392+
"data": false,
393+
"valid": false
394+
}
395+
]
357396
}
358397
]

0 commit comments

Comments
 (0)