Skip to content

Commit

Permalink
rustfmt fail fix
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinstochita committed Nov 22, 2023
1 parent 4078b5e commit f45bfac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
34 changes: 29 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,39 +1228,63 @@ mod tests {
}

#[test]
fn logical_not_exp_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())]);
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())]);
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())]);
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())]);
assert_eq!(
v,
vec![Slice(
&json!({"second":{"active": 1}}),
"$.['first']".to_string()
)]
);
}

// #[test]
Expand Down
2 changes: 0 additions & 2 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ fn parse_filter_index(pair: Pair<Rule>) -> Result<JsonPathIndex, JsonPathParserE
Ok(JsonPathIndex::Filter(parse_logic_or(pair.into_inner())?))
}



fn parse_logic_or(pairs: Pairs<Rule>) -> Result<FilterExpression, JsonPathParserError> {
let mut expr: Option<FilterExpression> = None;
let error_message = format!("Failed to parse logical expression: {:?}", pairs);
Expand Down
4 changes: 2 additions & 2 deletions src/path/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub enum FilterPath<'a> {
},
Not {
exp: PathInstance<'a>,
}
},
}

impl<'a> FilterPath<'a> {
Expand All @@ -228,7 +228,7 @@ impl<'a> FilterPath<'a> {
},
FilterExpression::Not(exp) => FilterPath::Not {
exp: Box::new(FilterPath::new(exp, root)),
}
},
}
}
fn compound(
Expand Down

0 comments on commit f45bfac

Please sign in to comment.