1
0
mirror of https://github.com/danog/strum.git synced 2024-12-04 02:17:56 +01:00
strum/strum_tests/tests/as_ref_no_strum.rs
kraktus fd519ec47f
Fix EnumIter macro code generation (#287)
* 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>
2023-07-29 14:58:18 -07:00

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());
}