diff options
Diffstat (limited to '')
-rw-r--r-- | testing/templates/match-custom-enum.html | 8 | ||||
-rw-r--r-- | testing/tests/matches.rs | 19 |
2 files changed, 27 insertions, 0 deletions
diff --git a/testing/templates/match-custom-enum.html b/testing/templates/match-custom-enum.html new file mode 100644 index 0000000..cb45b8f --- /dev/null +++ b/testing/templates/match-custom-enum.html @@ -0,0 +1,8 @@ +{% match color %} +{% when Color::Rgb with (r, g, b) %} +Colorful: #{{ "{:02X}"|format(r) }}{{ "{:02X}"|format(g) }}{{ "{:02X}"|format(b) }} +{% when Color::GrayScale with (val) %} +Gray: #{{ "{:02X}"|format(val) }}{{ "{:02X}"|format(val) }}{{ "{:02X}"|format(val) }} +{% else %} +CMYK not supported +{% endmatch %} diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index b8a6c98..86d32be 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -63,3 +63,22 @@ fn test_match_literal_num() { let s = MatchLitNumTemplate { item: 23 }; assert_eq!(s.render().unwrap(), "\n\nElse found 23\n"); } + +#[allow(dead_code)] +enum Color { + Rgb(u32, u32, u32), + GrayScale(u32), + Cmyk(u32, u32, u32, u32) +} + +#[derive(Template)] +#[template(path = "match-custom-enum.html")] +struct MatchCustomEnumTemplate { + color: Color, +} + +#[test] +fn test_match_custom_enum() { + let s = MatchCustomEnumTemplate { color: Color::Rgb(160, 0, 255) }; + assert_eq!(s.render().unwrap(), "\n\nColorful: #A000FF\n"); +} |