-
Notifications
You must be signed in to change notification settings - Fork 11
Test normalized paths #100
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
Conversation
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.
LGTM. Will wait for approvals from @glyn and @gregsdennis.
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.
Nice work! This is a great idea, a user had recently raised an issue on serde_json_path
's normalized path generation. See hiltontj/serde_json_path#113
I just ran the new tests in my implementation, all passed. |
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.
I think this is valuable, thanks. But I don't understand why we'd want some tests not to have normalized paths. Would it be possible to add a commit which includes all the normalized paths for all remaining tests and also have the schema mandate that result_paths is present whenever result is present and results_paths is present whenever results is present?
It's possible. I was thinking 100% path test coverage would be something we'd work towards over time, over multiple commits, considering the labour involved in manually changing and reviewing all 679 test cases. I'll happily chip away at them here over the coming days if necessary. Alternatively we could generate/validate all expected normalized paths programatically using one or more existing implementations, which would give me reasonable confidence in the correctness of the resulting tests. If we were to generate normalized paths programmatically, it would make an alternative schema seem less daunting. For example: (Note that I've changed {
"name": "basic, wildcard shorthand, array data",
"query": "$.*",
"document": ["first", "second"],
"result": {
"values": ["first", "second"],
"paths": ["$[0]", "$[1]"]
}
} and {
"name": "basic, wildcard shorthand, object data",
"selector": "$.*",
"document": {
"a": "A",
"b": "B"
},
"results": [
{
"values": ["A", "B"],
"paths": ["$['a']", "$['b']"]
},
{
"values": ["B", "A"],
"paths": ["$['b']", "$['a']"]
}
]
} |
Yup, I think that's the best solution. I'd be comfortable going with the paths that two implementations (from distinct implementers) agree on. |
Mine already outputs node locations. I'll see if I can batch the output. I can work up the schema changes, too. |
@glyn @gregsdennis I got my version of normalized paths in #101 . We can compare the compiled cts.json to cross-check. |
My last commit populates
@f3ath, it looks like #101 has not updated files in |
Looks like I have a bug where I'm not properly escaping chars in name selectors, but everything else passes for me. Also, I realized that I can't fully generate the cases because I only handle a single potential ordering. |
I used the existing |
7cb3af3
to
f056ea0
Compare
f056ea0
to
aaa53f2
Compare
@glyn, updated |
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.
Similar to @f3ath's suggestion in #99, this PR changes the schema to allow
result_paths
orresults_paths
properties (I couldn't quite bring myself to usepath
singular for an array) and adds expected normalized paths to a few select test cases.Currently,
result_paths
is only allowed whenresult
is present, andresults_paths
is only allowed ifresults
is present. I imagine if normalized paths are worth testing for a given query then the resulting values should be tested too, so testing paths alone is not currently allowed by the schema.