Skip to content

Commit b255d27

Browse files
committed
Add tests for ignoring irrelevant types.
1 parent 71a0d30 commit b255d27

13 files changed

+122
-57
lines changed

tests/draft3/additionalItems.json

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
"items defaults to empty schema so everything is valid",
6161
"data": [ 1, 2, 3, 4, 5 ],
6262
"valid": true
63+
},
64+
{
65+
"description": "ignores non-arrays",
66+
"data": {"foo" : "bar"},
67+
"valid": true
6368
}
6469
]
6570
},

tests/draft3/additionalProperties.json

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"description": "an additional property is invalid",
1717
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
1818
"valid": false
19+
},
20+
{
21+
"description": "ignores non-objects",
22+
"data": [1, 2, 3],
23+
"valid": true
1924
}
2025
]
2126
},

tests/draft3/dependencies.json

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"description": "missing dependency",
2525
"data": {"bar": 2},
2626
"valid": false
27+
},
28+
{
29+
"description": "ignores non-objects",
30+
"data": "foo",
31+
"valid": true
2732
}
2833
]
2934
},

tests/draft3/divisibleBy.json

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
[
22
{
3-
"description": "by number",
4-
"schema": {"divisibleBy": 1.5},
3+
"description": "by int",
4+
"schema": {"divisibleBy": 2},
55
"tests": [
66
{
7-
"description": "zero is divisible by anything (except 0)",
8-
"data": 0,
7+
"description": "int by int",
8+
"data": 10,
99
"valid": true
1010
},
1111
{
12-
"description": "4.5 is divisible by 1.5",
13-
"data": 4.5,
14-
"valid": true
12+
"description": "int by int fail",
13+
"data": 7,
14+
"valid": false
1515
},
1616
{
17-
"description": "35 is not divisible by 1.5",
18-
"data": 35,
19-
"valid": false
17+
"description": "ignores non-numbers",
18+
"data": "foo",
19+
"valid": true
2020
}
2121
]
2222
},
2323
{
24-
"description": "by int",
25-
"schema": {"divisibleBy": 2},
24+
"description": "by number",
25+
"schema": {"divisibleBy": 1.5},
2626
"tests": [
2727
{
28-
"description": "int by int",
29-
"data": 10,
28+
"description": "zero is divisible by anything (except 0)",
29+
"data": 0,
3030
"valid": true
3131
},
3232
{
33-
"description": "int by int fail",
34-
"data": 7,
33+
"description": "4.5 is divisible by 1.5",
34+
"data": 4.5,
35+
"valid": true
36+
},
37+
{
38+
"description": "35 is not divisible by 1.5",
39+
"data": 35,
3540
"valid": false
3641
}
3742
]

tests/draft3/items.json

+46-41
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
[
2-
{
3-
"description": "a schema given for items",
4-
"schema": {
5-
"items": {"type": "integer"}
6-
},
7-
"tests": [
8-
{
9-
"description": "valid items",
10-
"data": [ 1, 2, 3 ],
11-
"valid": true
12-
},
13-
{
14-
"description": "wrong type of items",
15-
"data": [1, "x"],
16-
"valid": false
17-
}
18-
]
19-
},
20-
{
21-
"description": "an array of schemas for items",
22-
"schema": {
23-
"items": [
24-
{"type": "integer"},
25-
{"type": "string"}
26-
]
27-
},
28-
"tests": [
29-
{
30-
"description": "correct types",
31-
"data": [ 1, "foo" ],
32-
"valid": true
33-
},
34-
{
35-
"description": "wrong types",
36-
"data": [ "foo", 1 ],
37-
"valid": false
38-
}
39-
]
40-
}
41-
]
1+
[
2+
{
3+
"description": "a schema given for items",
4+
"schema": {
5+
"items": {"type": "integer"}
6+
},
7+
"tests": [
8+
{
9+
"description": "valid items",
10+
"data": [ 1, 2, 3 ],
11+
"valid": true
12+
},
13+
{
14+
"description": "wrong type of items",
15+
"data": [1, "x"],
16+
"valid": false
17+
},
18+
{
19+
"description": "ignores non-arrays",
20+
"data": {"foo" : "bar"},
21+
"valid": true
22+
}
23+
]
24+
},
25+
{
26+
"description": "an array of schemas for items",
27+
"schema": {
28+
"items": [
29+
{"type": "integer"},
30+
{"type": "string"}
31+
]
32+
},
33+
"tests": [
34+
{
35+
"description": "correct types",
36+
"data": [ 1, "foo" ],
37+
"valid": true
38+
},
39+
{
40+
"description": "wrong types",
41+
"data": [ "foo", 1 ],
42+
"valid": false
43+
}
44+
]
45+
}
46+
]

tests/draft3/maxItems.json

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"description": "too long is invalid",
1818
"data": [1, 2, 3],
1919
"valid": false
20+
},
21+
{
22+
"description": "ignores non-arrays",
23+
"data": "foobar",
24+
"valid": true
2025
}
2126
]
2227
}

tests/draft3/maxLength.json

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"description": "too long is invalid",
1818
"data": "foo",
1919
"valid": false
20+
},
21+
{
22+
"description": "ignores non-strings",
23+
"data": 10,
24+
"valid": true
2025
}
2126
]
2227
}

tests/draft3/maximum.json

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"description": "above the maximum is invalid",
1313
"data": 3.5,
1414
"valid": false
15+
},
16+
{
17+
"description": "ignores non-numbers",
18+
"data": "x",
19+
"valid": true
1520
}
1621
]
1722
},

tests/draft3/minItems.json

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"description": "too short is invalid",
1818
"data": [],
1919
"valid": false
20+
},
21+
{
22+
"description": "ignores non-arrays",
23+
"data": "",
24+
"valid": true
2025
}
2126
]
2227
}

tests/draft3/minLength.json

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"description": "too short is invalid",
1818
"data": "f",
1919
"valid": false
20+
},
21+
{
22+
"description": "ignores non-strings",
23+
"data": 1,
24+
"valid": true
2025
}
2126
]
2227
}

tests/draft3/minimum.json

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"description": "below the minimum is invalid",
1313
"data": 0.6,
1414
"valid": false
15+
},
16+
{
17+
"description": "ignores non-numbers",
18+
"data": "x",
19+
"valid": true
1520
}
1621
]
1722
},

tests/draft3/pattern.json

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"description": "a non-matching pattern is invalid",
1313
"data": "abc",
1414
"valid": false
15+
},
16+
{
17+
"description": "ignores non-strings",
18+
"data": true,
19+
"valid": true
1520
}
1621
]
1722
}

tests/draft3/properties.json

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
"description": "doesn't invalidate other properties",
2828
"data": {"quux": []},
2929
"valid": true
30+
},
31+
{
32+
"description": "ignores non-objects",
33+
"data": [],
34+
"valid": true
3035
}
3136
]
3237
},

0 commit comments

Comments
 (0)