Implemented float literals for OwnedLiterals, not yet for serde_json.
This commit is contained in:
parent
8daa746da6
commit
978bbe6eb3
@ -27,3 +27,7 @@ Do objects with different paths referencing the same variable match?{~n}
|
||||
{#int renamed=some_obj}
|
||||
{@eq key=some_obj value=renamed}some_obj equals renamed{:else}some_obj does not equal renamed{/eq}{~n}
|
||||
{/int}
|
||||
|
||||
Floating point equality{~n}
|
||||
======================={~n}
|
||||
{@eq key=int value=7.0}int is equal to 7.0{:else}int is not equal to 7.0{/eq}
|
||||
|
@ -119,6 +119,7 @@ pub struct Partial<'a> {
|
||||
pub enum OwnedLiteral {
|
||||
LString(String),
|
||||
LPositiveInteger(u64),
|
||||
LFloat(f64),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -137,6 +137,7 @@ impl Truthiness for OwnedLiteral {
|
||||
match self {
|
||||
OwnedLiteral::LString(text) => !text.is_empty(),
|
||||
OwnedLiteral::LPositiveInteger(_num) => true,
|
||||
OwnedLiteral::LFloat(_num) => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,6 +147,7 @@ impl Renderable for OwnedLiteral {
|
||||
match self {
|
||||
OwnedLiteral::LString(text) => Ok(text.clone()),
|
||||
OwnedLiteral::LPositiveInteger(num) => Ok(num.to_string()),
|
||||
OwnedLiteral::LFloat(num) => Ok(num.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,10 +182,25 @@ impl CompareContextElement for OwnedLiteral {
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
self_text == &other_num.to_string()
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LString(other_text)) => {
|
||||
&self_num.to_string() == other_text
|
||||
}
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_text == &other_num.to_string()
|
||||
}
|
||||
(
|
||||
OwnedLiteral::LPositiveInteger(self_num),
|
||||
OwnedLiteral::LPositiveInteger(other_num),
|
||||
) => self_num == other_num,
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_num == other_num
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
*self_num == (*other_num as f64)
|
||||
}
|
||||
(OwnedLiteral::LPositiveInteger(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
(*self_num as f64) == *other_num
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -212,10 +229,25 @@ impl CompareContextElement for OwnedLiteral {
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
self_text.partial_cmp(&other_num.to_string())
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LString(other_text)) => {
|
||||
self_num.to_string().partial_cmp(other_text)
|
||||
}
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_text.partial_cmp(&other_num.to_string())
|
||||
}
|
||||
(
|
||||
OwnedLiteral::LPositiveInteger(self_num),
|
||||
OwnedLiteral::LPositiveInteger(other_num),
|
||||
) => self_num.partial_cmp(other_num),
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_num.partial_cmp(other_num)
|
||||
}
|
||||
(OwnedLiteral::LPositiveInteger(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
(*self_num as f64).partial_cmp(other_num)
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
self_num.partial_cmp(&(*other_num as f64))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user