From 4d28120732ffeb29ded0613af3e38e28722ea6e9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 13 Jun 2020 14:55:27 -0400 Subject: [PATCH] I have broken the comparison function. --- src/bin.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 66bb1cf..c5b6a2f 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -410,18 +410,21 @@ impl CompareContextElement for serde_json::Value { } } // Handle literals - match other.to_any().downcast_ref::() { - None => (), - Some(OwnedLiteral::LString(text)) => { + match (self, other.to_any().downcast_ref::()) { + (_, None) => (), + (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); } - Some(OwnedLiteral::LPositiveInteger(other_num)) => { + (_, Some(OwnedLiteral::LPositiveInteger(other_num))) => { let other_json_num: serde_json::Number = std::convert::From::from(*other_num); return self.partial_compare( &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); match other_json_num { None => return None, @@ -483,6 +486,13 @@ impl From<&OwnedLiteral> for JsonNumber { match original { OwnedLiteral::LPositiveInteger(num) => JsonNumber::UnsignedInteger(*num), OwnedLiteral::LString(text) => text.into(), + OwnedLiteral::LFloat(num) => { + if num.is_nan() { + JsonNumber::Failure + } else { + JsonNumber::Decimal(*num) + } + } } } }