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>
36 lines
705 B
Rust
36 lines
705 B
Rust
use strum_macros::AsRefStr;
|
|
|
|
mod core {} // ensure macros call `::core`
|
|
|
|
#[derive(Debug, Eq, PartialEq, AsRefStr)]
|
|
enum Color {
|
|
#[strum(to_string = "RedRed")]
|
|
Red,
|
|
#[strum(serialize = "b", to_string = "blue")]
|
|
Blue { hue: usize },
|
|
#[strum(serialize = "y", serialize = "yellow")]
|
|
Yellow,
|
|
#[strum(default)]
|
|
Green(String),
|
|
}
|
|
|
|
#[test]
|
|
fn as_red_str() {
|
|
assert_eq!("RedRed", (Color::Red).as_ref());
|
|
}
|
|
|
|
#[test]
|
|
fn as_blue_str() {
|
|
assert_eq!("blue", (Color::Blue { hue: 0 }).as_ref());
|
|
}
|
|
|
|
#[test]
|
|
fn as_yellow_str() {
|
|
assert_eq!("yellow", (Color::Yellow).as_ref());
|
|
}
|
|
|
|
#[test]
|
|
fn as_green_str() {
|
|
assert_eq!("Green", (Color::Green(String::default())).as_ref());
|
|
}
|