diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 117f882..e612cf5 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -292,88 +292,76 @@ mod tests { use crate::renderer::context_element::Loopable; use crate::renderer::context_element::Renderable; use crate::renderer::context_element::Walkable; + use crate::renderer::CompareContextElement; - impl ContextElement for u32 {} - impl ContextElement for &str {} - impl ContextElement for HashMap<&str, I> {} + impl ContextElement for HashMap {} - impl Renderable for u32 { - fn render(&self, _filters: &Vec) -> Result { - // TODO: handle the filters - Ok(self.to_string()) - } - } - - impl Renderable for &str { - fn render(&self, _filters: &Vec) -> Result { - // TODO: handle the filters - Ok(self.to_string()) - } - } - - impl Renderable for HashMap<&str, I> { + impl Renderable for HashMap { fn render(&self, _filters: &Vec) -> Result { // TODO: handle the filters Ok("[object Object]".to_owned()) } } - impl Walkable for HashMap<&str, I> { + impl Walkable for HashMap { fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { let child = self.get(segment).ok_or(WalkError::CantWalk)?; Ok(child) } } - impl Walkable for &str { - fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { - Err(WalkError::CantWalk) - } - } - - impl Walkable for u32 { - fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { - Err(WalkError::CantWalk) - } - } - - impl Loopable for &str { - fn get_loop_elements(&self) -> Vec<&dyn ContextElement> { - if self.is_empty() { - Vec::new() - } else { - vec![self] - } - } - } - - impl Loopable for u32 { + impl Loopable for HashMap { fn get_loop_elements(&self) -> Vec<&dyn ContextElement> { vec![self] } } - impl Loopable for HashMap<&str, I> { - fn get_loop_elements(&self) -> Vec<&dyn ContextElement> { - vec![self] + impl CompareContextElement for HashMap { + fn equals(&self, other: &dyn ContextElement) -> bool { + false } } #[test] fn test_walk_path() { - let context: HashMap<&str, &str> = - [("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")] - .iter() - .cloned() - .collect(); - let number_context: HashMap<&str, u32> = [("cat", 1), ("dog", 2), ("tiger", 3)] - .iter() - .cloned() - .collect(); - let deep_context: HashMap<&str, HashMap<&str, &str>> = [ - ("cat", [("food", "meat")].iter().cloned().collect()), - ("dog", [("food", "meat")].iter().cloned().collect()), - ("tiger", [("food", "people")].iter().cloned().collect()), + let context: HashMap = [ + ("cat".to_string(), "kitty".to_string()), + ("dog".to_string(), "doggy".to_string()), + ("tiger".to_string(), "murderkitty".to_string()), + ] + .iter() + .cloned() + .collect(); + let number_context: HashMap = [ + ("cat".to_string(), 1), + ("dog".to_string(), 2), + ("tiger".to_string(), 3), + ] + .iter() + .cloned() + .collect(); + let deep_context: HashMap> = [ + ( + "cat".to_string(), + [("food".to_string(), "meat".to_string())] + .iter() + .cloned() + .collect(), + ), + ( + "dog".to_string(), + [("food".to_string(), "meat".to_string())] + .iter() + .cloned() + .collect(), + ), + ( + "tiger".to_string(), + [("food".to_string(), "people".to_string())] + .iter() + .cloned() + .collect(), + ), ] .iter() .cloned()