1
0
mirror of https://github.com/danog/strum.git synced 2024-12-11 17:09:36 +01:00
strum/strum_tests/tests/enum_message.rs
Azriel Hoh 1c00f6cfa5 Feature/33/derive enum variants (#34)
* Run rustfmt over repository.

* Bump `syn` to 0.15

* Implemented ability to `serialize_all` using cases from `heck`.

Issue #21

* Use `path` and `version` in dependency specifications.

Issue #21

* Updated documentation.

Issue #21

* Added `CHANGELOG.md`.

* Also convert case when deriving `Display`.

Issue #21

* Added `EnumDiscriminants` derive.

Issue #33

* Added the ability to rename derived `EnumDiscriminants`.

Issue #33

* Updated `README.md` and lib.rs docs.

Issue #33

* Updated `CHANGELOG.md`.

Issue #33

* WIP: refactoring to allow attributes on discriminants enum.

* Use single `strum_discriminants` top level attribute.

Issue #33

* Allow multiple declarations of `strum_discriminants` attribute.

Issue #33

* Pass through all other attributes to discriminant enum.

Issue #33

* Add `impl From<MyEnum> for MyEnumDiscriminants`.

Issue #33

* Add `impl<'_enum> From<&'_enum MyEnum> for MyEnumDiscriminants`.

Issue #33

* Added complex case test for `From` derivation.

Issue #33

* Added docs to some helper functions.

* Added docs about `From` impls.

Issue #33
2018-09-26 12:13:45 -07:00

56 lines
1.3 KiB
Rust

extern crate strum;
#[macro_use]
extern crate strum_macros;
use strum::EnumMessage;
#[derive(Debug, Eq, PartialEq, EnumMessage)]
enum Pets {
#[strum(message = "I'm a dog")]
Dog,
#[strum(message = "I'm a cat")]
#[strum(detailed_message = "I'm a very exquisite striped cat")]
Cat,
#[strum(detailed_message = "My fish is named Charles McFish")]
Fish,
Bird,
#[strum(disabled = "true")]
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());
assert_eq!(
"I'm a very exquisite striped cat",
(Pets::Cat).get_detailed_message().unwrap()
);
}
#[test]
fn only_detailed_message() {
assert_eq!(None, (Pets::Fish).get_message());
assert_eq!(
"My fish is named Charles McFish",
(Pets::Fish).get_detailed_message().unwrap()
);
}
#[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());
}