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>
50 lines
864 B
Rust
50 lines
864 B
Rust
use strum::EnumProperty;
|
|
|
|
mod core {} // ensure macros call `::core`
|
|
|
|
#[derive(Debug, EnumProperty)]
|
|
enum Test {
|
|
#[strum(props(key = "value"))]
|
|
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"));
|
|
}
|
|
|
|
#[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());
|
|
}
|