From 48c5ebbd2be8f7d89f37f3aa04500b8ad1a3d460 Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 12 Dec 2018 20:43:36 +0100 Subject: Allow using brackets for enums in `match` --- testing/templates/match-custom-enum.html | 4 ++-- testing/tests/matches.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'testing') diff --git a/testing/templates/match-custom-enum.html b/testing/templates/match-custom-enum.html index cb45b8f..bec38b9 100644 --- a/testing/templates/match-custom-enum.html +++ b/testing/templates/match-custom-enum.html @@ -1,6 +1,6 @@ {% match color %} -{% when Color::Rgb with (r, g, b) %} -Colorful: #{{ "{:02X}"|format(r) }}{{ "{:02X}"|format(g) }}{{ "{:02X}"|format(b) }} +{% when Color::Rgb with {r, g: g, b: blue} %} +Colorful: #{{ "{:02X}"|format(r) }}{{ "{:02X}"|format(g) }}{{ "{:02X}"|format(blue) }} {% when Color::GrayScale with (val) %} Gray: #{{ "{:02X}"|format(val) }}{{ "{:02X}"|format(val) }}{{ "{:02X}"|format(val) }} {% else %} diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index 89082ef..8657fa5 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -62,7 +62,7 @@ fn test_match_literal_num() { #[allow(dead_code)] enum Color { - Rgb(u32, u32, u32), + Rgb { r: u32, g: u32, b: u32 }, GrayScale(u32), Cmyk(u32, u32, u32, u32), } @@ -76,7 +76,11 @@ struct MatchCustomEnumTemplate { #[test] fn test_match_custom_enum() { let s = MatchCustomEnumTemplate { - color: Color::Rgb(160, 0, 255), + color: Color::Rgb { + r: 160, + g: 0, + b: 255, + }, }; assert_eq!(s.render().unwrap(), "\n\nColorful: #A000FF\n"); } -- cgit