Fix the equality test.
This commit is contained in:
parent
d77ab7401c
commit
03a8328148
17
src/bin.rs
17
src/bin.rs
@ -143,6 +143,7 @@ impl Loopable for serde_json::Value {
|
||||
|
||||
impl CompareContextElement for serde_json::Value {
|
||||
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||
// println!("equals json {:?} | {:?}", self, other);
|
||||
// Handle other serde_json::Value
|
||||
match other.to_any().downcast_ref::<Self>() {
|
||||
None => (),
|
||||
@ -156,15 +157,15 @@ impl CompareContextElement for serde_json::Value {
|
||||
_ => return self == other_json_value,
|
||||
},
|
||||
}
|
||||
// Handle string literals
|
||||
match other.to_any().downcast_ref::<String>() {
|
||||
// Handle literals
|
||||
match other.to_any().downcast_ref::<OwnedLiteral>() {
|
||||
None => (),
|
||||
Some(other_string) => return self.as_str().map_or(false, |s| s == other_string),
|
||||
}
|
||||
// Handle numeric literals
|
||||
match other.to_any().downcast_ref::<u64>() {
|
||||
None => (),
|
||||
Some(other_num) => return self.as_u64().map_or(false, |n| n == *other_num),
|
||||
Some(OwnedLiteral::LString(other_string)) => {
|
||||
return self.as_str().map_or(false, |s| s == other_string)
|
||||
}
|
||||
Some(OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
return self.as_u64().map_or(false, |n| n == *other_num)
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ impl Walkable for OwnedLiteral {
|
||||
|
||||
impl CompareContextElement for OwnedLiteral {
|
||||
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||
// println!("equals literal {:?} | {:?}", self, other);
|
||||
// If its an OwnedLiteral then compare them directly,
|
||||
// otherwise defer to the other type's implementation of
|
||||
// CompareContextElement since the end user could add any
|
||||
|
Loading…
x
Reference in New Issue
Block a user