2020-09-17 20:21:21 +02:00
|
|
|
use strum::{EnumCount, EnumIter, IntoEnumIterator};
|
2018-11-05 19:36:09 +01:00
|
|
|
|
2023-07-29 23:58:18 +02:00
|
|
|
mod core {} // ensure macros call `::core`
|
|
|
|
|
2018-11-05 19:36:09 +01:00
|
|
|
#[derive(Debug, EnumCount, EnumIter)]
|
|
|
|
enum Week {
|
|
|
|
Sunday,
|
|
|
|
Monday,
|
|
|
|
Tuesday,
|
|
|
|
Wednesday,
|
|
|
|
Thursday,
|
|
|
|
Friday,
|
|
|
|
Saturday,
|
|
|
|
}
|
|
|
|
|
2023-06-18 02:50:15 +02:00
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Debug, EnumCount, EnumIter)]
|
|
|
|
enum Pets {
|
|
|
|
Dog,
|
|
|
|
Cat,
|
|
|
|
Fish,
|
|
|
|
Bird,
|
|
|
|
#[strum(disabled)]
|
|
|
|
Hamster,
|
|
|
|
}
|
|
|
|
|
2018-11-05 19:36:09 +01:00
|
|
|
#[test]
|
|
|
|
fn simple_test() {
|
2020-07-26 06:41:15 +02:00
|
|
|
assert_eq!(7, Week::COUNT);
|
|
|
|
assert_eq!(Week::iter().count(), Week::COUNT);
|
2018-11-05 19:36:09 +01:00
|
|
|
}
|
2021-07-17 05:40:19 +02:00
|
|
|
|
2023-06-18 02:50:15 +02:00
|
|
|
#[test]
|
|
|
|
fn disabled_test() {
|
|
|
|
assert_eq!(4, Pets::COUNT);
|
|
|
|
assert_eq!(Pets::iter().count(), Pets::COUNT);
|
|
|
|
}
|
|
|
|
|
2021-07-17 05:40:19 +02:00
|
|
|
#[test]
|
|
|
|
fn crate_module_path_test() {
|
|
|
|
pub mod nested {
|
|
|
|
pub mod module {
|
|
|
|
pub use strum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, EnumCount, EnumIter)]
|
|
|
|
#[strum(crate = "nested::module::strum")]
|
|
|
|
enum Week {
|
|
|
|
Sunday,
|
|
|
|
Monday,
|
|
|
|
Tuesday,
|
|
|
|
Wednesday,
|
|
|
|
Thursday,
|
|
|
|
Friday,
|
|
|
|
Saturday,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(7, Week::COUNT);
|
|
|
|
assert_eq!(Week::iter().count(), Week::COUNT);
|
|
|
|
}
|