From caddcab336763858beca1072923ef93ed2be7c31 Mon Sep 17 00:00:00 2001 From: Trevor Hilton Date: Fri, 2 Feb 2024 15:20:35 -0500 Subject: [PATCH] feat: include query_located in CTS test --- serde_json_path/tests/compliance.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/serde_json_path/tests/compliance.rs b/serde_json_path/tests/compliance.rs index 13850b3..531562f 100644 --- a/serde_json_path/tests/compliance.rs +++ b/serde_json_path/tests/compliance.rs @@ -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"); @@ -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::>(); - 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::>(); + assert_eq!( + expected, actual, + "(located) {name}: incorrect result, expected {expected:?}, got {actual:?}" + ); + } } } }