diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-24 20:22:32 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-24 20:22:32 +0200 |
commit | c8b14c6d0d61e12c45860c279f648ea6904488c3 (patch) | |
tree | ce7ca24a838523520c2831556f4d89d8030280ce | |
parent | 1c9066f9b40e0f4eb8fd67f6492efc96308eccd4 (diff) | |
download | askama-c8b14c6d0d61e12c45860c279f648ea6904488c3.tar.gz askama-c8b14c6d0d61e12c45860c279f648ea6904488c3.tar.bz2 askama-c8b14c6d0d61e12c45860c279f648ea6904488c3.zip |
Add test case for user-defined filters
-rw-r--r-- | testing/tests/filters.rs | 19 |
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"); +} |