ajv/spec/tests/rules/uniqueItems.json

114 lines
2.9 KiB
JSON

[
{
"description": "uniqueItems with algorithm using hash",
"schema": {
"items": { "type": "string" },
"uniqueItems": true
},
"tests": [
{
"description": "array of unique strings is valid",
"data": ["foo", "bar", "baz"],
"valid": true
},
{
"description": "array of unique items with strings that are properties of hash is valid",
"data": ["toString", "foo"],
"valid": true
},
{
"description": "array of non-unique strings is invalid",
"data": ["foo", "bar", "bar"],
"valid": false
},
{
"description": "array with non-strings is invalid",
"data": ["1", 2],
"valid": false
}
]
},
{
"description": "uniqueItems with multiple types when the list of types includes array",
"schema": {
"items": { "type": ["array", "string"] },
"uniqueItems": true
},
"tests": [
{
"description": "array of unique items is valid",
"data": [[1], [2], "foo"],
"valid": true
},
{
"description": "array of non-unique items is invalid",
"data": [[1], [1], "foo"],
"valid": false
},
{
"description": "array with incorrect type is invalid",
"data": [{}, 1, 2],
"valid": false
}
]
},
{
"description": "uniqueItems with multiple types when the list of types includes object",
"schema": {
"items": { "type": ["object", "string"] },
"uniqueItems": true
},
"tests": [
{
"description": "array of unique items is valid",
"data": [{"a": 1}, {"b": 2}, "foo"],
"valid": true
},
{
"description": "array of non-unique items is invalid",
"data": [{"a": 1}, {"a": 1}, "foo"],
"valid": false
},
{
"description": "array with incorrect type is invalid",
"data": [[], 1, 2],
"valid": false
}
]
},
{
"description": "uniqueItems with multiple types when all types are scalar",
"schema": {
"items": { "type": ["number", "string", "boolean", "null"] },
"uniqueItems": true
},
"tests": [
{
"description": "array of unique items is valid (string/number)",
"data": ["1", 1, 2],
"valid": true
},
{
"description": "array of unique items is valid (string/boolean)",
"data": ["true", true, false],
"valid": true
},
{
"description": "array of unique items is valid (string/null)",
"data": ["null", null, 0],
"valid": true
},
{
"description": "array of non-unique items is invalid",
"data": [1, 1, 2],
"valid": false
},
{
"description": "array with incorrect type is invalid",
"data": [[], 1, 2],
"valid": false
}
]
}
]