From bd13fcf731544fb8b4340e1059030cb2ecbe308b Mon Sep 17 00:00:00 2001 From: Shristibot Date: Sat, 13 Dec 2025 01:40:34 +0530 Subject: [PATCH 1/4] 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 510a0e0a..131f22de 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/4] 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 131f22de..b680f3ac 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/4] 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 b680f3ac..90618469 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/4] 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 90618469..8b965f17 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 1c35d7e6..acdfc3d0 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 284e9191..7a4a92ca 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 + } + ] + } ]