diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/allOf.json b/test/JSON-Schema-Test-Suite/tests/draft7/allOf.json index 00c016c..eb61209 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/allOf.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/allOf.json @@ -141,5 +141,78 @@ "valid": false } ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "allOf": [ + {}, + { "type": "number" } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "allOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/anyOf.json b/test/JSON-Schema-Test-Suite/tests/draft7/anyOf.json index 4d05a9e..bad3e77 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/anyOf.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/anyOf.json @@ -138,5 +138,26 @@ "valid": false } ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "anyOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/dependencies.json b/test/JSON-Schema-Test-Suite/tests/draft7/dependencies.json index 80e552f..8dd78aa 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/dependencies.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/dependencies.json @@ -168,5 +168,101 @@ "valid": true } ] + }, + { + "description": "empty array of dependencies", + "schema": { + "dependencies": { + "foo": [] + } + }, + "tests": [ + { + "description": "object with property is valid", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": {"required": ["foo\"bar"]}, + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "valid object 1", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "valid object 2", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "valid object 3", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "invalid object 1", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "invalid object 2", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "invalid object 3", + "data": { + "foo'bar": 1 + }, + "valid": false + }, + { + "description": "invalid object 4", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/enum.json b/test/JSON-Schema-Test-Suite/tests/draft7/enum.json index 8fb9d7a..04a92a4 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/enum.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/enum.json @@ -68,5 +68,28 @@ "valid": false } ] + }, + { + "description": "enum with escaped characters", + "schema": { + "enum": ["foo\nbar", "foo\rbar"] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/items.json b/test/JSON-Schema-Test-Suite/tests/draft7/items.json index 13a6a11..67f1184 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/items.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/items.json @@ -129,5 +129,122 @@ "valid": true } ] + }, + { + "description": "items and subitems", + "schema": { + "definitions": { + "item": { + "type": "array", + "additionalItems": false, + "items": [ + { "$ref": "#/definitions/sub-item" }, + { "$ref": "#/definitions/sub-item" } + ] + }, + "sub-item": { + "type": "object", + "required": ["foo"] + } + }, + "type": "array", + "additionalItems": false, + "items": [ + { "$ref": "#/definitions/item" }, + { "$ref": "#/definitions/item" }, + { "$ref": "#/definitions/item" } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ {"foo": null}, {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + {"foo": null}, + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ {}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "fewer items is valid", + "data": [ + [ {"foo": null} ], + [ {"foo": null} ] + ], + "valid": true + } + ] + }, + { + "description": "nested items", + "schema": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]], + "valid": false + }, + { + "description": "not deep enough", + "data": [[[1], [2],[3]], [[4], [5], [6]]], + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/minimum.json b/test/JSON-Schema-Test-Suite/tests/draft7/minimum.json index bd1e95b..2a9c42b 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/minimum.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/minimum.json @@ -24,5 +24,36 @@ "valid": true } ] + }, + { + "description": "minimum validation with signed integer", + "schema": {"minimum": -2}, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/oneOf.json b/test/JSON-Schema-Test-Suite/tests/draft7/oneOf.json index bc4295c..57640b7 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/oneOf.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/oneOf.json @@ -149,5 +149,58 @@ "valid": false } ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "oneOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "type": "object", + "oneOf": [ + { "required": ["foo", "bar"] }, + { "required": ["foo", "baz"] } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "first valid - valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "second valid - valid", + "data": {"foo": 1, "baz": 3}, + "valid": true + }, + { + "description": "both valid - invalid", + "data": {"foo": 1, "bar": 2, "baz" : 3}, + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/properties.json b/test/JSON-Schema-Test-Suite/tests/draft7/properties.json index c8ad719..b86c181 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/properties.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/properties.json @@ -124,5 +124,44 @@ "valid": false } ] + }, + { + "description": "properties with escaped characters", + "schema": { + "properties": { + "foo\nbar": {"type": "number"}, + "foo\"bar": {"type": "number"}, + "foo\\bar": {"type": "number"}, + "foo\rbar": {"type": "number"}, + "foo\tbar": {"type": "number"}, + "foo\fbar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/ref.json b/test/JSON-Schema-Test-Suite/tests/draft7/ref.json index 7579507..fecfe7e 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/ref.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/ref.json @@ -328,5 +328,32 @@ "valid": false } ] + }, + { + "description": "refs with quote", + "schema": { + "properties": { + "foo\"bar": {"$ref": "#/definitions/foo\"bar"} + }, + "definitions": { + "foo\"bar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/required.json b/test/JSON-Schema-Test-Suite/tests/draft7/required.json index bd96907..abf18f3 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/required.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/required.json @@ -66,5 +66,40 @@ "valid": true } ] + }, + { + "description": "required with escaped characters", + "schema": { + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false + } + ] } ] diff --git a/test/JSON-Schema-Test-Suite/tests/draft7/type.json b/test/JSON-Schema-Test-Suite/tests/draft7/type.json index 6129374..ea33b18 100644 --- a/test/JSON-Schema-Test-Suite/tests/draft7/type.json +++ b/test/JSON-Schema-Test-Suite/tests/draft7/type.json @@ -115,6 +115,11 @@ "data": "1", "valid": true }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, { "description": "an object is not a string", "data": {}, @@ -228,6 +233,11 @@ "data": 1, "valid": false }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, { "description": "a float is not a boolean", "data": 1.1, @@ -238,6 +248,11 @@ "data": "foo", "valid": false }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, { "description": "an object is not a boolean", "data": {}, @@ -249,10 +264,15 @@ "valid": false }, { - "description": "a boolean is a boolean", + "description": "true is a boolean", "data": true, "valid": true }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, { "description": "null is not a boolean", "data": null, @@ -274,11 +294,21 @@ "data": 1.1, "valid": false }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, { "description": "a string is not null", "data": "foo", "valid": false }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, { "description": "an object is not null", "data": {}, @@ -290,10 +320,15 @@ "valid": false }, { - "description": "a boolean is not null", + "description": "true is not null", "data": true, "valid": false }, + { + "description": "false is not null", + "data": false, + "valid": false + }, { "description": "null is null", "data": null, @@ -341,5 +376,89 @@ "valid": false } ] + }, + { + "description": "type as array with one item", + "schema": { + "type": ["string"] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "type": ["array", "object"] + }, + "tests": [ + { + "description": "array is valid", + "data": [1,2,3], + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": 123}, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "type": ["array", "object", "null"] + }, + "tests": [ + { + "description": "array is valid", + "data": [1,2,3], + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": 123}, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] } ]