2021-11-06 17:30:09 +01:00
|
|
|
use strum::FromRepr;
|
|
|
|
|
2023-07-29 23:58:18 +02:00
|
|
|
mod core {} // ensure macros call `::core`
|
|
|
|
|
2021-11-06 17:30:09 +01:00
|
|
|
#[derive(Debug, FromRepr, PartialEq)]
|
2023-07-03 22:45:32 +02:00
|
|
|
/// Day of the week
|
2021-11-06 17:30:09 +01:00
|
|
|
#[repr(u8)]
|
|
|
|
enum Week {
|
|
|
|
Sunday,
|
|
|
|
Monday,
|
|
|
|
Tuesday,
|
|
|
|
Wednesday,
|
|
|
|
Thursday,
|
|
|
|
Friday = 4 + 3,
|
|
|
|
Saturday = 8,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_test() {
|
2022-06-25 02:47:32 +02:00
|
|
|
assert_eq!(Week::from_repr(0), Some(Week::Sunday));
|
|
|
|
assert_eq!(Week::from_repr(1), Some(Week::Monday));
|
|
|
|
assert_eq!(Week::from_repr(6), None);
|
|
|
|
assert_eq!(Week::from_repr(7), Some(Week::Friday));
|
|
|
|
assert_eq!(Week::from_repr(8), Some(Week::Saturday));
|
|
|
|
assert_eq!(Week::from_repr(9), None);
|
2021-11-06 17:30:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[rustversion::since(1.46)]
|
|
|
|
#[test]
|
|
|
|
fn const_test() {
|
|
|
|
// This is to test that it works in a const fn
|
|
|
|
const fn from_repr(discriminant: u8) -> Option<Week> {
|
|
|
|
Week::from_repr(discriminant)
|
|
|
|
}
|
|
|
|
assert_eq!(from_repr(0), Some(Week::Sunday));
|
|
|
|
assert_eq!(from_repr(1), Some(Week::Monday));
|
|
|
|
assert_eq!(from_repr(6), None);
|
|
|
|
assert_eq!(from_repr(7), Some(Week::Friday));
|
|
|
|
assert_eq!(from_repr(8), Some(Week::Saturday));
|
|
|
|
assert_eq!(from_repr(9), None);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn crate_module_path_test() {
|
|
|
|
pub mod nested {
|
|
|
|
pub mod module {
|
|
|
|
pub use strum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, FromRepr, PartialEq)]
|
|
|
|
#[strum(crate = "nested::module::strum")]
|
|
|
|
enum Week {
|
|
|
|
Sunday,
|
|
|
|
Monday,
|
|
|
|
Tuesday,
|
|
|
|
Wednesday,
|
|
|
|
Thursday,
|
|
|
|
Friday,
|
|
|
|
Saturday,
|
|
|
|
}
|
|
|
|
|
2022-06-25 02:47:32 +02:00
|
|
|
assert_eq!(Week::from_repr(0), Some(Week::Sunday));
|
|
|
|
assert_eq!(Week::from_repr(6), Some(Week::Saturday));
|
|
|
|
assert_eq!(Week::from_repr(7), None);
|
2021-11-06 17:30:09 +01:00
|
|
|
}
|