From 8063e112a66d9b31f05315ccd2f8374d1c7d8d31 Mon Sep 17 00:00:00 2001 From: vallentin Date: Thu, 18 Nov 2021 08:25:37 +0100 Subject: Added optional escaper tests --- testing/tests/filters.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'testing/tests') 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 @@ -26,6 +26,54 @@ fn filter_escape() { ); } +#[derive(Template)] +#[template( + source = "{{ \"

Foo Bar

\"|escape(\"none\") }} +{{ \"

Foo Bar

\"|escape(\"html\") }} +{{ \"

Foo Bar

\"|escape }} +{{ \"

Foo Bar

\" }} +", + ext = "txt", + escape = "none" +)] +struct OptEscaperNoneTemplate; + +#[test] +fn filter_opt_escaper_none() { + let t = OptEscaperNoneTemplate; + assert_eq!( + t.render().unwrap(), + r#"

Foo Bar

+<h1 class="title">Foo Bar</h1> +

Foo Bar

+

Foo Bar

"# + ); +} + +#[derive(Template)] +#[template( + source = "{{ \"

Foo Bar

\"|escape(\"none\") }} +{{ \"

Foo Bar

\"|escape(\"html\") }} +{{ \"

Foo Bar

\"|escape }} +{{ \"

Foo Bar

\" }} +", + ext = "txt", + escape = "html" +)] +struct OptEscaperHtmlTemplate; + +#[test] +fn filter_opt_escaper_html() { + let t = OptEscaperHtmlTemplate; + assert_eq!( + t.render().unwrap(), + r#"

Foo Bar

+<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> { -- cgit