Fix the equality test.

This commit is contained in:
Tom Alexander 2020-05-16 23:19:02 -04:00
parent d77ab7401c
commit 03a8328148
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 10 additions and 8 deletions

View File

@ -143,6 +143,7 @@ impl Loopable for serde_json::Value {
impl CompareContextElement for serde_json::Value { impl CompareContextElement for serde_json::Value {
fn equals(&self, other: &dyn ContextElement) -> bool { fn equals(&self, other: &dyn ContextElement) -> bool {
// println!("equals json {:?} | {:?}", self, other);
// Handle other serde_json::Value // Handle other serde_json::Value
match other.to_any().downcast_ref::<Self>() { match other.to_any().downcast_ref::<Self>() {
None => (), None => (),
@ -156,15 +157,15 @@ impl CompareContextElement for serde_json::Value {
_ => return self == other_json_value, _ => return self == other_json_value,
}, },
} }
// Handle string literals // Handle literals
match other.to_any().downcast_ref::<String>() { match other.to_any().downcast_ref::<OwnedLiteral>() {
None => (), None => (),
Some(other_string) => return self.as_str().map_or(false, |s| s == other_string), Some(OwnedLiteral::LString(other_string)) => {
} return self.as_str().map_or(false, |s| s == other_string)
// Handle numeric literals }
match other.to_any().downcast_ref::<u64>() { Some(OwnedLiteral::LPositiveInteger(other_num)) => {
None => (), return self.as_u64().map_or(false, |n| n == *other_num)
Some(other_num) => return self.as_u64().map_or(false, |n| n == *other_num), }
} }
false false
} }

View File

@ -160,6 +160,7 @@ impl Walkable for OwnedLiteral {
impl CompareContextElement for OwnedLiteral { impl CompareContextElement for OwnedLiteral {
fn equals(&self, other: &dyn ContextElement) -> bool { fn equals(&self, other: &dyn ContextElement) -> bool {
// println!("equals literal {:?} | {:?}", self, other);
// If its an OwnedLiteral then compare them directly, // If its an OwnedLiteral then compare them directly,
// otherwise defer to the other type's implementation of // otherwise defer to the other type's implementation of
// CompareContextElement since the end user could add any // CompareContextElement since the end user could add any