duster/src/renderer/renderer.rs

713 lines
28 KiB
Rust
Raw Normal View History

use crate::parser::template;
use crate::parser::Body;
use crate::parser::DustTag;
2020-05-10 18:22:59 +00:00
use crate::parser::KVPair;
use crate::parser::PartialNameElement;
2020-05-10 18:22:59 +00:00
use crate::parser::RValue;
2020-05-03 18:52:08 +00:00
use crate::parser::Special;
use crate::parser::Template;
use crate::parser::{Filter, TemplateElement};
use crate::renderer::context_element::ContextElement;
2020-04-11 22:25:48 +00:00
use crate::renderer::errors::CompileError;
use crate::renderer::errors::RenderError;
use crate::renderer::errors::WalkError;
2020-05-10 02:05:43 +00:00
use crate::renderer::inline_partial_tree::extract_inline_partials;
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
use crate::renderer::parameters_context::ParametersContext;
2020-05-09 18:53:53 +00:00
use crate::renderer::walking::walk_path;
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct CompiledTemplate<'a> {
template: Template<'a>,
2020-04-11 22:25:48 +00:00
pub name: String,
}
#[derive(Clone, Debug)]
2020-04-11 00:58:55 +00:00
pub struct DustRenderer<'a> {
2020-04-11 22:25:48 +00:00
templates: HashMap<String, &'a Template<'a>>,
}
2020-04-11 22:25:48 +00:00
pub fn compile_template<'a>(
source: &'a str,
name: String,
) -> Result<CompiledTemplate<'a>, CompileError> {
// TODO: Make this all consuming
2020-04-11 22:25:48 +00:00
// TODO: This could use better error management
let (_remaining, parsed_template) = template(source).expect("Failed to compile template");
2020-04-11 22:25:48 +00:00
Ok(CompiledTemplate {
template: parsed_template,
name: name,
2020-04-11 22:25:48 +00:00
})
}
2020-04-11 00:58:55 +00:00
impl<'a> DustRenderer<'a> {
pub fn new() -> DustRenderer<'a> {
DustRenderer {
2020-04-11 22:25:48 +00:00
templates: HashMap::new(),
}
}
pub fn load_source(&mut self, template: &'a CompiledTemplate) {
2020-04-11 22:25:48 +00:00
self.templates
.insert(template.name.clone(), &template.template);
}
2020-04-11 00:58:55 +00:00
pub fn render(
2020-05-05 23:51:07 +00:00
&'a self,
name: &str,
breadcrumbs: &Vec<&'a dyn ContextElement>,
2020-05-10 02:05:43 +00:00
) -> Result<String, RenderError> {
self.render_template(name, breadcrumbs, None)
}
fn render_template(
&'a self,
name: &str,
breadcrumbs: &Vec<&'a dyn ContextElement>,
blocks: Option<&'a InlinePartialTreeElement<'a>>,
2020-05-09 18:27:42 +00:00
) -> Result<String, RenderError> {
2020-05-05 23:51:07 +00:00
let main_template = match self.templates.get(name) {
Some(tmpl) => tmpl,
None => {
2020-05-09 18:27:42 +00:00
return Err(RenderError::TemplateNotFound(name.to_owned()));
2020-05-05 23:51:07 +00:00
}
};
2020-05-10 02:05:43 +00:00
let extracted_inline_partials = extract_inline_partials(main_template);
let new_blocks = InlinePartialTreeElement::new(blocks, extracted_inline_partials);
self.render_body(&main_template.contents, breadcrumbs, &new_blocks)
2020-05-05 23:51:07 +00:00
}
fn render_maybe_body(
&'a self,
body: &'a Option<Body>,
breadcrumbs: &Vec<&'a dyn ContextElement>,
blocks: &'a InlinePartialTreeElement<'a>,
) -> Result<String, RenderError> {
match body {
None => Ok("".to_owned()),
Some(body) => Ok(self.render_body(body, breadcrumbs, blocks)?),
}
}
fn render_body(
2020-05-05 23:51:07 +00:00
&'a self,
body: &'a Body,
breadcrumbs: &Vec<&'a dyn ContextElement>,
blocks: &'a InlinePartialTreeElement<'a>,
2020-05-09 18:27:42 +00:00
) -> Result<String, RenderError> {
2020-05-05 23:51:07 +00:00
let mut output = String::new();
for elem in &body.elements {
match elem {
TemplateElement::TEIgnoredWhitespace(_) => {}
TemplateElement::TESpan(span) => output.push_str(span.contents),
TemplateElement::TETag(dt) => {
output.push_str(&self.render_tag(dt, breadcrumbs, blocks)?);
2020-05-05 23:51:07 +00:00
}
}
}
Ok(output)
}
fn render_partial_name(
&'a self,
body: &'a Vec<PartialNameElement>,
breadcrumbs: &Vec<&'a dyn ContextElement>,
blocks: &'a InlinePartialTreeElement<'a>,
) -> Result<String, RenderError> {
let converted_to_template_elements: Vec<TemplateElement<'a>> =
body.into_iter().map(|e| e.into()).collect();
self.render_body(
&Body {
elements: converted_to_template_elements,
},
breadcrumbs,
blocks,
)
}
fn render_tag(
2020-05-05 23:51:07 +00:00
&'a self,
tag: &'a DustTag,
breadcrumbs: &Vec<&'a dyn ContextElement>,
blocks: &'a InlinePartialTreeElement<'a>,
2020-05-09 18:27:42 +00:00
) -> Result<String, RenderError> {
2020-05-05 23:51:07 +00:00
match tag {
DustTag::DTComment(_comment) => (),
DustTag::DTSpecial(special) => {
return Ok(match special {
Special::Space => " ",
Special::NewLine => "\n",
Special::CarriageReturn => "\r",
Special::LeftCurlyBrace => "{",
Special::RightCurlyBrace => "}",
}
.to_owned())
}
2020-05-24 03:41:05 +00:00
DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()),
2020-05-05 23:51:07 +00:00
DustTag::DTReference(reference) => {
let val = walk_path(breadcrumbs, &reference.path.keys);
match val {
2020-05-09 18:10:38 +00:00
Err(WalkError::CantWalk) => return Ok("".to_owned()),
Ok(final_val) => {
2020-05-09 18:18:45 +00:00
let loop_elements = final_val.get_loop_elements();
if loop_elements.is_empty() {
return Ok("".to_owned());
} else {
return final_val.render(&Self::preprocess_filters(&reference.filters));
}
}
2020-05-05 23:51:07 +00:00
}
}
DustTag::DTSection(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
2020-05-05 23:51:07 +00:00
if loop_elements.is_empty() {
// Oddly enough if the value is falsey (like
// an empty array or null), Dust uses the
// original context before walking the path as
// the context for rendering the else block
return self.render_maybe_body(&container.else_contents, breadcrumbs, blocks);
2020-05-05 23:51:07 +00:00
} else {
match &container.contents {
None => return Ok("".to_owned()),
Some(body) => {
let rendered_results: Result<Vec<String>, RenderError> = loop_elements
.into_iter()
.map(|array_elem| {
let mut new_breadcumbs = breadcrumbs.clone();
new_breadcumbs.push(array_elem);
self.render_body(&body, &new_breadcumbs, blocks)
2020-05-05 23:51:07 +00:00
})
.collect();
let rendered_slice: &[String] = &rendered_results?;
return Ok(rendered_slice.join(""));
}
}
}
}
2020-05-06 23:10:09 +00:00
DustTag::DTExists(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
return if loop_elements.is_empty() {
self.render_maybe_body(&container.else_contents, breadcrumbs, blocks)
2020-05-06 23:10:09 +00:00
} else {
self.render_maybe_body(&container.contents, breadcrumbs, blocks)
};
2020-05-06 23:10:09 +00:00
}
DustTag::DTNotExists(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
return if !loop_elements.is_empty() {
self.render_maybe_body(&container.else_contents, breadcrumbs, blocks)
} else {
self.render_maybe_body(&container.contents, breadcrumbs, blocks)
};
}
DustTag::DTPartial(partial) => {
let partial_name = self.render_partial_name(&partial.name, breadcrumbs, blocks)?;
if partial.params.is_empty() {
let rendered_content =
self.render_template(&partial_name, breadcrumbs, Some(blocks))?;
return Ok(rendered_content);
} else {
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
let mut new_breadcrumbs = breadcrumbs.clone();
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context);
let rendered_content =
self.render_template(&partial_name, &new_breadcrumbs, Some(blocks))?;
return Ok(rendered_content);
}
}
DustTag::DTInlinePartial(_named_block) => {
// Inline partials are blank during rendering (they get injected into blocks)
return Ok("".to_owned());
}
DustTag::DTBlock(named_block) => {
return match blocks.get_block(named_block.name) {
None => self.render_maybe_body(&named_block.contents, breadcrumbs, blocks),
Some(interior) => self.render_maybe_body(interior, breadcrumbs, blocks),
};
}
2020-05-10 18:22:59 +00:00
DustTag::DTHelperEquals(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
// Special case: when comparing two RVPaths, if the
// path is equal then dust assumes the values are
// equal (otherwise, non-scalar values are
// automatically not equal)
if Self::are_paths_identical(&param_map) {
return match &parameterized_block.contents {
None => Ok("".to_owned()),
Some(body) => {
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
Ok(rendered_content)
}
};
}
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
2020-05-10 18:22:59 +00:00
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
2020-05-11 01:00:52 +00:00
if left_side == right_side {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
2020-05-11 01:14:51 +00:00
} else {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
2020-05-16 16:26:28 +00:00
}
}
DustTag::DTHelperNotEquals(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
// Special case: when comparing two RVPaths, if the
// path is equal then dust assumes the values are
// equal (otherwise, non-scalar values are
// automatically not equal)
if Self::are_paths_identical(&param_map) {
return match &parameterized_block.else_contents {
None => Ok("".to_owned()),
Some(body) => {
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
Ok(rendered_content)
}
};
}
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
2020-05-16 16:26:28 +00:00
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
2020-05-16 16:26:28 +00:00
if left_side != right_side {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
2020-05-16 16:26:28 +00:00
} else {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
2020-05-10 23:16:55 +00:00
}
2020-05-10 18:22:59 +00:00
}
2020-05-16 19:45:57 +00:00
DustTag::DTHelperGreaterThan(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
)
}
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped > right_side_unwrapped {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
} else {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
}
}
}
2020-05-16 19:45:57 +00:00
}
2020-05-16 23:05:03 +00:00
DustTag::DTHelperGreaterThanOrEquals(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
)
}
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped >= right_side_unwrapped {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
} else {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
}
}
}
}
2020-05-16 23:05:03 +00:00
DustTag::DTHelperLessThan(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
)
}
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped < right_side_unwrapped {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
} else {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
}
}
}
}
2020-05-16 23:06:40 +00:00
DustTag::DTHelperLessThanOrEquals(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
)
}
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped <= right_side_unwrapped {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
} else {
return self.render_maybe_body(
2020-05-16 23:06:40 +00:00
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
}
2020-05-16 23:06:40 +00:00
}
}
}
2020-05-05 23:51:07 +00:00
}
Ok("".to_owned())
}
/// Gets the elements to loop over for a section.
///
/// If the value is falsey, and therefore should render the else
/// block, this will return an empty vector.
fn get_loop_elements<'b>(
2020-05-09 18:14:22 +00:00
walk_result: Result<&'b dyn ContextElement, WalkError>,
) -> Vec<&'b dyn ContextElement> {
match walk_result {
Err(WalkError::CantWalk) => Vec::new(),
Ok(walk_target) => walk_target.get_loop_elements(),
}
}
fn are_paths_identical<'b>(param_map: &HashMap<&str, &RValue<'b>>) -> bool {
match (param_map.get("key"), param_map.get("value")) {
(None, _) => false,
(_, None) => false,
(Some(key_rval), Some(value_rval)) => match (key_rval, value_rval) {
(RValue::RVPath(key_path), RValue::RVPath(value_path)) => {
key_path.keys == value_path.keys
}
_ => false,
},
}
}
fn get_rval_map<'b>(params: &'b Vec<KVPair<'b>>) -> HashMap<&'b str, &'b RValue<'b>> {
params
.iter()
.map(|pair: &KVPair<'b>| (pair.key, &pair.value))
.collect()
}
fn get_rval<'b>(
breadcrumbs: &Vec<&'b dyn ContextElement>,
param_map: &HashMap<&str, &'b RValue<'b>>,
key: &str,
) -> Option<Result<&'b dyn ContextElement, WalkError>> {
match param_map.get(key) {
None => None,
Some(rval) => match rval {
RValue::RVLiteral(literal) => Some(Ok(literal)),
RValue::RVPath(path) => Some(walk_path(breadcrumbs, &path.keys)),
},
}
}
fn preprocess_filters(filters: &Vec<Filter>) -> Vec<Filter> {
let mut final_filters: Vec<Filter> = filters
.into_iter()
.filter(|f| f != &&Filter::DisableHtmlEncode)
.map(|f| f.clone())
.collect();
// If the user has not specified any escaping filter (|s or
// |h), automatically add an html escape filter
if !filters.iter().any(|f| f == &Filter::DisableHtmlEncode) {
final_filters.push(Filter::HtmlEncode);
}
final_filters
}
}
2020-04-12 00:31:44 +00:00
#[cfg(test)]
mod tests {
use super::*;
use crate::parser::Filter;
use crate::renderer::context_element::Loopable;
use crate::renderer::context_element::Renderable;
use crate::renderer::context_element::Walkable;
2020-05-11 03:26:15 +00:00
use crate::renderer::CompareContextElement;
use std::cmp::Ordering;
2020-04-12 00:31:44 +00:00
2020-05-17 02:39:29 +00:00
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),
}
}
}
2020-05-11 03:26:15 +00:00
impl<I: 'static + ContextElement + Clone> ContextElement for HashMap<String, I> {}
2020-05-11 03:26:15 +00:00
impl<I: ContextElement> Renderable for HashMap<String, I> {
2020-05-06 00:22:25 +00:00
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
// TODO: handle the filters
2020-05-09 17:46:12 +00:00
Ok("[object Object]".to_owned())
2020-04-12 00:31:44 +00:00
}
2020-05-06 00:22:25 +00:00
}
2020-04-12 00:31:44 +00:00
2020-05-11 03:26:15 +00:00
impl<I: ContextElement> Walkable for HashMap<String, I> {
2020-05-09 18:22:36 +00:00
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
let child = self.get(segment).ok_or(WalkError::CantWalk)?;
2020-05-06 00:22:25 +00:00
Ok(child)
2020-04-12 01:07:12 +00:00
}
2020-05-06 00:22:25 +00:00
}
2020-04-12 01:07:12 +00:00
2020-05-11 03:26:15 +00:00
impl<I: 'static + ContextElement + Clone> Loopable for HashMap<String, I> {
2020-05-09 18:22:36 +00:00
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
vec![self]
}
2020-05-06 00:22:25 +00:00
}
2020-05-11 03:26:15 +00:00
impl<I: 'static + ContextElement + Clone> CompareContextElement for HashMap<String, I> {
fn equals(&self, other: &dyn ContextElement) -> bool {
false
2020-05-06 00:22:25 +00:00
}
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
// TODO: Implement
None
}
2020-05-06 00:22:25 +00:00
}
#[test]
2020-05-06 00:43:53 +00:00
fn test_walk_path() {
2020-05-11 03:26:15 +00:00
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<String, u64> = [
("cat".to_string(), 1),
("dog".to_string(), 2),
("tiger".to_string(), 3),
]
.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(),
),
2020-05-06 00:22:25 +00:00
]
.iter()
.cloned()
.collect();
assert_eq!(
walk_path(&vec![&context as &dyn ContextElement], &vec!["cat"])
2020-05-06 00:22:25 +00:00
.unwrap()
.render(&Vec::new())
.unwrap(),
"kitty".to_owned()
);
2020-05-06 00:38:42 +00:00
assert_eq!(
walk_path(
2020-05-06 00:38:42 +00:00
&vec![&number_context as &dyn ContextElement],
&vec!["tiger"]
)
.unwrap()
.render(&Vec::new())
.unwrap(),
"3".to_owned()
);
assert_eq!(
walk_path(
2020-05-06 00:38:42 +00:00
&vec![&deep_context as &dyn ContextElement],
&vec!["tiger", "food"]
)
.unwrap()
.render(&Vec::new())
.unwrap(),
"people".to_owned()
);
2020-05-06 00:22:25 +00:00
}
2020-04-12 00:31:44 +00:00
}