diff options
author | vallentin <mail@vallentin.dev> | 2021-11-18 08:25:37 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-11-19 15:30:10 +0100 |
commit | 8063e112a66d9b31f05315ccd2f8374d1c7d8d31 (patch) | |
tree | 2ce4f861e212c7dd1ea0b371a4efeb9ad90947d1 /testing | |
parent | 8a5ff3b41298ebbdd32ac6e74421704d06864a94 (diff) | |
download | askama-8063e112a66d9b31f05315ccd2f8374d1c7d8d31.tar.gz askama-8063e112a66d9b31f05315ccd2f8374d1c7d8d31.tar.bz2 askama-8063e112a66d9b31f05315ccd2f8374d1c7d8d31.zip |
Added optional escaper tests
Diffstat (limited to 'testing')
-rw-r--r-- | testing/tests/filters.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/testing/tests/filters.rs b/testing/tests/filters.rs index 1f382f6..be3e0ab 100644 --- a/testing/tests/filters.rs +++ b/testing/tests/filters.rs @@ -27,6 +27,54 @@ fn filter_escape() { } #[derive(Template)] +#[template( + source = "{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\"|escape(\"none\") }} +{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\"|escape(\"html\") }} +{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\"|escape }} +{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\" }} +", + ext = "txt", + escape = "none" +)] +struct OptEscaperNoneTemplate; + +#[test] +fn filter_opt_escaper_none() { + let t = OptEscaperNoneTemplate; + assert_eq!( + t.render().unwrap(), + r#"<h1 class="title">Foo Bar</h1> +<h1 class="title">Foo Bar</h1> +<h1 class="title">Foo Bar</h1> +<h1 class="title">Foo Bar</h1>"# + ); +} + +#[derive(Template)] +#[template( + source = "{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\"|escape(\"none\") }} +{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\"|escape(\"html\") }} +{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\"|escape }} +{{ \"<h1 class=\\\"title\\\">Foo Bar</h1>\" }} +", + ext = "txt", + escape = "html" +)] +struct OptEscaperHtmlTemplate; + +#[test] +fn filter_opt_escaper_html() { + let t = OptEscaperHtmlTemplate; + assert_eq!( + t.render().unwrap(), + r#"<h1 class="title">Foo Bar</h1> +<h1 class="title">Foo Bar</h1> +<h1 class="title">Foo Bar</h1> +<h1 class="title">Foo Bar</h1>"# + ); +} + +#[derive(Template)] #[template(path = "format.html", escape = "none")] struct FormatTemplate<'a> { var: &'a str, |