Add test case for matching on Option<bool>

This commit is contained in:
Restioson 2021-08-24 23:51:05 +02:00 committed by Dirkjan Ochtman
parent 35cf03cf79
commit ed2e640dbd
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,8 @@
{% match item %}
{% when Some with (true) %}
Found Some(true)
{% when Some with (false) %}
Found Some(false)
{% when None %}
Not Found
{% endmatch %}

View File

@ -26,6 +26,24 @@ fn test_match_option() {
assert_eq!(s.render().unwrap(), "\nNot Found\n");
}
#[derive(Template)]
#[template(path = "match-opt-bool.html")]
struct MatchOptBoolTemplate {
item: Option<bool>,
}
#[test]
fn test_match_option_bool() {
let s = MatchOptBoolTemplate { item: Some(true) };
assert_eq!(s.render().unwrap(), "\nFound Some(true)\n");
let s = MatchOptBoolTemplate { item: Some(false) };
assert_eq!(s.render().unwrap(), "\nFound Some(false)\n");
let s = MatchOptBoolTemplate { item: None };
assert_eq!(s.render().unwrap(), "\nNot Found\n");
}
#[test]
fn test_match_ref_deref() {
let s = MatchOptRefTemplate { item: &Some("foo") };