2017-02-23 09:09:57 +01:00
|
|
|
use strum::EnumProperty;
|
|
|
|
|
|
|
|
#[derive(Debug, EnumProperty)]
|
|
|
|
enum Test {
|
2018-09-26 21:13:45 +02:00
|
|
|
#[strum(props(key = "value"))]
|
2017-02-23 09:09:57 +01:00
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prop_test() {
|
|
|
|
let a = Test::A;
|
|
|
|
assert_eq!("value", a.get_str("key").unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prop_test_not_found() {
|
|
|
|
let a = Test::A;
|
|
|
|
assert_eq!(None, a.get_str("Not Found"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prop_test_not_found_2() {
|
|
|
|
let b = Test::B;
|
|
|
|
assert_eq!(None, b.get_str("key"));
|
2018-09-26 21:13:45 +02:00
|
|
|
}
|
2021-07-17 05:40:19 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn crate_module_path_test() {
|
|
|
|
pub mod nested {
|
|
|
|
pub mod module {
|
|
|
|
pub use strum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Debug, EnumProperty)]
|
|
|
|
#[strum(crate = "nested::module::strum")]
|
|
|
|
enum Test {
|
|
|
|
#[strum(props(key = "value"))]
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
let a = Test::A;
|
|
|
|
assert_eq!("value", a.get_str("key").unwrap());
|
|
|
|
}
|