Skip to content

Commit 890ea1f

Browse files
Add specification property to draft2020-12 type tests (fixes #699)
1 parent d69537a commit 890ea1f

File tree

11 files changed

+393
-311
lines changed

11 files changed

+393
-311
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,13 @@ Here is a single *test case*, containing one or more tests:
7979

8080
### Subdirectories Within Each Version directory
8181

82-
There is currently only one additional subdirectory that may exist within each specification version test directory.
82+
A specification version test directory may contain one or more subdirectories.
8383

84-
This is:
84+
These are:
8585

86-
1. `optional/`: Contains tests that are considered optional.
86+
1. `optional/`: Contains tests that are considered optional. Note that this subdirectory currently conflates many reasons why a test may be optional -- it may be because tests within a particular file are indeed not required by the specification but still potentially useful to an implementer, or it may be because tests within it only apply to programming languages with particular functionality (in which case they are not truly optional in such a language). In the future this directory structure will be made richer to reflect these differences more clearly.
8787

88-
Note, the `optional/` subdirectory today conflates many reasons why a test may be optional -- it may be because tests within a particular file are indeed not required by the specification but still potentially useful to an implementer, or it may be because tests within it only apply to programming languages with particular functionality (in
89-
which case they are not truly optional in such a language).
90-
In the future this directory structure will be made richer to reflect these differences more clearly.
88+
2. `proposals/`: Contains a subfolder for each active proposal to the specification. If the proposal is a keyword (generally the case), then the subfolder will bear the name of that keyword. Inside the proposal subfolder is a series of test files that would contain amendments to the required test suite should the proposal be incorporated into the specification. These test should be considered volitile while the proposal is in development, however implementations claiming to support the proposal are expected to pass its tests.
9189

9290
## Using the Suite to Test a Validator Implementation
9391

test-schema.json

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
33
"$id": "https://json-schema.org/tests/test-schema",
44
"description": "A schema for files contained within this suite",
5-
65
"type": "array",
76
"minItems": 1,
87
"items": {
98
"description": "An individual test case, containing multiple tests of a single schema's behavior",
10-
119
"type": "object",
12-
"required": [ "description", "schema", "tests" ],
10+
"required": [
11+
"description",
12+
"schema",
13+
"tests"
14+
],
1315
"properties": {
1416
"description": {
1517
"description": "The test case description",
@@ -25,67 +27,76 @@
2527
"tests": {
2628
"description": "A set of related tests all using the same schema",
2729
"type": "array",
28-
"items": { "$ref": "#/$defs/test" },
30+
"items": {
31+
"$ref": "#/$defs/test"
32+
},
2933
"minItems": 1
3034
},
31-
"specification":{
35+
"specification": {
3236
"description": "A reference to a specification document which defines the behavior tested by this test case. Typically this should be a JSON Schema specification document, though in cases where the JSON Schema specification points to another RFC it should contain *both* the portion of the JSON Schema specification which indicates what RFC (and section) to follow as *well* as information on where in that specification the behavior is specified.",
33-
3437
"type": "array",
3538
"minItems": 1,
3639
"uniqueItems": true,
37-
"items":{
40+
"items": {
3841
"properties": {
39-
"core": {
42+
"core": {
4043
"description": "A section in official JSON Schema core drafts",
4144
"url": "https://json-schema.org/specification-links",
42-
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
43-
"type":"string"
45+
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
46+
"type": "string"
4447
},
4548
"validation": {
4649
"description": "A section in official JSON Schema validation drafts",
4750
"url": "https://json-schema.org/specification-links",
48-
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
49-
"type":"string"
51+
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
52+
"type": "string"
5053
},
51-
"ecma262": {
54+
"ecma262": {
5255
"description": "A section in official ECMA 262 specification for defining regular expressions",
5356
"url": "https://262.ecma-international.org/",
54-
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
55-
"type":"string"
57+
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
58+
"type": "string"
5659
},
57-
"perl5": {
60+
"perl5": {
5861
"description": "A section name in Perl documentation for defining regular expressions",
5962
"url": "https://perldoc.perl.org/perlre",
60-
"type":"string"
63+
"type": "string"
6164
},
62-
"quote": {
65+
"quote": {
6366
"description": "Quote describing the test case",
64-
"type":"string"
67+
"type": "string"
6568
}
6669
},
6770
"patternProperties": {
68-
"^rfc\\d+$": {
71+
"^rfc\\d+$": {
6972
"description": "A section in official RFC for the given rfc number",
7073
"url": "https://www.rfc-editor.org/",
71-
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
72-
"type":"string"
74+
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
75+
"type": "string"
7376
},
74-
"^iso\\d+$": {
77+
"^iso\\d+$": {
7578
"description": "A section in official ISO for the given iso number",
76-
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
77-
"type": "string"
79+
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
80+
"type": "string"
7881
}
7982
},
80-
"additionalProperties": { "type": "string" },
83+
"additionalProperties": {
84+
"type": "string"
85+
},
8186
"minProperties": 1,
8287
"propertyNames": {
8388
"oneOf": [
8489
{
8590
"pattern": "^((iso)|(rfc))[0-9]+$"
8691
},
8792
{
88-
"enum": [ "core", "validation", "ecma262", "perl5", "quote" ]
93+
"enum": [
94+
"core",
95+
"validation",
96+
"ecma262",
97+
"perl5",
98+
"quote"
99+
]
89100
}
90101
]
91102
}
@@ -94,13 +105,15 @@
94105
},
95106
"additionalProperties": false
96107
},
97-
98108
"$defs": {
99109
"test": {
100110
"description": "A single test",
101-
102111
"type": "object",
103-
"required": [ "description", "data", "valid" ],
112+
"required": [
113+
"description",
114+
"data",
115+
"valid"
116+
],
104117
"properties": {
105118
"description": {
106119
"description": "The test description, briefly explaining which behavior it exercises",
@@ -121,4 +134,4 @@
121134
"additionalProperties": false
122135
}
123136
}
124-
}
137+
}

tests/draft2020-12/type.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[
22
{
33
"description": "integer type matches integers",
4+
"specification": [
5+
{
6+
"validation": "6.1.1"
7+
}],
48
"schema": {
59
"$schema": "https://json-schema.org/draft/2020-12/schema",
610
"type": "integer"
@@ -55,6 +59,11 @@
5559
},
5660
{
5761
"description": "number type matches numbers",
62+
"specification": [
63+
{
64+
"validation": "6.1.1"
65+
}],
66+
5867
"schema": {
5968
"$schema": "https://json-schema.org/draft/2020-12/schema",
6069
"type": "number"
@@ -109,6 +118,11 @@
109118
},
110119
{
111120
"description": "string type matches strings",
121+
"specification": [
122+
{
123+
"validation": "6.1.1"
124+
}],
125+
112126
"schema": {
113127
"$schema": "https://json-schema.org/draft/2020-12/schema",
114128
"type": "string"
@@ -163,6 +177,11 @@
163177
},
164178
{
165179
"description": "object type matches objects",
180+
"specification": [
181+
{
182+
"validation": "6.1.1"
183+
}],
184+
166185
"schema": {
167186
"$schema": "https://json-schema.org/draft/2020-12/schema",
168187
"type": "object"
@@ -207,6 +226,11 @@
207226
},
208227
{
209228
"description": "array type matches arrays",
229+
"specification": [
230+
{
231+
"validation": "6.1.1"
232+
}],
233+
210234
"schema": {
211235
"$schema": "https://json-schema.org/draft/2020-12/schema",
212236
"type": "array"
@@ -251,6 +275,11 @@
251275
},
252276
{
253277
"description": "boolean type matches booleans",
278+
"specification": [
279+
{
280+
"validation": "6.1.1"
281+
}],
282+
254283
"schema": {
255284
"$schema": "https://json-schema.org/draft/2020-12/schema",
256285
"type": "boolean"
@@ -310,6 +339,11 @@
310339
},
311340
{
312341
"description": "null type matches only the null object",
342+
"specification": [
343+
{
344+
"validation": "6.1.1"
345+
}],
346+
313347
"schema": {
314348
"$schema": "https://json-schema.org/draft/2020-12/schema",
315349
"type": "null"
@@ -369,6 +403,11 @@
369403
},
370404
{
371405
"description": "multiple types can be specified in an array",
406+
"specification": [
407+
{
408+
"validation": "6.1.1"
409+
}],
410+
372411
"schema": {
373412
"$schema": "https://json-schema.org/draft/2020-12/schema",
374413
"type": ["integer", "string"]
@@ -413,6 +452,11 @@
413452
},
414453
{
415454
"description": "type as array with one item",
455+
"specification": [
456+
{
457+
"validation": "6.1.1"
458+
}],
459+
416460
"schema": {
417461
"$schema": "https://json-schema.org/draft/2020-12/schema",
418462
"type": ["string"]
@@ -432,6 +476,11 @@
432476
},
433477
{
434478
"description": "type: array or object",
479+
"specification": [
480+
{
481+
"validation": "6.1.1"
482+
}],
483+
435484
"schema": {
436485
"$schema": "https://json-schema.org/draft/2020-12/schema",
437486
"type": ["array", "object"]
@@ -466,6 +515,11 @@
466515
},
467516
{
468517
"description": "type: array, object or null",
518+
"specification": [
519+
{
520+
"validation": "6.1.1"
521+
}],
522+
469523
"schema": {
470524
"$schema": "https://json-schema.org/draft/2020-12/schema",
471525
"type": ["array", "object", "null"]
@@ -499,3 +553,4 @@
499553
]
500554
}
501555
]
556+

tests/v1/additionalProperties.json

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -177,41 +177,6 @@
177177
}
178178
]
179179
},
180-
{
181-
"description": "propertyDependencies with additionalProperties",
182-
"schema": {
183-
"$schema": "https://json-schema.org/v1",
184-
"properties" : {"foo2" : {}},
185-
"propertyDependencies": {
186-
"foo" : {},
187-
"foo2": {
188-
"bar": {
189-
"properties": {
190-
"buz": {}
191-
}
192-
}
193-
}
194-
},
195-
"additionalProperties": false
196-
},
197-
"tests": [
198-
{
199-
"description": "additionalProperties doesn't consider propertyDependencies properties" ,
200-
"data": {"foo": ""},
201-
"valid": false
202-
},
203-
{
204-
"description": "additionalProperties can't see buz even when foo2 is present",
205-
"data": {"foo2": "bar", "buz": ""},
206-
"valid": false
207-
},
208-
{
209-
"description": "additionalProperties can't see buz",
210-
"data": {"buz": ""},
211-
"valid": false
212-
}
213-
]
214-
},
215180
{
216181
"description": "dependentSchemas with additionalProperties",
217182
"schema": {

0 commit comments

Comments
 (0)