From de77b7a3efcba24b9bf6ee5162512c6e684c5602 Mon Sep 17 00:00:00 2001 From: Trevor Hilton Date: Wed, 8 Nov 2023 09:20:00 -0500 Subject: [PATCH 1/3] fix compliance test for checking negative 0 --- jsonpath-compliance-test-suite | 2 +- .../src/parser/primitive/number.rs | 4 +++ serde_json_path/tests/compliance.rs | 2 +- .../src/spec/selector/filter.rs | 27 ++++++++++++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/jsonpath-compliance-test-suite b/jsonpath-compliance-test-suite index 1f50165..ca076c0 160000 --- a/jsonpath-compliance-test-suite +++ b/jsonpath-compliance-test-suite @@ -1 +1 @@ -Subproject commit 1f501653e6e84e6830834a217abad9df405ece3b +Subproject commit ca076c0e55d378236e7b70fc8e6414234dcca294 diff --git a/serde_json_path/src/parser/primitive/number.rs b/serde_json_path/src/parser/primitive/number.rs index b1174cc..01d4313 100644 --- a/serde_json_path/src/parser/primitive/number.rs +++ b/serde_json_path/src/parser/primitive/number.rs @@ -55,5 +55,9 @@ mod tests { parse_number("1.0001"), Ok(("", Number::from_f64(1.0001).unwrap())) ); + assert_eq!( + parse_number("-0"), + Ok(("", Number::from_f64(-0.0).unwrap())) + ); } } diff --git a/serde_json_path/tests/compliance.rs b/serde_json_path/tests/compliance.rs index c95ca67..9f82f54 100644 --- a/serde_json_path/tests/compliance.rs +++ b/serde_json_path/tests/compliance.rs @@ -60,7 +60,7 @@ fn compliace_test_suite() { } } -const TEST_CASE_N: usize = 303; +const TEST_CASE_N: usize = 131; #[test] #[ignore = "this is only for testing individual CTS test cases as needed"] diff --git a/serde_json_path_core/src/spec/selector/filter.rs b/serde_json_path_core/src/spec/selector/filter.rs index e3e2242..563a535 100644 --- a/serde_json_path_core/src/spec/selector/filter.rs +++ b/serde_json_path_core/src/spec/selector/filter.rs @@ -214,15 +214,34 @@ pub struct ComparisonExpr { fn check_equal_to(left: &JsonPathValue, right: &JsonPathValue) -> bool { match (left, right) { - (JsonPathValue::Node(v1), JsonPathValue::Node(v2)) => v1 == v2, - (JsonPathValue::Node(v1), JsonPathValue::Value(v2)) => *v1 == v2, - (JsonPathValue::Value(v1), JsonPathValue::Node(v2)) => v1 == *v2, - (JsonPathValue::Value(v1), JsonPathValue::Value(v2)) => v1 == v2, + (JsonPathValue::Node(v1), JsonPathValue::Node(v2)) => value_equal_to(v1, v2), + (JsonPathValue::Node(v1), JsonPathValue::Value(v2)) => value_equal_to(v1, v2), + (JsonPathValue::Value(v1), JsonPathValue::Node(v2)) => value_equal_to(v1, v2), + (JsonPathValue::Value(v1), JsonPathValue::Value(v2)) => value_equal_to(v1, v2), (JsonPathValue::Nothing, JsonPathValue::Nothing) => true, _ => false, } } +fn value_equal_to(left: &Value, right: &Value) -> bool { + match (left, right) { + (Value::Number(l), Value::Number(r)) => number_equal_to(l, r), + _ => left == right, + } +} + +fn number_equal_to(left: &Number, right: &Number) -> bool { + if let (Some(l), Some(r)) = (left.as_f64(), right.as_f64()) { + l == r + } else if let (Some(l), Some(r)) = (left.as_i64(), right.as_i64()) { + l == r + } else if let (Some(l), Some(r)) = (left.as_u64(), right.as_u64()) { + l == r + } else { + false + } +} + fn value_less_than(left: &Value, right: &Value) -> bool { match (left, right) { (Value::Number(n1), Value::Number(n2)) => number_less_than(n1, n2), From 0e30e635134161c605d07b5b32938e4901fe9c95 Mon Sep 17 00:00:00 2001 From: Trevor Hilton Date: Wed, 8 Nov 2023 14:06:45 -0500 Subject: [PATCH 2/3] fix whitespace in dot name selector compliance issue --- serde_json_path/src/parser/segment.rs | 13 ++++++++----- serde_json_path/tests/compliance.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/serde_json_path/src/parser/segment.rs b/serde_json_path/src/parser/segment.rs index 8cc45ba..0cd5cc3 100644 --- a/serde_json_path/src/parser/segment.rs +++ b/serde_json_path/src/parser/segment.rs @@ -95,11 +95,14 @@ fn parse_dot_wildcard_shorthand(input: &str) -> PResult { #[cfg_attr(feature = "trace", tracing::instrument(level = "trace", parent = None, ret, err))] fn parse_child_segment(input: &str) -> PResult { - alt(( - parse_dot_wildcard_shorthand, - parse_dot_member_name_shorthand, - parse_child_long_hand, - ))(input) + preceded( + multispace0, + alt(( + parse_dot_wildcard_shorthand, + parse_dot_member_name_shorthand, + parse_child_long_hand, + )), + )(input) } #[cfg_attr(feature = "trace", tracing::instrument(level = "trace", parent = None, ret, err))] diff --git a/serde_json_path/tests/compliance.rs b/serde_json_path/tests/compliance.rs index 9f82f54..13850b3 100644 --- a/serde_json_path/tests/compliance.rs +++ b/serde_json_path/tests/compliance.rs @@ -60,7 +60,7 @@ fn compliace_test_suite() { } } -const TEST_CASE_N: usize = 131; +const TEST_CASE_N: usize = 388; #[test] #[ignore = "this is only for testing individual CTS test cases as needed"] From 98bfbd0bf91a25fa97e3125e6e7d8d78a1dedd2e Mon Sep 17 00:00:00 2001 From: Trevor Hilton Date: Wed, 8 Nov 2023 14:21:28 -0500 Subject: [PATCH 3/3] update changelog --- serde_json_path/CHANGELOG.md | 5 ++++- serde_json_path_core/CHANGELOG.md | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/serde_json_path/CHANGELOG.md b/serde_json_path/CHANGELOG.md index 5888742..de1e930 100644 --- a/serde_json_path/CHANGELOG.md +++ b/serde_json_path/CHANGELOG.md @@ -8,8 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased - **added**: `is_empty`, `is_more_than_one`, and `as_more_than_one` methods to `ExactlyOneError` ([#65]) +- **fixed**: allow whitespace before dot-name selectors ([#67]) +- **fixed**: ensure that the check `== -0` in filters works as expected ([#67]) [#65]: https://github.com/hiltontj/serde_json_path/pull/65 +[#67]: https://github.com/hiltontj/serde_json_path/pull/67 # 0.6.3 (17 September 2023) @@ -229,4 +232,4 @@ assert_eq!(nodes, vec![1, 2, 3]); # Previous Versions -Previous versions are not documented here. \ No newline at end of file +Previous versions are not documented here. diff --git a/serde_json_path_core/CHANGELOG.md b/serde_json_path_core/CHANGELOG.md index 68cba31..619c8de 100644 --- a/serde_json_path_core/CHANGELOG.md +++ b/serde_json_path_core/CHANGELOG.md @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased - **added**: `is_empty`, `is_more_than_one`, and `as_more_than_one` methods to `ExactlyOneError` ([#65]) +- **fixed**: ensure that the check `== -0` in filters works as expected ([#67]) [#65]: https://github.com/hiltontj/serde_json_path/pull/65 +[#67]: https://github.com/hiltontj/serde_json_path/pull/67 # 0.1.2 (17 September 2023)