diff options
author | Anthony Nowell <anowell@gmail.com> | 2017-10-05 02:47:36 -0600 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-11-02 14:58:46 +0100 |
commit | cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf (patch) | |
tree | f7c0c5ba23f1a6125846e248b73a8d273ebd7979 /testing/tests | |
parent | 751dee3fbabb35a8ad30ebdaee8e4dd4120c289a (diff) | |
download | askama-cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf.tar.gz askama-cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf.tar.bz2 askama-cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf.zip |
support literals in match arms
Diffstat (limited to 'testing/tests')
-rw-r--r-- | testing/tests/matches.rs | 32 |
1 files changed, 26 insertions, 6 deletions
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"); } |