2019-06-23 13:39:28 +02:00
|
|
|
#![allow(unused_imports)]
|
2017-02-16 04:16:40 +01:00
|
|
|
extern crate strum;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate strum_macros;
|
|
|
|
|
|
|
|
use strum::EnumMessage;
|
|
|
|
|
2018-09-26 21:13:45 +02:00
|
|
|
#[derive(Debug, Eq, PartialEq, EnumMessage)]
|
2017-02-16 04:16:40 +01:00
|
|
|
enum Pets {
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(message = "I'm a dog")]
|
2017-02-16 04:16:40 +01:00
|
|
|
Dog,
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(message = "I'm a cat")]
|
|
|
|
#[strum(detailed_message = "I'm a very exquisite striped cat")]
|
2017-02-16 04:16:40 +01:00
|
|
|
Cat,
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(detailed_message = "My fish is named Charles McFish")]
|
2017-02-16 04:16:40 +01:00
|
|
|
Fish,
|
|
|
|
Bird,
|
2020-07-29 18:36:48 +02:00
|
|
|
#[strum(disabled)]
|
2017-02-16 04:16:40 +01:00
|
|
|
Hamster,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_message() {
|
|
|
|
assert_eq!("I'm a dog", (Pets::Dog).get_message().unwrap());
|
|
|
|
assert_eq!("I'm a dog", (Pets::Dog).get_detailed_message().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn detailed_message() {
|
|
|
|
assert_eq!("I'm a cat", (Pets::Cat).get_message().unwrap());
|
2018-09-26 21:13:45 +02:00
|
|
|
assert_eq!(
|
|
|
|
"I'm a very exquisite striped cat",
|
|
|
|
(Pets::Cat).get_detailed_message().unwrap()
|
|
|
|
);
|
2017-02-16 04:16:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn only_detailed_message() {
|
|
|
|
assert_eq!(None, (Pets::Fish).get_message());
|
2018-09-26 21:13:45 +02:00
|
|
|
assert_eq!(
|
|
|
|
"My fish is named Charles McFish",
|
|
|
|
(Pets::Fish).get_detailed_message().unwrap()
|
|
|
|
);
|
2017-02-16 04:16:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_message() {
|
|
|
|
assert_eq!(None, (Pets::Bird).get_message());
|
|
|
|
assert_eq!(None, (Pets::Bird).get_detailed_message());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disabled_message() {
|
|
|
|
assert_eq!(None, (Pets::Hamster).get_message());
|
|
|
|
assert_eq!(None, (Pets::Hamster).get_detailed_message());
|
2018-09-26 21:13:45 +02:00
|
|
|
}
|
2020-02-11 00:55:18 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, EnumMessage)]
|
|
|
|
#[strum(serialize_all = "kebab_case")]
|
|
|
|
enum Brightness {
|
|
|
|
DarkBlack,
|
|
|
|
Dim {
|
|
|
|
glow: usize,
|
|
|
|
},
|
|
|
|
#[strum(serialize = "bright")]
|
|
|
|
BrightWhite,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get_serializations() {
|
|
|
|
assert_eq!(
|
|
|
|
vec!["dark-black"],
|
|
|
|
(Brightness::DarkBlack).get_serializations()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
vec!["dim"],
|
|
|
|
(Brightness::Dim { glow: 1 }).get_serializations()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
vec!["bright"],
|
|
|
|
(Brightness::BrightWhite).get_serializations()
|
|
|
|
);
|
|
|
|
}
|