I have broken the comparison function.

This commit is contained in:
Tom Alexander 2020-06-13 14:55:27 -04:00
parent 5b656a44ad
commit 4d28120732
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -410,18 +410,21 @@ impl CompareContextElement for serde_json::Value {
} }
} }
// Handle literals // Handle literals
match other.to_any().downcast_ref::<OwnedLiteral>() { match (self, other.to_any().downcast_ref::<OwnedLiteral>()) {
None => (), (_, None) => (),
Some(OwnedLiteral::LString(text)) => { (serde_json::Value::String(self_text), Some(OwnedLiteral::LString(other_text))) => {
return self_text.partial_cmp(other_text);
}
(_, Some(OwnedLiteral::LString(text))) => {
return self.to_string().partial_cmp(text); return self.to_string().partial_cmp(text);
} }
Some(OwnedLiteral::LPositiveInteger(other_num)) => { (_, Some(OwnedLiteral::LPositiveInteger(other_num))) => {
let other_json_num: serde_json::Number = std::convert::From::from(*other_num); let other_json_num: serde_json::Number = std::convert::From::from(*other_num);
return self.partial_compare( return self.partial_compare(
&serde_json::Value::Number(other_json_num) as &dyn ContextElement &serde_json::Value::Number(other_json_num) as &dyn ContextElement
); );
} }
Some(OwnedLiteral::LFloat(other_num)) => { (_, Some(OwnedLiteral::LFloat(other_num))) => {
let other_json_num = serde_json::Number::from_f64(*other_num); let other_json_num = serde_json::Number::from_f64(*other_num);
match other_json_num { match other_json_num {
None => return None, None => return None,
@ -483,6 +486,13 @@ impl From<&OwnedLiteral> for JsonNumber {
match original { match original {
OwnedLiteral::LPositiveInteger(num) => JsonNumber::UnsignedInteger(*num), OwnedLiteral::LPositiveInteger(num) => JsonNumber::UnsignedInteger(*num),
OwnedLiteral::LString(text) => text.into(), OwnedLiteral::LString(text) => text.into(),
OwnedLiteral::LFloat(num) => {
if num.is_nan() {
JsonNumber::Failure
} else {
JsonNumber::Decimal(*num)
}
}
} }
} }
} }