From 189dfb1755cc11f510d620af1aebcc02269fc66f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 May 2020 22:39:29 -0400 Subject: [PATCH] Fix tests. --- src/parser/parser.rs | 32 +++++++++++------ src/renderer/renderer.rs | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 11 deletions(-) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 613f2df..a1ed027 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -920,7 +920,7 @@ mod tests { }, KVPair { key: "animal", - value: RValue::RVString("cat".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString("cat".to_owned())) } ] }) @@ -943,7 +943,7 @@ mod tests { }, KVPair { key: "animal", - value: RValue::RVString("cat".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString("cat".to_owned())) } ] }) @@ -962,11 +962,11 @@ mod tests { params: vec![ KVPair { key: "a", - value: RValue::RVString("foo".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString("foo".to_owned())) }, KVPair { key: "b", - value: RValue::RVPositiveInteger(179) + value: RValue::RVLiteral(OwnedLiteral::LPositiveInteger(179)) } ] }) @@ -989,7 +989,7 @@ mod tests { }, KVPair { key: "value", - value: RValue::RVString("cat".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString("cat".to_owned())) } ], contents: Some(Body { @@ -1025,7 +1025,7 @@ mod tests { }, KVPair { key: "value", - value: RValue::RVString("cat".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString("cat".to_owned())) } ], contents: None, @@ -1131,23 +1131,33 @@ mod tests { params: vec![ KVPair { key: "v1", - value: RValue::RVString("b".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString( + "b".to_owned() + )) }, KVPair { key: "v2", - value: RValue::RVString("b".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString( + "b".to_owned() + )) }, KVPair { key: "v3", - value: RValue::RVString("b".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString( + "b".to_owned() + )) }, KVPair { key: "v4", - value: RValue::RVString("b".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString( + "b".to_owned() + )) }, KVPair { key: "v5", - value: RValue::RVString("b".to_owned()) + value: RValue::RVLiteral(OwnedLiteral::LString( + "b".to_owned() + )) } ] } diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index f3862cd..0169599 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -493,6 +493,81 @@ mod tests { use crate::renderer::context_element::Walkable; use crate::renderer::CompareContextElement; + impl ContextElement for String {} + + impl Renderable for String { + fn render(&self, _filters: &Vec) -> Result { + Ok(self.clone()) + } + } + + impl Loopable for String { + fn get_loop_elements(&self) -> Vec<&dyn ContextElement> { + if self.is_empty() { + Vec::new() + } else { + vec![self] + } + } + } + + impl Walkable for String { + fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { + Err(WalkError::CantWalk) + } + } + + impl CompareContextElement for String { + fn equals(&self, other: &dyn ContextElement) -> bool { + match other.to_any().downcast_ref::() { + None => false, + Some(other_string) => self == other_string, + } + } + + fn partial_compare(&self, other: &dyn ContextElement) -> Option { + match other.to_any().downcast_ref::() { + None => None, + Some(other_string) => self.partial_cmp(other_string), + } + } + } + impl ContextElement for u64 {} + + impl Renderable for u64 { + fn render(&self, _filters: &Vec) -> Result { + Ok(self.to_string()) + } + } + + impl Loopable for u64 { + fn get_loop_elements(&self) -> Vec<&dyn ContextElement> { + vec![self] + } + } + + impl Walkable for u64 { + fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { + Err(WalkError::CantWalk) + } + } + + impl CompareContextElement for u64 { + fn equals(&self, other: &dyn ContextElement) -> bool { + match other.to_any().downcast_ref::() { + None => false, + Some(other_num) => self == other_num, + } + } + + fn partial_compare(&self, other: &dyn ContextElement) -> Option { + match other.to_any().downcast_ref::() { + None => None, + Some(other_num) => self.partial_cmp(other_num), + } + } + } + impl ContextElement for HashMap {} impl Renderable for HashMap {