Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compliance Update #67

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion serde_json_path/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -229,4 +232,4 @@ assert_eq!(nodes, vec![1, 2, 3]);

# Previous Versions

Previous versions are not documented here.
Previous versions are not documented here.
4 changes: 4 additions & 0 deletions serde_json_path/src/parser/primitive/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
);
}
}
13 changes: 8 additions & 5 deletions serde_json_path/src/parser/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ fn parse_dot_wildcard_shorthand(input: &str) -> PResult<Segment> {

#[cfg_attr(feature = "trace", tracing::instrument(level = "trace", parent = None, ret, err))]
fn parse_child_segment(input: &str) -> PResult<Segment> {
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))]
Expand Down
2 changes: 1 addition & 1 deletion serde_json_path/tests/compliance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn compliace_test_suite() {
}
}

const TEST_CASE_N: usize = 303;
const TEST_CASE_N: usize = 388;

#[test]
#[ignore = "this is only for testing individual CTS test cases as needed"]
Expand Down
2 changes: 2 additions & 0 deletions serde_json_path_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 23 additions & 4 deletions serde_json_path_core/src/spec/selector/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down