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

Add tests for incorrect filter usage #56

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
73 changes: 73 additions & 0 deletions cts.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,26 @@
}
]
},
{
"name": "filter, existence without selector",
"selector": "$[?@]",
"document": {
"a": {},
"b": 1
},
"result": [
{},
1
]
},
{
"name": "filter, existence test on primitive (not supported)",
Marcono1234 marked this conversation as resolved.
Show resolved Hide resolved
"selector": "$.a[?@]",
"document": {
"a": 1
},
"result": []
},
{
"name": "filter, equals string, single quotes",
"selector": "$[?@.a=='b']",
Expand Down Expand Up @@ -1844,6 +1864,43 @@
]
]
},
{
"name": "filter, on primitive (not supported)",
Marcono1234 marked this conversation as resolved.
Show resolved Hide resolved
"selector": "$.a[?@ == 1]",
"document": {
"a": 1
},
"result": []
},
{
"name": "filter, on primitive object member value (@ refers to member values, not the object)",
"selector": "$[?@.a == 1]",
"document": {
"a": 1
},
"result": []
},
{
"name": "filter, name selector on array",
"selector": "$[?@[\"0\"] == 5]",
Marcono1234 marked this conversation as resolved.
Show resolved Hide resolved
"document": [
[
5,
6
]
],
"result": []
},
{
"name": "filter, index selector on object",
"selector": "$[?@[0] == 5]",
"document": [
{
"0": 5
}
],
"result": []
},
{
"name": "filter, relative non-singular query, index, equal",
"selector": "$[?(@[0, 0]==42)]",
Expand Down Expand Up @@ -4096,6 +4153,22 @@
],
"result": []
},
{
"name": "functions, length, filter on primitive array element (@ refers to array elements, not the array)",
"selector": "$[?length(@)==1]",
Copy link
Contributor

Choose a reason for hiding this comment

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

This test could be made broader, thus:

Suggested change
"selector": "$[?length(@)==1]",
"selector": "$[?length(@)>=0]",

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it would be good to add a test for the comparison of two Nothing values if we don't already, e.g.:

$[?length(@)==length(@)]

should select all the elements of an array argument.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

@glyn I think these changes are moot given the conversation I've raised. What these tests are trying to verify can be accomplished with several more targeted tests.

"document": [
1
],
"result": []
},
{
"name": "functions, length, filter on primitive object member value (@ refers to member values, not the object)",
"selector": "$[?length(@)==1]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"selector": "$[?length(@)==1]",
"selector": "$[?length(@)>=0]",

"document": {
"a": 1
},
"result": []
},
{
"name": "functions, length, result must be compared",
"selector": "$[?length(@.a)]",
Expand Down
36 changes: 36 additions & 0 deletions tests/filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
{"a": null, "d": "e"}
]
},
{
"name": "existence without selector",
"selector": "$[?@]",
"document": {"a": {}, "b": 1},
"result": [{}, 1]
},
{
"name": "existence test on primitive (not supported)",
"selector": "$.a[?@]",
"document": {"a": 1},
"result": []
},
{
"name": "equals string, single quotes",
"selector" : "$[?@.a=='b']",
Expand Down Expand Up @@ -478,6 +490,30 @@
[42]
]
},
{
"name": "on primitive (not supported)",
"selector": "$.a[?@ == 1]",
"document": {"a": 1},
"result": []
},
{
"name": "on primitive object member value (@ refers to member values, not the object)",
"selector": "$[?@.a == 1]",
"document": {"a": 1},
"result": []
},
{
"name": "name selector on array",
"selector": "$[?@[\"0\"] == 5]",
"document": [[5, 6]],
"result": []
},
{
"name": "index selector on object",
"selector": "$[?@[0] == 5]",
"document": [{"0": 5}],
"result": []
},
{
"name": "relative non-singular query, index, equal",
"selector": "$[?(@[0, 0]==42)]",
Expand Down
12 changes: 12 additions & 0 deletions tests/functions/length.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
"document" : [{"d": "f"}],
"result": []
},
{
"name": "filter on primitive array element (@ refers to array elements, not the array)",
"selector": "$[?length(@)==1]",
"document": [1],
"result": []
},
{
"name": "filter on primitive object member value (@ refers to member values, not the object)",
"selector": "$[?length(@)==1]",
"document": {"a": 1},
"result": []
},
{
"name": "result must be compared",
"selector" : "$[?length(@.a)]",
Expand Down