mirror of
https://github.com/danog/strum.git
synced 2024-12-04 02:17:56 +01:00
fd519ec47f
* Add test to ensure macro call `::core`-related functions Avoiding local core modules to break the macro-generated code. Currently failing due to issue with `EnumIter` macros. * Fix macro of `EnumIter` close https://github.com/Peternator7/strum/issues/284 --------- Co-authored-by: kraktus <kraktus@users.noreply.github.com>
62 lines
1.0 KiB
Rust
62 lines
1.0 KiB
Rust
use strum::{EnumCount, EnumIter, IntoEnumIterator};
|
|
|
|
mod core {} // ensure macros call `::core`
|
|
|
|
#[derive(Debug, EnumCount, EnumIter)]
|
|
enum Week {
|
|
Sunday,
|
|
Monday,
|
|
Tuesday,
|
|
Wednesday,
|
|
Thursday,
|
|
Friday,
|
|
Saturday,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug, EnumCount, EnumIter)]
|
|
enum Pets {
|
|
Dog,
|
|
Cat,
|
|
Fish,
|
|
Bird,
|
|
#[strum(disabled)]
|
|
Hamster,
|
|
}
|
|
|
|
#[test]
|
|
fn simple_test() {
|
|
assert_eq!(7, Week::COUNT);
|
|
assert_eq!(Week::iter().count(), Week::COUNT);
|
|
}
|
|
|
|
#[test]
|
|
fn disabled_test() {
|
|
assert_eq!(4, Pets::COUNT);
|
|
assert_eq!(Pets::iter().count(), Pets::COUNT);
|
|
}
|
|
|
|
#[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);
|
|
}
|