2017-04-16 03:08:49 +02:00
|
|
|
extern crate strum;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate strum_macros;
|
|
|
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
use std::string::ToString;
|
|
|
|
|
2018-09-26 21:13:45 +02:00
|
|
|
#[derive(Debug, Eq, PartialEq, EnumString, ToString)]
|
2017-04-16 03:08:49 +02:00
|
|
|
enum Color {
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(to_string = "RedRed")]
|
2017-04-16 03:08:49 +02:00
|
|
|
Red,
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(serialize = "b", to_string = "blue")]
|
2017-04-16 03:08:49 +02:00
|
|
|
Blue { hue: usize },
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(serialize = "y", serialize = "yellow")]
|
2017-04-16 03:08:49 +02:00
|
|
|
Yellow,
|
2020-07-29 18:36:48 +02:00
|
|
|
#[strum(default)]
|
2017-04-16 03:08:49 +02:00
|
|
|
Green(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_blue_string() {
|
2018-09-26 21:13:45 +02:00
|
|
|
assert_eq!(
|
|
|
|
String::from("blue"),
|
|
|
|
(Color::Blue { hue: 0 }).to_string().as_ref()
|
|
|
|
);
|
2017-04-16 03:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_yellow_string() {
|
|
|
|
assert_eq!(String::from("yellow"), (Color::Yellow).to_string().as_ref());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_red_string() {
|
2017-08-24 04:18:23 +02:00
|
|
|
assert_eq!(String::from("RedRed"), (Color::Red).to_string());
|
2018-09-26 21:13:45 +02:00
|
|
|
assert_eq!(
|
|
|
|
Color::Red,
|
|
|
|
Color::from_str((Color::Red).to_string().as_ref()).unwrap()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, ToString)]
|
|
|
|
#[strum(serialize_all = "snake_case")]
|
|
|
|
enum Brightness {
|
|
|
|
DarkBlack,
|
|
|
|
Dim {
|
|
|
|
glow: usize,
|
|
|
|
},
|
|
|
|
#[strum(serialize = "bright")]
|
|
|
|
BrightWhite,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn brightness_to_string() {
|
|
|
|
assert_eq!(
|
|
|
|
String::from("dark_black"),
|
|
|
|
Brightness::DarkBlack.to_string().as_ref()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
String::from("dim"),
|
|
|
|
Brightness::Dim { glow: 0 }.to_string().as_ref()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
String::from("bright"),
|
|
|
|
Brightness::BrightWhite.to_string().as_ref()
|
|
|
|
);
|
2017-04-16 03:08:49 +02:00
|
|
|
}
|