From 1622df7aeecb71fca2da630330513b26cefef16b Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Fri, 16 Jul 2021 16:23:31 +0200 Subject: Allow omitting "with" keyword in match blocks Askama uses the syntax `{% when Variant with (parameters) %}` in `{% match %}` blocks. This is done because Askama does not implement the whole pattern matching of Rust's `match` statements. This PR wants to bring Askama a step closer Rust's matching, so the "with" keyword should not be needed anymore. --- testing/tests/matches.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'testing') diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index d75a6c4..380a69c 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -113,3 +113,20 @@ fn test_match_no_whitespace() { let s = MatchNoWhitespace { foo: Some(1) }; assert_eq!(s.render().unwrap(), "1"); } + +#[derive(Template)] +#[template( + source = "{% match foo %}{% when Some(bar) %}{{ bar }}{% when None %}{% endmatch %}", + ext = "txt" +)] +struct MatchWithoutWithKeyword { + foo: Option, +} + +#[test] +fn test_match_without_with_keyword() { + let s = MatchWithoutWithKeyword { foo: Some(1) }; + assert_eq!(s.render().unwrap(), "1"); + let s = MatchWithoutWithKeyword { foo: None }; + assert_eq!(s.render().unwrap(), ""); +} -- cgit