-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added negate operator '!' * Fix chaining '!' by moving the logic_not before parsing logic_atom * rustfmt fail fix
- Loading branch information
1 parent
c7b5524
commit 89a0630
Showing
6 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -1244,6 +1244,66 @@ mod tests { | |
); | ||
} | ||
|
||
#[test] | ||
fn logical_not_exp_test() { | ||
let json: Box<Value> = Box::new(json!({"first":{"second":{"active":1}}})); | ||
let path: Box<JsonPathInst> = Box::from( | ||
JsonPathInst::from_str("$.first[?([email protected]_not_exist >= 1.0)]") | ||
.expect("the path is correct"), | ||
); | ||
let finder = JsonPathFinder::new(json.clone(), path); | ||
let v = finder.find_slice(); | ||
assert_eq!( | ||
v, | ||
vec![Slice( | ||
&json!({"second":{"active": 1}}), | ||
"$.['first']".to_string() | ||
)] | ||
); | ||
|
||
let path: Box<JsonPathInst> = Box::from( | ||
JsonPathInst::from_str("$.first[?(!(@.does_not_exist >= 1.0))]") | ||
.expect("the path is correct"), | ||
); | ||
let finder = JsonPathFinder::new(json.clone(), path); | ||
let v = finder.find_slice(); | ||
assert_eq!( | ||
v, | ||
vec![Slice( | ||
&json!({"second":{"active": 1}}), | ||
"$.['first']".to_string() | ||
)] | ||
); | ||
|
||
let path: Box<JsonPathInst> = Box::from( | ||
JsonPathInst::from_str("$.first[?(!(@.second.active == 1) || @.second.active == 1)]") | ||
.expect("the path is correct"), | ||
); | ||
let finder = JsonPathFinder::new(json.clone(), path); | ||
let v = finder.find_slice(); | ||
assert_eq!( | ||
v, | ||
vec![Slice( | ||
&json!({"second":{"active": 1}}), | ||
"$.['first']".to_string() | ||
)] | ||
); | ||
|
||
let path: Box<JsonPathInst> = Box::from( | ||
JsonPathInst::from_str("$.first[?([email protected] == 1 && [email protected] == 1 || [email protected] == 2)]") | ||
.expect("the path is correct"), | ||
); | ||
let finder = JsonPathFinder::new(json, path); | ||
let v = finder.find_slice(); | ||
assert_eq!( | ||
v, | ||
vec![Slice( | ||
&json!({"second":{"active": 1}}), | ||
"$.['first']".to_string() | ||
)] | ||
); | ||
} | ||
|
||
// #[test] | ||
// fn no_value_len_field_test() { | ||
// let json: Box<Value> = | ||
|
This file contains 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 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 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 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