From de84a59c5c5d80b93b89903c494df0334f8ab091 Mon Sep 17 00:00:00 2001 From: DrGFreeman Date: Tue, 2 Nov 2021 23:02:35 -0400 Subject: [PATCH 1/2] Add and modify uniqueItems tests Improve uniqueItems tests to ensure validators verify all elements of arrays: - Use more than two items in the test arrays. - Set the first and last items as non-unique where applicable. - Add tests for arrays of unique and non-unique strings. --- tests/draft-next/uniqueItems.json | 16 +++++++++++++--- tests/draft2019-09/uniqueItems.json | 16 +++++++++++++--- tests/draft2020-12/uniqueItems.json | 16 +++++++++++++--- tests/draft3/uniqueItems.json | 16 +++++++++++++--- tests/draft4/uniqueItems.json | 16 +++++++++++++--- tests/draft6/uniqueItems.json | 16 +++++++++++++--- tests/draft7/uniqueItems.json | 16 +++++++++++++--- 7 files changed, 91 insertions(+), 21 deletions(-) diff --git a/tests/draft-next/uniqueItems.json b/tests/draft-next/uniqueItems.json index b3762cbf..e7fbc619 100644 --- a/tests/draft-next/uniqueItems.json +++ b/tests/draft-next/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -28,6 +28,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -61,7 +71,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { diff --git a/tests/draft2019-09/uniqueItems.json b/tests/draft2019-09/uniqueItems.json index 4846c773..4458b6e5 100644 --- a/tests/draft2019-09/uniqueItems.json +++ b/tests/draft2019-09/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -28,6 +28,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -61,7 +71,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { diff --git a/tests/draft2020-12/uniqueItems.json b/tests/draft2020-12/uniqueItems.json index b3762cbf..e7fbc619 100644 --- a/tests/draft2020-12/uniqueItems.json +++ b/tests/draft2020-12/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -28,6 +28,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -61,7 +71,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { diff --git a/tests/draft3/uniqueItems.json b/tests/draft3/uniqueItems.json index fd4b8497..db6d0318 100644 --- a/tests/draft3/uniqueItems.json +++ b/tests/draft3/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -18,6 +18,16 @@ "data": [1.0, 1.00, 1], "valid": false }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -51,7 +61,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { diff --git a/tests/draft4/uniqueItems.json b/tests/draft4/uniqueItems.json index 4846c773..4458b6e5 100644 --- a/tests/draft4/uniqueItems.json +++ b/tests/draft4/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -28,6 +28,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -61,7 +71,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { diff --git a/tests/draft6/uniqueItems.json b/tests/draft6/uniqueItems.json index 4846c773..4458b6e5 100644 --- a/tests/draft6/uniqueItems.json +++ b/tests/draft6/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -28,6 +28,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -61,7 +71,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { diff --git a/tests/draft7/uniqueItems.json b/tests/draft7/uniqueItems.json index 4846c773..4458b6e5 100644 --- a/tests/draft7/uniqueItems.json +++ b/tests/draft7/uniqueItems.json @@ -5,12 +5,12 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2], + "data": [1, 2, 3], "valid": true }, { "description": "non-unique array of integers is invalid", - "data": [1, 1], + "data": [1, 2, 1], "valid": false }, { @@ -28,6 +28,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -61,7 +71,7 @@ }, { "description": "non-unique array of arrays is invalid", - "data": [["foo"], ["foo"]], + "data": [["foo"], ["bar"], ["foo"]], "valid": false }, { From 2c53688862574475b858f000802f768b6c19f903 Mon Sep 17 00:00:00 2001 From: DrGFreeman Date: Wed, 3 Nov 2021 18:29:57 -0400 Subject: [PATCH 2/2] Add tests instead of modifying existing tests --- tests/draft-next/uniqueItems.json | 12 +++++++++++- tests/draft2019-09/uniqueItems.json | 12 +++++++++++- tests/draft2020-12/uniqueItems.json | 12 +++++++++++- tests/draft3/uniqueItems.json | 12 +++++++++++- tests/draft4/uniqueItems.json | 12 +++++++++++- tests/draft6/uniqueItems.json | 12 +++++++++++- tests/draft7/uniqueItems.json | 12 +++++++++++- 7 files changed, 77 insertions(+), 7 deletions(-) diff --git a/tests/draft-next/uniqueItems.json b/tests/draft-next/uniqueItems.json index e7fbc619..85c619d9 100644 --- a/tests/draft-next/uniqueItems.json +++ b/tests/draft-next/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -71,6 +76,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false }, diff --git a/tests/draft2019-09/uniqueItems.json b/tests/draft2019-09/uniqueItems.json index 4458b6e5..2ccf666d 100644 --- a/tests/draft2019-09/uniqueItems.json +++ b/tests/draft2019-09/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -71,6 +76,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false }, diff --git a/tests/draft2020-12/uniqueItems.json b/tests/draft2020-12/uniqueItems.json index e7fbc619..85c619d9 100644 --- a/tests/draft2020-12/uniqueItems.json +++ b/tests/draft2020-12/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -71,6 +76,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false }, diff --git a/tests/draft3/uniqueItems.json b/tests/draft3/uniqueItems.json index db6d0318..c48c6a06 100644 --- a/tests/draft3/uniqueItems.json +++ b/tests/draft3/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -61,6 +66,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false }, diff --git a/tests/draft4/uniqueItems.json b/tests/draft4/uniqueItems.json index 4458b6e5..2ccf666d 100644 --- a/tests/draft4/uniqueItems.json +++ b/tests/draft4/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -71,6 +76,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false }, diff --git a/tests/draft6/uniqueItems.json b/tests/draft6/uniqueItems.json index 4458b6e5..2ccf666d 100644 --- a/tests/draft6/uniqueItems.json +++ b/tests/draft6/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -71,6 +76,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false }, diff --git a/tests/draft7/uniqueItems.json b/tests/draft7/uniqueItems.json index 4458b6e5..2ccf666d 100644 --- a/tests/draft7/uniqueItems.json +++ b/tests/draft7/uniqueItems.json @@ -5,11 +5,16 @@ "tests": [ { "description": "unique array of integers is valid", - "data": [1, 2, 3], + "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", "data": [1, 2, 1], "valid": false }, @@ -71,6 +76,11 @@ }, { "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", "data": [["foo"], ["bar"], ["foo"]], "valid": false },