Skip to content

Commit

Permalink
some tests for keywords added in later drafts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
karenetheridge committed Jun 3, 2020
1 parent c3f4319 commit 45bda8b
Show file tree
Hide file tree
Showing 3 changed files with 933 additions and 0 deletions.
346 changes: 346 additions & 0 deletions tests/draft4/unrecognized-keywords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,346 @@
[
{
"description": "$anchor: location-independent identifier",
"schema": {
"allOf": [{
"$ref": "#foo"
}],
"$defs": {
"A": {
"$anchor": "foo",
"type": "integer"
}
}
},
"tests": [
{
"data": 1,
"description": "cannot match: $ref is not found",
"valid": false
},
{
"data": "a",
"description": "mismatch",
"valid": false
}
]
},
{
"description": "$id: Location-independent identifier",
"schema": {
"allOf": [{
"$ref": "#foo"
}],
"$defs": {
"A": {
"$id": "#foo",
"type": "integer"
}
}
},
"tests": [
{
"data": 1,
"description": "match",
"valid": true
},
{
"data": "a",
"description": "mismatch",
"valid": false
}
]
},
{
"description": "dependentSchemas: single dependency",
"schema": {
"dependentSchemas": {
"bar": {
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "integer"}
}
}
}
},
"tests": [
{
"description": "valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "no dependency",
"data": {"foo": "quux"},
"valid": true
},
{
"description": "wrong type",
"data": {"foo": "quux", "bar": 2},
"valid": true
},
{
"description": "wrong type other",
"data": {"foo": 2, "bar": "quux"},
"valid": true
},
{
"description": "wrong type both",
"data": {"foo": "quux", "bar": "quux"},
"valid": true
}
]
},
{
"description": "dependentRequired: single dependency",
"schema": {"dependentRequired": {"bar": ["foo"]}},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependant",
"data": {"foo": 1},
"valid": true
},
{
"description": "with dependency",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "missing dependency",
"data": {"bar": 2},
"valid": true
},
{
"description": "ignores arrays",
"data": ["bar"],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "unevaluatedItems false",
"schema": {
"type": "array",
"unevaluatedItems": false
},
"tests": [
{
"description": "with no unevaluated items",
"data": [],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo"],
"valid": true
}
]
},
{
"description": "unevaluatedProperties schema",
"schema": {
"type": "object",
"unevaluatedProperties": {
"type": "string",
"minLength": 3
}
},
"tests": [
{
"description": "with no unevaluated properties",
"data": {},
"valid": true
},
{
"description": "with valid unevaluated properties",
"data": {
"foo": "foo"
},
"valid": true
},
{
"description": "with invalid unevaluated properties",
"data": {
"foo": "fo"
},
"valid": true
}
]
},
{
"description": "maxContains with contains",
"schema": {
"contains": {"const": 1},
"maxContains": 1
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": true
},
{
"description": "all elements match, valid maxContains",
"data": [ 1 ],
"valid": true
},
{
"description": "all elements match, invalid maxContains",
"data": [ 1, 1 ],
"valid": true
},
{
"description": "some elements match, valid maxContains",
"data": [ 1, 2 ],
"valid": true
},
{
"description": "some elements match, invalid maxContains",
"data": [ 1, 2, 1 ],
"valid": true
}
]
},
{
"description": "minContains=2 with contains",
"schema": {
"contains": {"const": 1},
"minContains": 2
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": true
},
{
"description": "all elements match, invalid minContains",
"data": [ 1 ],
"valid": true
},
{
"description": "some elements match, invalid minContains",
"data": [ 1, 2 ],
"valid": true
},
{
"description": "all elements match, valid minContains (exactly as needed)",
"data": [ 1, 1 ],
"valid": true
},
{
"description": "all elements match, valid minContains (more than needed)",
"data": [ 1, 1, 1 ],
"valid": true
},
{
"description": "some elements match, valid minContains",
"data": [ 1, 2, 1 ],
"valid": true
}
]
},
{
"description": "minContains = 0",
"schema": {
"contains": {"const": 1},
"minContains": 0
},
"tests": [
{
"description": "empty array is invalid",
"data": [ ],
"valid": true
},
{
"description": "minContains = 0 would make contains always pass",
"data": [ 2 ],
"valid": true
}
]
},
{
"description": "if with boolean schema true",
"schema": { "if": true, "then": { "const": "then" }, "else": { "const": "else" } },
"tests": [
{
"description": "boolean schema true in if (invalid when supported)",
"data": "then",
"valid": true
},
{
"description": "boolean schema true in if (valid when supported)",
"data": "else",
"valid": true
}
]
},
{
"description": "if with boolean schema false",
"schema": { "if": false, "then": { "const": "then" }, "else": { "const": "else" } },
"tests": [
{
"description": "boolean schema false in if (invalid when supported)",
"data": "then",
"valid": true
},
{
"description": "boolean schema false in if (valid when supported)",
"data": "else",
"valid": true
}
]
},
{
"description": "propertyNames with boolean schema false",
"schema": {"propertyNames": false},
"tests": [
{
"description": "object with any properties is invalid",
"data": {"foo": 1},
"valid": true
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "const validation",
"schema": {"const": 2},
"tests": [
{
"description": "same value is valid",
"data": 2,
"valid": true
},
{
"description": "another value is invalid",
"data": 5,
"valid": true
},
{
"description": "another type is invalid",
"data": "a",
"valid": true
}
]
}
]
Loading

0 comments on commit 45bda8b

Please sign in to comment.