-
Notifications
You must be signed in to change notification settings - Fork 6
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -509,6 +509,26 @@ | |||||
} | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"name": "filter, existence without selector", | ||||||
"selector": "$[?@]", | ||||||
"document": { | ||||||
"a": {}, | ||||||
"b": 1 | ||||||
}, | ||||||
"result": [ | ||||||
{}, | ||||||
1 | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"name": "filter, existence test on primitive, selects nothing", | ||||||
"selector": "$.a[?@]", | ||||||
"document": { | ||||||
"a": 1 | ||||||
}, | ||||||
"result": [] | ||||||
}, | ||||||
{ | ||||||
"name": "filter, equals string, single quotes", | ||||||
"selector": "$[?@.a=='b']", | ||||||
|
@@ -1844,6 +1864,43 @@ | |||||
] | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"name": "filter, on primitive, selects nothing", | ||||||
"selector": "$.a[?@ == 1]", | ||||||
"document": { | ||||||
"a": 1 | ||||||
}, | ||||||
"result": [] | ||||||
}, | ||||||
{ | ||||||
"name": "filter, on primitive object member value, selects nothing", | ||||||
"selector": "$[?@.a == 1]", | ||||||
"document": { | ||||||
"a": 1 | ||||||
}, | ||||||
"result": [] | ||||||
}, | ||||||
{ | ||||||
"name": "filter, name selector on array", | ||||||
"selector": "$[?@['0'] == 5]", | ||||||
"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)]", | ||||||
|
@@ -4096,6 +4153,22 @@ | |||||
], | ||||||
"result": [] | ||||||
}, | ||||||
{ | ||||||
"name": "functions, length, filter on primitive array element, selects nothing", | ||||||
"selector": "$[?length(@)==1]", | ||||||
"document": [ | ||||||
1 | ||||||
], | ||||||
"result": [] | ||||||
}, | ||||||
{ | ||||||
"name": "functions, length, filter on primitive object member value, selects nothing", | ||||||
"selector": "$[?length(@)==1]", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"document": { | ||||||
"a": 1 | ||||||
}, | ||||||
"result": [] | ||||||
}, | ||||||
{ | ||||||
"name": "functions, length, result must be compared", | ||||||
"selector": "$[?length(@.a)]", | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,18 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
{"a": null, "d": "e"} | ||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "existence without selector", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"selector": "$[?@]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"document": {"a": {}, "b": 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
"result": [{}, 1] | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "existence test on primitive, selects nothing", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"selector": "$.a[?@]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"document": {"a": 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
"result": [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "equals string, single quotes", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"selector" : "$[?@.a=='b']", | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -478,6 +490,30 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
[42] | ||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "on primitive, selects nothing", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"selector": "$.a[?@ == 1]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"document": {"a": 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
"result": [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+493
to
+498
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be improved since the
Suggested change
Also, I don't think having a filter here improves the test. It could be any selector.
Suggested change
would do just as well. If we use this, then we need to have a series of these, and
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It seems that would be the first test then with primitive top-level value. I had created #57 to propose in general adding tests for that.
But those are (at least in the specification) two separate cases which independently say that only arrays and objects are supported, so maybe it would be good to have separate tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I thought we had those tests for primitives but we only have tests for e.g. "index selector against object".) |
||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "on primitive object member value, selects nothing", | ||||||||||||||||||||||||||||||||||||||||||||||||||
"selector": "$[?@.a == 1]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+500
to
+501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the following three tests seem to be checking that a relative path ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one was based on hiltontj/serde_json_path#49 where the reporter assumed And the tests "name selector on array" and "index selector on object" are supposed to cover the same issue in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Two things here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fair point. But I think here if the document is But if you add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I view this differently. The test should be that Separately, we test that That There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Therefore, I think there is value in having tests that ensure the behaviour of queries against primitives for both absolute and relative paths. Relative paths can only appear in filters, so having separate tests for those requires queries like @Marcono1234 has used here. I suppose that the motivation for this test case is that one implementor (me) made a logic error in the handling of singular queries, so, having this test would prevent another from doing the same. It is not possible to come up with tests for every conceivable logic error, or misinterpretation of JSONPath, but I don't see the harm in having a test that guards against one that did happen (and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While true,
Okay. That this was an implementation error wasn't understood. I thought this was a user that expected something incorrect. However, I still maintain, that this test is overly complex and can be broken down into smaller constituent pieces that still achieve the goal of verifying proper operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for taking so long to get back...
This escaped me, thanks for pointing that out. I was incorrect there. Relative path |
||||||||||||||||||||||||||||||||||||||||||||||||||
"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)]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,18 @@ | |
"document" : [{"d": "f"}], | ||
"result": [] | ||
}, | ||
{ | ||
"name": "filter on primitive array element, selects nothing", | ||
"selector": "$[?length(@)==1]", | ||
"document": [1], | ||
"result": [] | ||
}, | ||
Comment on lines
+55
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're already effectively testing this with "number arg" on line 32 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as with #56 (comment); the intention was to make sure no library misinterprets |
||
{ | ||
"name": "filter on primitive object member value, selects nothing", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the effectively the same test as before: checking to see what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right; I mainly added this to make sure no implementation misinterprets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that can be tested without the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you provide an example for such a test please? My intention was that if a library misinterprets Maybe using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that would not detect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, exactly, and in doing so, it correctly tests that the implementation is interpreting Once it's known that the implementation interprets |
||
"selector": "$[?length(@)==1]", | ||
"document": {"a": 1}, | ||
"result": [] | ||
}, | ||
{ | ||
"name": "result must be compared", | ||
"selector" : "$[?length(@.a)]", | ||
|
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.:should select all the elements of an array argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/blob/main/tests%2Ffilter.json
We have
Nothing
equality.There was a problem hiding this comment.
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.