aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-24 20:22:32 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-24 20:22:32 +0200
commitc8b14c6d0d61e12c45860c279f648ea6904488c3 (patch)
treece7ca24a838523520c2831556f4d89d8030280ce /testing
parent1c9066f9b40e0f4eb8fd67f6492efc96308eccd4 (diff)
downloadaskama-c8b14c6d0d61e12c45860c279f648ea6904488c3.tar.gz
askama-c8b14c6d0d61e12c45860c279f648ea6904488c3.tar.bz2
askama-c8b14c6d0d61e12c45860c279f648ea6904488c3.zip
Add test case for user-defined filters
Diffstat (limited to 'testing')
-rw-r--r--testing/tests/filters.rs19
1 files changed, 19 insertions, 0 deletions
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<String> {
+ Ok(s.replace("oo", "aa").to_string())
+ }
+}
+
+#[test]
+fn test_my_filter() {
+ let t = MyFilterTemplate { s: "foo" };
+ assert_eq!(t.render().unwrap(), "faa");
+}