mirror of
https://github.com/danog/strum.git
synced 2024-12-11 08:59:37 +01:00
85e2c1692b
* Added enum_is * feat(is): Use a simple match and cover all cases * Removed dependency convert_case * Added disabled support for enum_is
71 lines
1.2 KiB
Rust
71 lines
1.2 KiB
Rust
use strum::EnumIs;
|
|
|
|
#[derive(EnumIs)]
|
|
enum Foo {
|
|
Unit,
|
|
Named0 {},
|
|
Named1 { _a: char },
|
|
Named2 { _a: u32, _b: String },
|
|
Unnamed0(),
|
|
Unnamed1(Option<u128>),
|
|
Unnamed2(bool, u8),
|
|
MultiWordName,
|
|
#[strum(disabled)]
|
|
#[allow(dead_code)]
|
|
Disabled,
|
|
}
|
|
|
|
#[test]
|
|
fn simple_test() {
|
|
assert!(Foo::Unit.is_unit());
|
|
}
|
|
|
|
#[test]
|
|
fn named_0() {
|
|
assert!(Foo::Named0 {}.is_named_0());
|
|
}
|
|
|
|
#[test]
|
|
fn named_1() {
|
|
let foo = Foo::Named1 {
|
|
_a: Default::default(),
|
|
};
|
|
assert!(foo.is_named_1());
|
|
}
|
|
|
|
#[test]
|
|
fn named_2() {
|
|
let foo = Foo::Named2 {
|
|
_a: Default::default(),
|
|
_b: Default::default(),
|
|
};
|
|
assert!(foo.is_named_2());
|
|
}
|
|
|
|
#[test]
|
|
fn unnamed_0() {
|
|
assert!(Foo::Unnamed0().is_unnamed_0());
|
|
}
|
|
|
|
#[test]
|
|
fn unnamed_1() {
|
|
let foo = Foo::Unnamed1(Default::default());
|
|
assert!(foo.is_unnamed_1());
|
|
}
|
|
|
|
#[test]
|
|
fn unnamed_2() {
|
|
let foo = Foo::Unnamed2(Default::default(), Default::default());
|
|
assert!(foo.is_unnamed_2());
|
|
}
|
|
|
|
#[test]
|
|
fn multi_word() {
|
|
assert!(Foo::MultiWordName.is_multi_word_name());
|
|
}
|
|
|
|
#[test]
|
|
fn doesnt_match_other_variations() {
|
|
assert!(!Foo::Unit.is_multi_word_name());
|
|
}
|