From ed2e640dbdff88fe118d943fa0ea9ae00eb11555 Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 24 Aug 2021 23:51:05 +0200 Subject: Add test case for matching on Option --- testing/templates/match-opt-bool.html | 8 ++++++++ testing/tests/matches.rs | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 testing/templates/match-opt-bool.html (limited to 'testing') diff --git a/testing/templates/match-opt-bool.html b/testing/templates/match-opt-bool.html new file mode 100644 index 0000000..d2e4454 --- /dev/null +++ b/testing/templates/match-opt-bool.html @@ -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 %} diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index c328e39..206cd1d 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -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, +} + +#[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") }; -- cgit