From bd13fcf731544fb8b4340e1059030cb2ecbe308b Mon Sep 17 00:00:00 2001 From: Shristibot Date: Sat, 13 Dec 2025 01:40:34 +0530 Subject: [PATCH 1/5] Add if/then/else test cases for issue #767 --- tests/draft2019-09/if-then-else.json | 66 +++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/tests/draft2019-09/if-then-else.json b/tests/draft2019-09/if-then-else.json index 510a0e0ac..131f22de7 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -264,5 +264,69 @@ "valid": false } ] - } + }, + { + "description": "then: false should fail if condition matches", + "schema": { + "if": { "const": 1 }, + "then": false + }, + "tests": [ + { + "description": "matches if → then=false → invalid", + "data": 1, + "valid": false + }, + { + "description": "does not match if → then ignored → valid", + "data": 2, + "valid": true + } + ] + }, + { + "description": "else: false should fail when if condition does not match", + "schema": { + "if": { + "properties":{ + "name":{"type":"string"} + }, + "required": ["name"] + }, + "else": false + }, + "tests": [ + { + "description": "does not match if → else executes → invalid", + "data": 2, + "valid": false + }, + { + "description": "matches if → else does not execute → valid", + "data":{"name":"foo"}, + "valid":true + } + ] + }, + { + "description": "then and else both are false", + "schema":{ + "if":{"type":"number"}, + "then":false, + "else":false + }, + "tests":[ + { + "description": "matches if → then executes and else does not execute →invalid", + "data": 4, + "valid": false + }, + { + "description": "does not match if → else executes →invalid", + "data": "foo", + "valid": false + } + ] + } ] + From bc1763ed847988f99e1444ede1d744db8edbb4f7 Mon Sep 17 00:00:00 2001 From: Shristibot Date: Sat, 13 Dec 2025 02:02:48 +0530 Subject: [PATCH 2/5] Fix description formatting in false-handling tests --- tests/draft2019-09/if-then-else.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/draft2019-09/if-then-else.json b/tests/draft2019-09/if-then-else.json index 131f22de7..b680f3ac2 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -317,12 +317,12 @@ }, "tests":[ { - "description": "matches if → then executes and else does not execute →invalid", + "description": "matches if → then executes and else does not execute → invalid", "data": 4, "valid": false }, { - "description": "does not match if → else executes →invalid", + "description": "does not match if → else executes → invalid", "data": "foo", "valid": false } From ccfb91af2481c56ffc5bb0a7059a195cf3c76845 Mon Sep 17 00:00:00 2001 From: Shristibot Date: Sat, 13 Dec 2025 02:17:29 +0530 Subject: [PATCH 3/5] Fix description style and add false-handling tests for issue #767 --- tests/draft2019-09/if-then-else.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/draft2019-09/if-then-else.json b/tests/draft2019-09/if-then-else.json index b680f3ac2..90618469b 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -266,7 +266,7 @@ ] }, { - "description": "then: false should fail if condition matches", + "description": "then: false fails when condition matches", "schema": { "if": { "const": 1 }, "then": false @@ -285,7 +285,7 @@ ] }, { - "description": "else: false should fail when if condition does not match", + "description": "else: false fails when condition does not match", "schema": { "if": { "properties":{ From 23ff2750378dd2de48836333a0ce02f3f94feef7 Mon Sep 17 00:00:00 2001 From: Shristibot Date: Sat, 13 Dec 2025 02:31:30 +0530 Subject: [PATCH 4/5] Fix incorrect test condition, simplify test, and copy tests to all drafts as requested --- tests/draft2019-09/if-then-else.json | 17 +++----- tests/draft2020-12/if-then-else.json | 60 +++++++++++++++++++++++++++- tests/draft7/if-then-else.json | 60 +++++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 13 deletions(-) diff --git a/tests/draft2019-09/if-then-else.json b/tests/draft2019-09/if-then-else.json index 90618469b..8b965f17b 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -287,24 +287,19 @@ { "description": "else: false fails when condition does not match", "schema": { - "if": { - "properties":{ - "name":{"type":"string"} - }, - "required": ["name"] - }, + "if": { "const": 1 }, "else": false }, "tests": [ + { + "description": "matches if → else ignored → valid", + "data": 1, + "valid": true + }, { "description": "does not match if → else executes → invalid", "data": 2, "valid": false - }, - { - "description": "matches if → else does not execute → valid", - "data":{"name":"foo"}, - "valid":true } ] }, diff --git a/tests/draft2020-12/if-then-else.json b/tests/draft2020-12/if-then-else.json index 1c35d7e61..acdfc3d0b 100644 --- a/tests/draft2020-12/if-then-else.json +++ b/tests/draft2020-12/if-then-else.json @@ -264,5 +264,63 @@ "valid": false } ] - } + }, + { + "description": "then: false fails when condition matches", + "schema": { + "if": { "const": 1 }, + "then": false + }, + "tests": [ + { + "description": "matches if → then=false → invalid", + "data": 1, + "valid": false + }, + { + "description": "does not match if → then ignored → valid", + "data": 2, + "valid": true + } + ] + }, + { + "description": "else: false fails when condition does not match", + "schema": { + "if": { "const": 1 }, + "else": false + }, + "tests": [ + { + "description": "matches if → else ignored → valid", + "data": 1, + "valid": true + }, + { + "description": "does not match if → else executes → invalid", + "data": 2, + "valid": false + } + ] + }, + { + "description": "then and else both are false", + "schema":{ + "if":{"type":"number"}, + "then":false, + "else":false + }, + "tests":[ + { + "description": "matches if → then executes and else does not execute → invalid", + "data": 4, + "valid": false + }, + { + "description": "does not match if → else executes → invalid", + "data": "foo", + "valid": false + } + ] + } ] diff --git a/tests/draft7/if-then-else.json b/tests/draft7/if-then-else.json index 284e91912..7a4a92ca9 100644 --- a/tests/draft7/if-then-else.json +++ b/tests/draft7/if-then-else.json @@ -254,5 +254,63 @@ "valid": false } ] - } + }, + { + "description": "then: false fails when condition matches", + "schema": { + "if": { "const": 1 }, + "then": false + }, + "tests": [ + { + "description": "matches if → then=false → invalid", + "data": 1, + "valid": false + }, + { + "description": "does not match if → then ignored → valid", + "data": 2, + "valid": true + } + ] + }, + { + "description": "else: false fails when condition does not match", + "schema": { + "if": { "const": 1 }, + "else": false + }, + "tests": [ + { + "description": "matches if → else ignored → valid", + "data": 1, + "valid": true + }, + { + "description": "does not match if → else executes → invalid", + "data": 2, + "valid": false + } + ] + }, + { + "description": "then and else both are false", + "schema":{ + "if":{"type":"number"}, + "then":false, + "else":false + }, + "tests":[ + { + "description": "matches if → then executes and else does not execute → invalid", + "data": 4, + "valid": false + }, + { + "description": "does not match if → else executes → invalid", + "data": "foo", + "valid": false + } + ] + } ] From bef1e2ed77e802d7b2ac857e4df9a937f330e9a0 Mon Sep 17 00:00:00 2001 From: Shristibot Date: Thu, 25 Dec 2025 14:38:55 +0530 Subject: [PATCH 5/5] Remove redundant then/else false test cases --- tests/draft2019-09/if-then-else.json | 22 +--------------------- tests/draft2020-12/if-then-else.json | 22 +--------------------- tests/draft7/if-then-else.json | 22 +--------------------- 3 files changed, 3 insertions(+), 63 deletions(-) diff --git a/tests/draft2019-09/if-then-else.json b/tests/draft2019-09/if-then-else.json index 8b965f17b..2907ee081 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -302,26 +302,6 @@ "valid": false } ] - }, - { - "description": "then and else both are false", - "schema":{ - "if":{"type":"number"}, - "then":false, - "else":false - }, - "tests":[ - { - "description": "matches if → then executes and else does not execute → invalid", - "data": 4, - "valid": false - }, - { - "description": "does not match if → else executes → invalid", - "data": "foo", - "valid": false - } - ] - } + } ] diff --git a/tests/draft2020-12/if-then-else.json b/tests/draft2020-12/if-then-else.json index acdfc3d0b..ce76d7476 100644 --- a/tests/draft2020-12/if-then-else.json +++ b/tests/draft2020-12/if-then-else.json @@ -302,25 +302,5 @@ "valid": false } ] - }, - { - "description": "then and else both are false", - "schema":{ - "if":{"type":"number"}, - "then":false, - "else":false - }, - "tests":[ - { - "description": "matches if → then executes and else does not execute → invalid", - "data": 4, - "valid": false - }, - { - "description": "does not match if → else executes → invalid", - "data": "foo", - "valid": false - } - ] - } + } ] diff --git a/tests/draft7/if-then-else.json b/tests/draft7/if-then-else.json index 7a4a92ca9..a7302f1ef 100644 --- a/tests/draft7/if-then-else.json +++ b/tests/draft7/if-then-else.json @@ -292,25 +292,5 @@ "valid": false } ] - }, - { - "description": "then and else both are false", - "schema":{ - "if":{"type":"number"}, - "then":false, - "else":false - }, - "tests":[ - { - "description": "matches if → then executes and else does not execute → invalid", - "data": 4, - "valid": false - }, - { - "description": "does not match if → else executes → invalid", - "data": "foo", - "valid": false - } - ] - } + } ]