From cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf Mon Sep 17 00:00:00 2001 From: Anthony Nowell Date: Thu, 5 Oct 2017 02:47:36 -0600 Subject: support literals in match arms --- testing/templates/match-literal.html | 8 ++++++++ testing/templates/match-opt.html | 8 ++++++++ testing/templates/match.html | 6 ------ testing/tests/matches.rs | 32 ++++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 testing/templates/match-literal.html create mode 100644 testing/templates/match-opt.html delete mode 100644 testing/templates/match.html (limited to 'testing') diff --git a/testing/templates/match-literal.html b/testing/templates/match-literal.html new file mode 100644 index 0000000..22203f4 --- /dev/null +++ b/testing/templates/match-literal.html @@ -0,0 +1,8 @@ +{% match item %} +{% when "foo" %} +Found literal foo +{% when "bar" %} +Found literal bar +{% else %} +Else found {{item}} +{% endmatch %} diff --git a/testing/templates/match-opt.html b/testing/templates/match-opt.html new file mode 100644 index 0000000..c77a2a6 --- /dev/null +++ b/testing/templates/match-opt.html @@ -0,0 +1,8 @@ +{% match item %} +{% when Some with ("foo") %} +Found literal foo +{% when Some with (val) %} +Found {{val}} +{% when None %} +Not Found +{% endmatch %} diff --git a/testing/templates/match.html b/testing/templates/match.html deleted file mode 100644 index 51950b4..0000000 --- a/testing/templates/match.html +++ /dev/null @@ -1,6 +0,0 @@ -{% match item %} -{% when Some with (val) %} -Found {{val}} -{% when None %} -Not Found -{% endmatch %} diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index 4a55615..4f159ab 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -4,15 +4,35 @@ extern crate askama; use askama::Template; #[derive(Template)] -#[template(path = "match.html")] -struct MatchTemplate<'a> { +#[template(path = "match-opt.html")] +struct MatchOptTemplate<'a> { item: Option<&'a str>, } #[test] fn test_match_option() { - let s = MatchTemplate { - item: Some("foo"), - }; - assert_eq!(s.render().unwrap(), "\n\nFound foo\n"); + let s = MatchOptTemplate { item: Some("foo") }; + assert_eq!(s.render().unwrap(), "\n\nFound literal foo\n"); + + let s = MatchOptTemplate { item: Some("bar") }; + assert_eq!(s.render().unwrap(), "\n\nFound bar\n"); + + let s = MatchOptTemplate { item: None }; + assert_eq!(s.render().unwrap(), "\n\nNot Found\n"); +} + + +#[derive(Template)] +#[template(path = "match-literal.html")] +struct MatchLitTemplate<'a> { + item: &'a str, +} + +#[test] +fn test_match_literal() { + let s = MatchLitTemplate { item: "bar" }; + assert_eq!(s.render().unwrap(), "\n\nFound literal bar\n"); + + let s = MatchLitTemplate { item: "qux" }; + assert_eq!(s.render().unwrap(), "\n\nElse found qux\n"); } -- cgit