Skip to content

Commit 23ff275

Browse files
Fix incorrect test condition, simplify test, and copy tests to all drafts as requested
1 parent ccfb91a commit 23ff275

File tree

3 files changed

+124
-13
lines changed

3 files changed

+124
-13
lines changed

tests/draft2019-09/if-then-else.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,19 @@
287287
{
288288
"description": "else: false fails when condition does not match",
289289
"schema": {
290-
"if": {
291-
"properties":{
292-
"name":{"type":"string"}
293-
},
294-
"required": ["name"]
295-
},
290+
"if": { "const": 1 },
296291
"else": false
297292
},
298293
"tests": [
294+
{
295+
"description": "matches if → else ignored → valid",
296+
"data": 1,
297+
"valid": true
298+
},
299299
{
300300
"description": "does not match if → else executes → invalid",
301301
"data": 2,
302302
"valid": false
303-
},
304-
{
305-
"description": "matches if → else does not execute → valid",
306-
"data":{"name":"foo"},
307-
"valid":true
308303
}
309304
]
310305
},

tests/draft2020-12/if-then-else.json

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,63 @@
264264
"valid": false
265265
}
266266
]
267-
}
267+
},
268+
{
269+
"description": "then: false fails when condition matches",
270+
"schema": {
271+
"if": { "const": 1 },
272+
"then": false
273+
},
274+
"tests": [
275+
{
276+
"description": "matches if → then=false → invalid",
277+
"data": 1,
278+
"valid": false
279+
},
280+
{
281+
"description": "does not match if → then ignored → valid",
282+
"data": 2,
283+
"valid": true
284+
}
285+
]
286+
},
287+
{
288+
"description": "else: false fails when condition does not match",
289+
"schema": {
290+
"if": { "const": 1 },
291+
"else": false
292+
},
293+
"tests": [
294+
{
295+
"description": "matches if → else ignored → valid",
296+
"data": 1,
297+
"valid": true
298+
},
299+
{
300+
"description": "does not match if → else executes → invalid",
301+
"data": 2,
302+
"valid": false
303+
}
304+
]
305+
},
306+
{
307+
"description": "then and else both are false",
308+
"schema":{
309+
"if":{"type":"number"},
310+
"then":false,
311+
"else":false
312+
},
313+
"tests":[
314+
{
315+
"description": "matches if → then executes and else does not execute → invalid",
316+
"data": 4,
317+
"valid": false
318+
},
319+
{
320+
"description": "does not match if → else executes → invalid",
321+
"data": "foo",
322+
"valid": false
323+
}
324+
]
325+
}
268326
]

tests/draft7/if-then-else.json

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,63 @@
254254
"valid": false
255255
}
256256
]
257-
}
257+
},
258+
{
259+
"description": "then: false fails when condition matches",
260+
"schema": {
261+
"if": { "const": 1 },
262+
"then": false
263+
},
264+
"tests": [
265+
{
266+
"description": "matches if → then=false → invalid",
267+
"data": 1,
268+
"valid": false
269+
},
270+
{
271+
"description": "does not match if → then ignored → valid",
272+
"data": 2,
273+
"valid": true
274+
}
275+
]
276+
},
277+
{
278+
"description": "else: false fails when condition does not match",
279+
"schema": {
280+
"if": { "const": 1 },
281+
"else": false
282+
},
283+
"tests": [
284+
{
285+
"description": "matches if → else ignored → valid",
286+
"data": 1,
287+
"valid": true
288+
},
289+
{
290+
"description": "does not match if → else executes → invalid",
291+
"data": 2,
292+
"valid": false
293+
}
294+
]
295+
},
296+
{
297+
"description": "then and else both are false",
298+
"schema":{
299+
"if":{"type":"number"},
300+
"then":false,
301+
"else":false
302+
},
303+
"tests":[
304+
{
305+
"description": "matches if → then executes and else does not execute → invalid",
306+
"data": 4,
307+
"valid": false
308+
},
309+
{
310+
"description": "does not match if → else executes → invalid",
311+
"data": "foo",
312+
"valid": false
313+
}
314+
]
315+
}
258316
]

0 commit comments

Comments
 (0)