From 710613a176b44ccc047c9987b3c400d10c294dc7 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 05:59:17 +0000 Subject: [PATCH 1/8] Introduce some tests of non-determinism Ref https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/issues/9 --- cts.json | 52 ++++++++++++++++++++++++++++++++++++++++++------ tests/basic.json | 30 ++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/cts.json b/cts.json index 11af641..52b6d53 100644 --- a/cts.json +++ b/cts.json @@ -93,9 +93,15 @@ "a": "A", "b": "B" }, - "result": [ - "A", - "B" + "results": [ + [ + "A", + "B" + ], + [ + "B", + "A" + ] ] }, { @@ -135,9 +141,15 @@ "b": "By" } }, - "result": [ - "Ax", - "Ay" + "results": [ + [ + "Ax", + "Ay" + ], + [ + "Ay", + "Ax" + ] ] }, { @@ -464,6 +476,34 @@ "f" ] }, + { + "name": "basic, descendant segment, object traversal, multiple selectors", + "selector": "$..['a','d']", + "document": { + "x": { + "a": "b", + "d": "e" + }, + "y": { + "a": "c", + "d": "f" + } + }, + "results": [ + [ + "b", + "e", + "c", + "f" + ], + [ + "c", + "f", + "b", + "e" + ] + ] + }, { "name": "basic, bald descendant segment", "selector": "$..", diff --git a/tests/basic.json b/tests/basic.json index a21e966..dbfe7b2 100644 --- a/tests/basic.json +++ b/tests/basic.json @@ -92,10 +92,13 @@ "a": "A", "b": "B" }, - "result": [ + "results": [[ "A", "B" - ] + ],[ + "B", + "A" + ]] }, { "name": "wildcard shorthand, array data", @@ -134,10 +137,13 @@ "b": "By" } }, - "result": [ + "results": [[ "Ax", "Ay" - ] + ],[ + "Ay", + "Ax" + ]] }, { "name": "multiple selectors", @@ -424,6 +430,22 @@ "f" ] }, + { + "name": "descendant segment, object traversal, multiple selectors", + "selector" : "$..['a','d']", + "document" : {"x": {"a": "b", "d": "e"}, "y": {"a":"c", "d": "f"}}, + "results": [[ + "b", + "e", + "c", + "f" + ],[ + "c", + "f", + "b", + "e" + ]] + }, { "name": "bald descendant segment", "selector": "$..", From a91b94d9f7032e9ac7df3e491fd9e0be13eeefcb Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 06:07:22 +0000 Subject: [PATCH 2/8] Add non-determinism to schema --- cts.schema.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cts.schema.json b/cts.schema.json index b32dc26..c10693c 100644 --- a/cts.schema.json +++ b/cts.schema.json @@ -32,6 +32,9 @@ "result": { "$ref": "#/$defs/test_case_result" }, + "results": { + "$ref": "#/$defs/test_case_results" + }, "invalid_selector": { "$ref": "#/$defs/invalid_selector" } @@ -63,6 +66,10 @@ "type": "array", "description": "The expected result of applying the selector to the document, contains all the matched values" }, + "test_case_results": { + "type": "array", + "description": "An array of possible expected results of applying the selector to the document, each element of which contains all the matched values" + }, "selector": { "description": "The JSONPath selector", "type": "string" From 05b19a82bf3753856de32f1e3f47429dae0a45a3 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 06:09:22 +0000 Subject: [PATCH 3/8] Fix schema constraints --- cts.schema.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cts.schema.json b/cts.schema.json index c10693c..7d05bc3 100644 --- a/cts.schema.json +++ b/cts.schema.json @@ -50,6 +50,12 @@ "result" ] }, + { + "required": [ + "document", + "results" + ] + }, { "required": [ "invalid_selector" From d8e2a499a2581109653ac52e01e7dededcd7f509 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 07:55:02 +0000 Subject: [PATCH 4/8] Limit the type of "results" It needs to be an array of arrays with at least two elements. This will help diagnose the likely mistake of using "results" instead of "result", since it should be fairly unusual for the results of a query to be an array of two or more arrays. --- cts.schema.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cts.schema.json b/cts.schema.json index 7d05bc3..1f57c9d 100644 --- a/cts.schema.json +++ b/cts.schema.json @@ -74,6 +74,8 @@ }, "test_case_results": { "type": "array", + "items": {"$ref": "#/$defs/test_case_result"}, + "minItems": 2, "description": "An array of possible expected results of applying the selector to the document, each element of which contains all the matched values" }, "selector": { From 6034b3fcdde88de7614bdb41e26208e39ed2222f Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 08:07:23 +0000 Subject: [PATCH 5/8] Mention non-determinism in the README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c428fe1..358656e 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,7 @@ Many editors support that file natively. Others (such as VS code) require a plug To add or modify a test suite, edit the corresponding file in the `tests` directory. To generate `cts.json`, run the `build.sh` located in the root folder. Do not modify `cts.json` directly. More details are available in the [Contributor Guide](./CONTRIBUTING.md). + +### Non-determinism + +Where the spec allows non-deterministic results for a given testcase, the testcase should specify an array of all the valid results (each of which is itself an array representing the resultant nodelist from the query) in the "results" member (and should not specify a "result" member). \ No newline at end of file From 389a233690dbf5f02b218156bb4915c4419cb579 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 08:16:28 +0000 Subject: [PATCH 6/8] "results" and "result" are mutually exclusive --- cts.schema.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cts.schema.json b/cts.schema.json index 1f57c9d..b8885e6 100644 --- a/cts.schema.json +++ b/cts.schema.json @@ -48,13 +48,19 @@ "required": [ "document", "result" - ] + ], + "properties": { + "results": false + } }, { "required": [ "document", "results" - ] + ], + "properties": { + "result": false + } }, { "required": [ From 6106a29bbc4fa9dbe8bda47572ddb9fa9bfd1fc1 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 08:24:54 +0000 Subject: [PATCH 7/8] Add more constraints to the schema --- cts.schema.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cts.schema.json b/cts.schema.json index b8885e6..b297ab9 100644 --- a/cts.schema.json +++ b/cts.schema.json @@ -50,6 +50,7 @@ "result" ], "properties": { + "invalid_selector": false, "results": false } }, @@ -59,13 +60,20 @@ "results" ], "properties": { + "invalid_selector": false, "result": false } }, { "required": [ + "name", "invalid_selector" - ] + ], + "properties": { + "document": false, + "result": false, + "results": false + } } ] }, From 8523282c8eda9678543c50729289323b46385aae Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 29 Feb 2024 08:27:33 +0000 Subject: [PATCH 8/8] Delete unnecessary constraint "name" is already required --- cts.schema.json | 1 - 1 file changed, 1 deletion(-) diff --git a/cts.schema.json b/cts.schema.json index b297ab9..7b3ad9b 100644 --- a/cts.schema.json +++ b/cts.schema.json @@ -66,7 +66,6 @@ }, { "required": [ - "name", "invalid_selector" ], "properties": {