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::Loopable;
|
||||||
use crate::renderer::context_element::Renderable;
|
use crate::renderer::context_element::Renderable;
|
||||||
use crate::renderer::context_element::Walkable;
|
use crate::renderer::context_element::Walkable;
|
||||||
|
use crate::renderer::CompareContextElement;
|
||||||
|
|
||||||
impl ContextElement for u32 {}
|
impl<I: 'static + ContextElement + Clone> ContextElement for HashMap<String, I> {}
|
||||||
impl ContextElement for &str {}
|
|
||||||
impl<I: ContextElement> ContextElement for HashMap<&str, I> {}
|
|
||||||
|
|
||||||
impl Renderable for u32 {
|
impl<I: ContextElement> Renderable for HashMap<String, I> {
|
||||||
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> {
|
|
||||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||||
// TODO: handle the filters
|
// TODO: handle the filters
|
||||||
Ok("[object Object]".to_owned())
|
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> {
|
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||||
let child = self.get(segment).ok_or(WalkError::CantWalk)?;
|
let child = self.get(segment).ok_or(WalkError::CantWalk)?;
|
||||||
Ok(child)
|
Ok(child)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Walkable for &str {
|
impl<I: 'static + ContextElement + Clone> Loopable for HashMap<String, I> {
|
||||||
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 {
|
|
||||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: ContextElement> Loopable for HashMap<&str, I> {
|
impl<I: 'static + ContextElement + Clone> CompareContextElement for HashMap<String, I> {
|
||||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||||
vec![self]
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_walk_path() {
|
fn test_walk_path() {
|
||||||
let context: HashMap<&str, &str> =
|
let context: HashMap<String, String> = [
|
||||||
[("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")]
|
("cat".to_string(), "kitty".to_string()),
|
||||||
|
("dog".to_string(), "doggy".to_string()),
|
||||||
|
("tiger".to_string(), "murderkitty".to_string()),
|
||||||
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.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()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
let deep_context: HashMap<&str, HashMap<&str, &str>> = [
|
let deep_context: HashMap<String, HashMap<String, String>> = [
|
||||||
("cat", [("food", "meat")].iter().cloned().collect()),
|
(
|
||||||
("dog", [("food", "meat")].iter().cloned().collect()),
|
"cat".to_string(),
|
||||||
("tiger", [("food", "people")].iter().cloned().collect()),
|
[("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()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user