aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_shared/src/parser.rs2
-rw-r--r--testing/tests/matches.rs17
2 files changed, 18 insertions, 1 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs
index d2b2cd1..29b325d 100644
--- a/askama_shared/src/parser.rs
+++ b/askama_shared/src/parser.rs
@@ -550,7 +550,7 @@ fn parameters(i: &[u8]) -> IResult<&[u8], Vec<&str>> {
fn with_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters<'_>> {
let (i, (_, value)) = tuple((
- tag("with"),
+ opt(tag("with")),
alt((match_simple_parameters, match_named_parameters)),
))(i)?;
Ok((i, value))
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<usize>,
+}
+
+#[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(), "");
+}