From c8b14c6d0d61e12c45860c279f648ea6904488c3 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 24 Aug 2017 20:22:32 +0200 Subject: Add test case for user-defined filters --- testing/tests/filters.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'testing') diff --git a/testing/tests/filters.rs b/testing/tests/filters.rs index 665e50d..524014e 100644 --- a/testing/tests/filters.rs +++ b/testing/tests/filters.rs @@ -30,3 +30,22 @@ fn filter_format() { let t = FormatTemplate { var: "formatted" }; assert_eq!(t.render().unwrap(), "\"formatted\""); } + + +#[derive(Template)] +#[template(source = "{{ s|myfilter }}")] +struct MyFilterTemplate<'a> { + s: &'a str, +} + +mod filters { + pub fn myfilter(s: &str) -> ::askama::Result { + Ok(s.replace("oo", "aa").to_string()) + } +} + +#[test] +fn test_my_filter() { + let t = MyFilterTemplate { s: "foo" }; + assert_eq!(t.render().unwrap(), "faa"); +} -- cgit