aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar PizzasBear <43722034+PizzasBear@users.noreply.github.com>2023-11-22 15:56:14 +0200
committerLibravatar GitHub <noreply@github.com>2023-11-22 14:56:14 +0100
commit48c6cd327d3c1df4218898be509250efcc56597c (patch)
tree6db2748a99e036960a0421070c222af096f040b7 /testing
parentea7267dfc2914cdc340bae1a823c0660daef19e6 (diff)
downloadaskama-48c6cd327d3c1df4218898be509250efcc56597c.tar.gz
askama-48c6cd327d3c1df4218898be509250efcc56597c.tar.bz2
askama-48c6cd327d3c1df4218898be509250efcc56597c.zip
Enhance match to include multiple targets (#911)
Signed-off-by: max <gmx.sht@gmail.com>
Diffstat (limited to 'testing')
-rw-r--r--testing/templates/match-enum-or.html8
-rw-r--r--testing/tests/matches.rs29
2 files changed, 37 insertions, 0 deletions
diff --git a/testing/templates/match-enum-or.html b/testing/templates/match-enum-or.html
new file mode 100644
index 0000000..ffd364d
--- /dev/null
+++ b/testing/templates/match-enum-or.html
@@ -0,0 +1,8 @@
+The card is
+{%- match suit %}
+ {%- when Suit::Clubs or Suit::Spades -%}
+ {{ " black" }}
+ {%- when Suit::Diamonds or Suit::Hearts -%}
+ {{ " red" }}
+{%- endmatch %}
+
diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs
index f5ccb95..4507489 100644
--- a/testing/tests/matches.rs
+++ b/testing/tests/matches.rs
@@ -195,3 +195,32 @@ fn test_match_with_comment() {
let s = MatchWithComment { good: false };
assert_eq!(s.render().unwrap(), "bad");
}
+
+enum Suit {
+ Clubs,
+ Diamonds,
+ Hearts,
+ Spades,
+}
+
+#[derive(Template)]
+#[template(path = "match-enum-or.html")]
+struct MatchEnumOrTemplate {
+ suit: Suit,
+}
+
+#[test]
+fn test_match_enum_or() {
+ let template = MatchEnumOrTemplate { suit: Suit::Clubs };
+ assert_eq!(template.render().unwrap(), "The card is black\n");
+ let template = MatchEnumOrTemplate { suit: Suit::Spades };
+ assert_eq!(template.render().unwrap(), "The card is black\n");
+
+ let template = MatchEnumOrTemplate { suit: Suit::Hearts };
+ assert_eq!(template.render().unwrap(), "The card is red\n");
+
+ let template = MatchEnumOrTemplate {
+ suit: Suit::Diamonds,
+ };
+ assert_eq!(template.render().unwrap(), "The card is red\n");
+}