Skip to content

Commit

Permalink
[244] Add a bunch of meta-schema tests
Browse files Browse the repository at this point in the history
This adds tests using the meta-schema as a schema. This does not test things
that cannot currently be guaranteed to be represented in a schema, for example,
normalized URL requirements and optional "format" for "pattern".
  • Loading branch information
ssilverman committed Aug 21, 2020
1 parent fce9e9b commit 88dd621
Show file tree
Hide file tree
Showing 53 changed files with 3,425 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/draft2019-09/additionalItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,55 @@
"valid": false
}
]
},
{
"description": "Meta-schema applicator tests: array",
"schema": {
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "Non-schema additionalItems: number",
"data": {
"additionalItems": 1
},
"valid": false
},
{
"description": "Non-schema additionalItems: string",
"data": {
"additionalItems": "hello"
},
"valid": false
},
{
"description": "Non-schema additionalItems: array",
"data": {
"additionalItems": []
},
"valid": false
},
{
"description": "Non-schema additionalItems: null",
"data": {
"additionalItems": null
},
"valid": false
},
{
"description": "Boolean additionalItems",
"data": {
"additionalItems": true
},
"valid": true
},
{
"description": "Object additionalItems",
"data": {
"additionalItems": {}
},
"valid": true
}
]
}
]
50 changes: 50 additions & 0 deletions tests/draft2019-09/additionalProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,55 @@
"valid": false
}
]
},
{
"description": "Meta-schema applicator tests: object",
"schema": {
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "Non-schema additionalProperties: number",
"data": {
"additionalProperties": 1
},
"valid": false
},
{
"description": "Non-schema additionalProperties: string",
"data": {
"additionalProperties": "hello"
},
"valid": false
},
{
"description": "Non-schema additionalProperties: array",
"data": {
"additionalProperties": []
},
"valid": false
},
{
"description": "Non-schema additionalProperties: null",
"data": {
"additionalProperties": null
},
"valid": false
},
{
"description": "Boolean additionalProperties",
"data": {
"additionalProperties": true
},
"valid": true
},
{
"description": "Object additionalProperties",
"data": {
"additionalProperties": {}
},
"valid": true
}
]
}
]
99 changes: 99 additions & 0 deletions tests/draft2019-09/allOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,104 @@
"valid": true
}
]
},
{
"description": "Meta-schema applicator tests: Boolean logic",
"schema": {
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "Non-array allOf: number",
"data": {
"allOf": 1
},
"valid": false
},
{
"description": "Non-array allOf: string",
"data": {
"allOf": "hello"
},
"valid": false
},
{
"description": "Non-array allOf: Boolean",
"data": {
"allOf": true
},
"valid": false
},
{
"description": "Non-array allOf: object",
"data": {
"allOf": {}
},
"valid": false
},
{
"description": "Non-array allOf: null",
"data": {
"allOf": null
},
"valid": false
},
{
"description": "Empty allOf",
"data": {
"allOf": []
},
"valid": false
},
{
"description": "Not-a-schema allOf: string",
"data": {
"allOf": [ "integer" ]
},
"valid": false
},
{
"description": "Not-a-schema allOf: number",
"data": {
"allOf": [ 1 ]
},
"valid": false
},
{
"description": "Not-a-schema allOf: null",
"data": {
"allOf": [ null ]
},
"valid": false
},
{
"description": "Not-a-schema allOf: array",
"data": {
"allOf": [ [] ]
},
"valid": false
},
{
"description": "Valid allOf: boolean schema",
"data": {
"allOf": [ true ]
},
"valid": true
},
{
"description": "Valid allOf: empty schema",
"data": {
"allOf": [ {} ]
},
"valid": true
},
{
"description": "Valid allOf: schema",
"data": {
"allOf": [ { "type": "integer" } ]
},
"valid": true
}
]
}
]
90 changes: 90 additions & 0 deletions tests/draft2019-09/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,95 @@
"valid": false
}
]
},
{
"description": "Meta-schema core tests: $anchor",
"schema": {
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "Non-string $anchor: number",
"data": {
"$anchor": 1
},
"valid": false
},
{
"description": "Non-string $anchor: Boolean",
"data": {
"$anchor": true
},
"valid": false
},
{
"description": "Non-string $anchor: null",
"data": {
"$anchor": null
},
"valid": false
},
{
"description": "Non-string $anchor: array",
"data": {
"$anchor": []
},
"valid": false
},
{
"description": "Non-string $anchor: object",
"data": {
"$anchor": {}
},
"valid": false
},
{
"description": "Valid $anchor",
"data": {
"$anchor": "himom"
},
"valid": true
},
{
"description": "Invalid $anchor: starts with invalid",
"data": {
"$anchor": "-himom"
},
"valid": false
},
{
"description": "Invalid $anchor: ends with invalid",
"data": {
"$anchor": "himom@"
},
"valid": false
},
{
"description": "Fragment syntax disallowed",
"data": {
"$ref": "#foo",
"$defs": {
"A": {
"$anchor": "#foo",
"type": "integer"
}
}
},
"valid": false
},
{
"description": "Invalid characters disallowed",
"data": {
"$ref": "#/a/b",
"$defs": {
"A": {
"$anchor": "/a/b",
"type": "integer"
}
}
},
"valid": false
}
]
}
]
Loading

0 comments on commit 88dd621

Please sign in to comment.