Revived the tests.
This commit is contained in:
parent
c88cab8316
commit
6e6560c742
@ -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<I: ContextElement> ContextElement for HashMap<&str, I> {}
|
||||
impl<I: 'static + ContextElement + Clone> ContextElement for HashMap<String, I> {}
|
||||
|
||||
impl Renderable for u32 {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: handle the filters
|
||||
Ok(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for &str {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: handle the filters
|
||||
Ok(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: ContextElement> Renderable for HashMap<&str, I> {
|
||||
impl<I: ContextElement> Renderable for HashMap<String, I> {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: handle the filters
|
||||
Ok("[object Object]".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: ContextElement> Walkable for HashMap<&str, I> {
|
||||
impl<I: ContextElement> Walkable for HashMap<String, I> {
|
||||
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<I: 'static + ContextElement + Clone> Loopable for HashMap<String, I> {
|
||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: ContextElement> Loopable for HashMap<&str, I> {
|
||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
vec![self]
|
||||
impl<I: 'static + ContextElement + Clone> CompareContextElement for HashMap<String, I> {
|
||||
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_walk_path() {
|
||||
let context: HashMap<&str, &str> =
|
||||
[("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")]
|
||||
let context: HashMap<String, String> = [
|
||||
("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<&str, u32> = [("cat", 1), ("dog", 2), ("tiger", 3)]
|
||||
let number_context: HashMap<String, u64> = [
|
||||
("cat".to_string(), 1),
|
||||
("dog".to_string(), 2),
|
||||
("tiger".to_string(), 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 deep_context: HashMap<String, HashMap<String, String>> = [
|
||||
(
|
||||
"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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user