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,
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(disabled = "true")]
|
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
|
|
|
}
|