Skip to content

Commit e6a270f

Browse files
committed
Properties.
1 parent 2192a63 commit e6a270f

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[
2+
{
3+
"description":
4+
"additionalProperties being false does not allow other properties",
5+
"schema": {
6+
"properties": {"foo": {}, "bar": {}},
7+
"additionalProperties": false
8+
},
9+
"tests": [
10+
{
11+
"description": "no additional properties is valid",
12+
"data": {"foo": 1},
13+
"valid": true
14+
},
15+
{
16+
"description": "an additional property is invalid",
17+
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
18+
"valid": false
19+
},
20+
]
21+
},
22+
{
23+
"description":
24+
"additionalProperties allows a schema which should validate",
25+
"schema": {
26+
"properties": {"foo": {}, "bar": {}},
27+
"additionalProperties": {"type": "boolean"},
28+
},
29+
"tests": [
30+
{
31+
"description": "no additional properties is valid",
32+
"data": {"foo": 1},
33+
"valid": true
34+
},
35+
{
36+
"description": "an additional valid property is valid",
37+
"data": {"foo" : 1, "bar" : 2, "quux" : true},
38+
"valid": true
39+
},
40+
{
41+
"description": "an additional invalid property is invalid",
42+
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
43+
"valid": false
44+
}
45+
]
46+
}
47+
{
48+
"description": "additionalProperties are allowed by default",
49+
"schema": {"properties": {"foo": {}, "bar": {}}},
50+
"tests": [
51+
{
52+
"description": "additional properties are allowed",
53+
"data": {"foo": 1, "bar": 2, "quux": true},
54+
"valid": true
55+
}
56+
]
57+
}
58+
]

tests/draft3/patternProperties.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"description":
4+
"patternProperties validates properties matching a regex",
5+
"schema": {
6+
"patternProperties": {
7+
"f.*o": {"type": "integer"}
8+
}
9+
},
10+
"tests": [
11+
{
12+
"description": "a single valid match is valid",
13+
"data": {"foo": 1},
14+
"valid": true
15+
},
16+
{
17+
"description": "multiple valid matches is valid",
18+
"data": {"foo": 1, "foooooo" : 2},
19+
"valid": true
20+
},
21+
{
22+
"description": "a single invalid match is invalid",
23+
"data": {"foo": "bar", "fooooo", 2},
24+
"valid": false
25+
},
26+
{
27+
"description": "multiple invalid matches is invalid",
28+
"data": {"foo": "bar", "foooooo" : "baz"},
29+
"valid": false
30+
},
31+
]
32+
},
33+
{
34+
"description": "multiple simulatneous patternProperties are validated",
35+
"schema": {
36+
"patternProperties": {
37+
"a*": {"type": "integer"},
38+
"aaa*": {"maximum": 20}
39+
}
40+
},
41+
"tests": [
42+
{
43+
"description": "a single valid match is valid",
44+
"data": {"a": 21},
45+
"valid": true
46+
},
47+
{
48+
"description": "a simultaneous match is valid",
49+
"data": {"aaaa": 18},
50+
"valid": true
51+
},
52+
{
53+
"description": "multiple matches is valid",
54+
"data": {"a": 21, "aaaa": 18},
55+
"valid": true
56+
},
57+
{
58+
"description": "an invalid due to one is invalid",
59+
"data": {"a": "bar"},
60+
"valid": false
61+
},
62+
{
63+
"description": "an invalid due to the other is invalid",
64+
"data": {"aaaa": 31},
65+
"valid": false
66+
},
67+
{
68+
"description": "an invalid due to both is invalid",
69+
"data": {"aaa": "foo", "aaaa": 31},
70+
"valid": false
71+
}
72+
]
73+
}
74+
]

tests/draft3/properties.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"description": "object properties validation",
4+
"schema": {
5+
"properties": {
6+
"foo": {"type": "integer"},
7+
"bar": {"type": "string"}
8+
}
9+
},
10+
"tests": [
11+
{
12+
"description": "both properties present and valid is valid",
13+
"data": {"foo": 1, "bar": "baz"},
14+
"valid": true
15+
},
16+
{
17+
"description": "one property invalid is invalid",
18+
"data": {"foo": 1, "bar": {}},
19+
"valid": false
20+
},
21+
{
22+
"description": "both properties invalid is invalid",
23+
"data": {"foo": [], "bar": {}},
24+
"valid": false
25+
},
26+
{
27+
"description": "doesn't invalidate other properties",
28+
"data": {"quux": []},
29+
"valid": true
30+
}
31+
]
32+
}
33+
]

0 commit comments

Comments
 (0)