Moving the custom types for the walk_path test inside the test function

This commit is contained in:
Tom Alexander 2020-04-11 22:54:48 -04:00
parent 273f6204d8
commit 869c32df21
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 40 additions and 40 deletions

View File

@ -107,48 +107,48 @@ fn walk_path<'a>(context: &'a dyn ContextElement, path: &Vec<&str>) -> &'a dyn C
mod tests {
use super::*;
impl ContextElement for u32 {}
impl ContextElement for &str {}
impl<I: ContextElement> ContextElement for HashMap<&str, I> {}
impl Renderable for u32 {
fn render(&self) -> std::string::String {
self.to_string()
}
}
impl Renderable for &str {
fn render(&self) -> std::string::String {
self.to_string()
}
}
impl<I: ContextElement> Renderable for HashMap<&str, I> {
fn render(&self) -> std::string::String {
panic!("Attempted to render a hashmap");
}
}
impl<I: ContextElement> Walkable for HashMap<&str, I> {
fn walk(&self, segment: &str) -> &dyn ContextElement {
self.get(segment).unwrap()
}
}
impl Walkable for &str {
fn walk(&self, _segment: &str) -> &dyn ContextElement {
panic!("Tried to walk down a str");
}
}
impl Walkable for u32 {
fn walk(&self, _segment: &str) -> &dyn ContextElement {
panic!("Tried to walk down a str");
}
}
#[test]
fn test_walk_path() {
impl ContextElement for u32 {}
impl ContextElement for &str {}
impl<I: ContextElement> ContextElement for HashMap<&str, I> {}
impl Renderable for u32 {
fn render(&self) -> std::string::String {
self.to_string()
}
}
impl Renderable for &str {
fn render(&self) -> std::string::String {
self.to_string()
}
}
impl<I: ContextElement> Renderable for HashMap<&str, I> {
fn render(&self) -> std::string::String {
panic!("Attempted to render a hashmap");
}
}
impl<I: ContextElement> Walkable for HashMap<&str, I> {
fn walk(&self, segment: &str) -> &dyn ContextElement {
self.get(segment).unwrap()
}
}
impl Walkable for &str {
fn walk(&self, _segment: &str) -> &dyn ContextElement {
panic!("Tried to walk down a str");
}
}
impl Walkable for u32 {
fn walk(&self, _segment: &str) -> &dyn ContextElement {
panic!("Tried to walk down a str");
}
}
let context: HashMap<&str, &str> =
[("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")]
.iter()