2018-06-26 17:22:19 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate strum_macros;
|
|
|
|
|
2018-09-26 21:13:45 +02:00
|
|
|
#[derive(Debug, Eq, PartialEq, AsRefStr)]
|
2018-06-26 17:22:19 +02:00
|
|
|
enum Color {
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(to_string = "RedRed")]
|
2018-06-26 17:22:19 +02:00
|
|
|
Red,
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(serialize = "b", to_string = "blue")]
|
2018-06-26 17:22:19 +02:00
|
|
|
Blue { hue: usize },
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(serialize = "y", serialize = "yellow")]
|
2018-06-26 17:22:19 +02:00
|
|
|
Yellow,
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(default = "true")]
|
2018-06-26 17:22:19 +02:00
|
|
|
Green(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn as_red_str() {
|
|
|
|
assert_eq!("RedRed", (Color::Red).as_ref());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn as_blue_str() {
|
|
|
|
assert_eq!("blue", (Color::Blue { hue: 0 }).as_ref());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn as_yellow_str() {
|
|
|
|
assert_eq!("yellow", (Color::Yellow).as_ref());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn as_green_str() {
|
|
|
|
assert_eq!("Green", (Color::Green(String::default())).as_ref());
|
|
|
|
}
|