Fix tests.

This commit is contained in:
Tom Alexander
2020-05-16 22:39:29 -04:00
parent c905e705ff
commit 189dfb1755
2 changed files with 96 additions and 11 deletions

View File

@@ -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<Filter>) -> Result<String, RenderError> {
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::<Self>() {
None => false,
Some(other_string) => self == other_string,
}
}
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
match other.to_any().downcast_ref::<Self>() {
None => None,
Some(other_string) => self.partial_cmp(other_string),
}
}
}
impl ContextElement for u64 {}
impl Renderable for u64 {
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
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::<Self>() {
None => false,
Some(other_num) => self == other_num,
}
}
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
match other.to_any().downcast_ref::<Self>() {
None => None,
Some(other_num) => self.partial_cmp(other_num),
}
}
}
impl<I: 'static + ContextElement + Clone> ContextElement for HashMap<String, I> {}
impl<I: ContextElement> Renderable for HashMap<String, I> {