Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce some tests of non-determinism #60

Merged
merged 8 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
},
gregsdennis marked this conversation as resolved.
Show resolved Hide resolved
"invalid_selector": {
"$ref": "#/$defs/invalid_selector"
}
Expand All @@ -45,12 +48,31 @@
"required": [
"document",
"result"
]
],
"properties": {
"invalid_selector": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregsdennis I took the liberty of tightening this up, even though it's not needed for the current PR.

"results": false
}
},
{
"required": [
"document",
"results"
],
"properties": {
"invalid_selector": false,
"result": false
}
},
{
"required": [
"invalid_selector"
]
],
"properties": {
"document": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregsdennis I took the liberty of tightening this up, even though it's not needed for the current PR.

"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",
gregsdennis marked this conversation as resolved.
Show resolved Hide resolved
"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
Loading