-
Notifications
You must be signed in to change notification settings - Fork 32
Compiled path test suite #102
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
Draft
thehiddenwaffle
wants to merge
4
commits into
besok:main
Choose a base branch
from
thehiddenwaffle:compiled_path_test_suite_c
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a635e6a
Progress on the test functions
thehiddenwaffle 8c09cb9
Refactor grammar to improve function parsing with type-sensitive func…
thehiddenwaffle 0b7c34c
Refactor function parsing to support type-sensitive signatures.
thehiddenwaffle 0e5e7fc
Merge branch 'besok:main' into compiled_path_test_suite_c
thehiddenwaffle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
jsonpath-rust-impl/tests/rfc9535_compile_tests/functions/count/compile_and_passes.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Test case: 00_count_function | ||
// Tags: function, count | ||
#[test] | ||
fn test_00_count_function() { | ||
let q_ast = ::jsonpath_rust_impl::json_query!($[?count(@..*)>2]); | ||
let q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(@..*)>2]"#).expect("failed to parse"); | ||
assert_eq!(q_pest, q_ast); | ||
} | ||
|
||
// Test case: 01_single_node_arg | ||
// Tags: function, count | ||
#[test] | ||
fn test_01_single_node_arg() { | ||
let q_ast = ::jsonpath_rust_impl::json_query!($[?count(@.a)>1]); | ||
let q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(@.a)>1]"#).expect("failed to parse"); | ||
assert_eq!(q_pest, q_ast); | ||
} | ||
|
||
// Test case: 02_multiple_selector_arg | ||
// Tags: function, count | ||
#[test] | ||
fn test_02_multiple_selector_arg() { | ||
let q_ast = ::jsonpath_rust_impl::json_query!($[?count(@["a","d"])>1]); | ||
let q_pest_double = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(@["a","d"])>1]"#).expect("failed to parse"); | ||
let q_pest_single = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(@['a','d'])>1]"#).expect("failed to parse"); | ||
assert_eq!(q_pest_double, q_ast); | ||
assert_eq!(q_pest_single, q_ast); | ||
} |
63 changes: 63 additions & 0 deletions
63
jsonpath-rust-impl/tests/rfc9535_compile_tests/functions/count/compile_but_expect_err.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Test case: 03_non_query_arg_number | ||
// Tags: function, count | ||
#[test] | ||
fn test_03_non_query_arg_number() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count(1)>2]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(1)>2]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 04_non_query_arg_string | ||
// Tags: function, count | ||
#[test] | ||
fn test_04_non_query_arg_string() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count('string')>2]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count('string')>2]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 05_non_query_arg_true | ||
// Tags: function, count | ||
#[test] | ||
fn test_05_non_query_arg_true() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count(true)>2]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(true)>2]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 06_non_query_arg_false | ||
// Tags: function, count | ||
#[test] | ||
fn test_06_non_query_arg_false() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count(false)>2]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(false)>2]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 07_non_query_arg_null | ||
// Tags: function, count | ||
#[test] | ||
fn test_07_non_query_arg_null() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count(null)>2]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(null)>2]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 08_result_must_be_compared | ||
// Tags: function, count | ||
#[test] | ||
fn test_08_result_must_be_compared() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count(@..*)]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(@..*)]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 09_no_params | ||
// Tags: function, count | ||
#[test] | ||
fn test_09_no_params() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count()==1]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count()==1]"#).expect_err("should not parse"); | ||
} | ||
|
||
// Test case: 10_too_many_params | ||
// Tags: function, count | ||
#[test] | ||
fn test_10_too_many_params() { | ||
// let q_ast = ::jsonpath_rust_impl::json_query!($[?count(@.a,@.b)==1]); | ||
let _q_pest = ::jsonpath_ast::ast::Main::try_from_pest_parse(r#"$[?count(@.a,@.b)==1]"#).expect_err("should not parse"); | ||
} |
47 changes: 47 additions & 0 deletions
47
jsonpath-rust-impl/tests/rfc9535_compile_tests/functions/count/does_not_compile.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Test case: 03_non_query_arg_number | ||
// Tags: function, count | ||
fn test_03_non_query_arg_number() { | ||
::jsonpath_rust_impl::json_query!($[?count(1)>2]); | ||
} | ||
|
||
// Test case: 04_non_query_arg_string | ||
// Tags: function, count | ||
fn test_04_non_query_arg_string() { | ||
::jsonpath_rust_impl::json_query!($[?count('string')>2]); | ||
} | ||
|
||
// Test case: 05_non_query_arg_true | ||
// Tags: function, count | ||
fn test_05_non_query_arg_true() { | ||
::jsonpath_rust_impl::json_query!($[?count(true)>2]); | ||
} | ||
|
||
// Test case: 06_non_query_arg_false | ||
// Tags: function, count | ||
fn test_06_non_query_arg_false() { | ||
::jsonpath_rust_impl::json_query!($[?count(false)>2]); | ||
} | ||
|
||
// Test case: 07_non_query_arg_null | ||
// Tags: function, count | ||
fn test_07_non_query_arg_null() { | ||
::jsonpath_rust_impl::json_query!($[?count(null)>2]); | ||
} | ||
|
||
// Test case: 08_result_must_be_compared | ||
// Tags: function, count | ||
fn test_08_result_must_be_compared() { | ||
::jsonpath_rust_impl::json_query!($[?count(@..*)]); | ||
} | ||
|
||
// Test case: 09_no_params | ||
// Tags: function, count | ||
fn test_09_no_params() { | ||
::jsonpath_rust_impl::json_query!($[?count()==1]); | ||
} | ||
|
||
// Test case: 10_too_many_params | ||
// Tags: function, count | ||
fn test_10_too_many_params() { | ||
::jsonpath_rust_impl::json_query!($[?count(@.a,@.b)==1]); | ||
} |
2 changes: 2 additions & 0 deletions
2
jsonpath-rust-impl/tests/rfc9535_compile_tests/functions/count/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod compile_and_passes; | ||
pub(crate) mod compile_but_expect_err; |
1 change: 1 addition & 0 deletions
1
jsonpath-rust-impl/tests/rfc9535_compile_tests/functions/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod count; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub(crate) mod basic; | ||
pub(crate) mod functions; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
During the course of testing functions I've realized that the current grammar isn't enforcing well typed arguments, meaning that a function call could make it through the grammar but still be considered invalid. This would seriously hamper the notion of being able compile paths because they would pest parse correctly then need to be checked again. I think tightening the grammar further to include a notion of the 3 types mentioned in the RFC would allow for a much more concise parser, as well as reduce validation logic during path parsing.
Uh oh!
There was an error while loading. Please reload this page.
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've read the RFC like 4 times now, and though I think I've got everything, but my head is starting to spin.