Add test for nested filters with references (see #76)

This commit is contained in:
Dirkjan Ochtman 2018-04-17 17:16:24 +02:00
parent 6f0739eedb
commit 02266bed68

View File

@ -49,6 +49,11 @@ mod filters {
pub fn myfilter(s: &str) -> ::askama::Result<String> {
Ok(s.replace("oo", "aa").to_string())
}
// for test_nested_filter_ref
pub fn mytrim(s: &::std::fmt::Display) -> ::askama::Result<String> {
let s = format!("{}", s);
Ok(s.trim().to_owned())
}
}
#[test]
@ -110,3 +115,16 @@ fn test_json() {
}"#
);
}
#[derive(Template)]
#[template(source = "{{ x|mytrim|safe }}", ext = "html")]
struct NestedFilterTemplate {
x: String,
}
#[test]
fn test_nested_filter_ref() {
let t = NestedFilterTemplate { x: " floo & bar".to_string() };
assert_eq!(t.render().unwrap(), "floo & bar");
}