Skip to content

Commit

Permalink
Merge pull request #60 from glyn/nondeterminism
Browse files Browse the repository at this point in the history
Introduce some tests of non-determinism
  • Loading branch information
gregsdennis authored Mar 1, 2024
2 parents 446336c + 8523282 commit a74462d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
52 changes: 46 additions & 6 deletions cts.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@
"a": "A",
"b": "B"
},
"result": [
"A",
"B"
"results": [
[
"A",
"B"
],
[
"B",
"A"
]
]
},
{
Expand Down Expand Up @@ -135,9 +141,15 @@
"b": "By"
}
},
"result": [
"Ax",
"Ay"
"results": [
[
"Ax",
"Ay"
],
[
"Ay",
"Ax"
]
]
},
{
Expand Down Expand Up @@ -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": "$..",
Expand Down
32 changes: 30 additions & 2 deletions cts.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"result": {
"$ref": "#/$defs/test_case_result"
},
"results": {
"$ref": "#/$defs/test_case_results"
},
"invalid_selector": {
"$ref": "#/$defs/invalid_selector"
}
Expand All @@ -45,12 +48,31 @@
"required": [
"document",
"result"
]
],
"properties": {
"invalid_selector": false,
"results": false
}
},
{
"required": [
"document",
"results"
],
"properties": {
"invalid_selector": false,
"result": false
}
},
{
"required": [
"invalid_selector"
]
],
"properties": {
"document": false,
"result": false,
"results": false
}
}
]
},
Expand All @@ -63,6 +85,12 @@
"type": "array",
"description": "The expected result of applying the selector to the document, contains all the matched values"
},
"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": {
"description": "The JSONPath selector",
"type": "string"
Expand Down
30 changes: 26 additions & 4 deletions tests/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@
"a": "A",
"b": "B"
},
"result": [
"results": [[
"A",
"B"
]
],[
"B",
"A"
]]
},
{
"name": "wildcard shorthand, array data",
Expand Down Expand Up @@ -134,10 +137,13 @@
"b": "By"
}
},
"result": [
"results": [[
"Ax",
"Ay"
]
],[
"Ay",
"Ax"
]]
},
{
"name": "multiple selectors",
Expand Down Expand Up @@ -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": "$..",
Expand Down

0 comments on commit a74462d

Please sign in to comment.