Skip to content

Commit

Permalink
feat: include query_located in CTS test
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltontj committed Feb 2, 2024
1 parent eeaa619 commit caddcab
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions serde_json_path/tests/compliance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct TestCase {
}

#[test]
fn compliace_test_suite() {
fn compliance_test_suite() {
let cts_json_str = fs::read_to_string("../jsonpath-compliance-test-suite/cts.json")
.expect("read cts.json file");

Expand All @@ -50,12 +50,25 @@ fn compliace_test_suite() {
"{name}: parsing {selector:?} should have failed",
);
} else {
let actual = path.expect("valid JSON Path string").query(document).all();
let path = path.expect("valid JSON Path string");
let expected = result.iter().collect::<Vec<&Value>>();
assert_eq!(
expected, actual,
"{name}: incorrect result, expected {expected:?}, got {actual:?}"
);
{
// Query using JsonPath::query
let actual = path.query(document).all();
assert_eq!(
expected, actual,
"{name}: incorrect result, expected {expected:?}, got {actual:?}"
);
}
{
// Query using JsonPath::query_located
let q = path.query_located(document);
let actual = q.nodes().collect::<Vec<&Value>>();
assert_eq!(
expected, actual,
"(located) {name}: incorrect result, expected {expected:?}, got {actual:?}"
);
}
}
}
}
Expand Down

0 comments on commit caddcab

Please sign in to comment.