2022-02-19 01:04:31 +01:00
|
|
|
/// test `serialize_all` cooperation with other macroses
|
2019-07-29 17:26:29 +02:00
|
|
|
use std::str::FromStr;
|
|
|
|
use std::string::ToString;
|
2022-02-19 01:04:31 +01:00
|
|
|
use strum::{Display, EnumString, IntoStaticStr};
|
2019-07-29 17:26:29 +02:00
|
|
|
|
2022-02-19 01:04:31 +01:00
|
|
|
#[derive(Debug, Eq, PartialEq, EnumString, Display, IntoStaticStr)]
|
2019-07-29 17:26:29 +02:00
|
|
|
#[strum(serialize_all = "title_case")]
|
|
|
|
enum Foo1 {
|
|
|
|
DarkBlack,
|
|
|
|
Dim { glow: usize },
|
|
|
|
BrightWhite,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_all_title_case() {
|
|
|
|
assert_eq!("Dark Black", Foo1::DarkBlack.to_string());
|
|
|
|
assert_eq!(Foo1::DarkBlack, Foo1::from_str("Dark Black").unwrap());
|
|
|
|
assert_eq!("Dark Black", <&'static str>::from(Foo1::DarkBlack));
|
|
|
|
}
|
|
|
|
|
2022-02-19 01:04:31 +01:00
|
|
|
#[derive(Debug, Eq, PartialEq, EnumString, Display, IntoStaticStr)]
|
2019-07-29 17:26:29 +02:00
|
|
|
#[strum(serialize_all = "UPPERCASE")]
|
|
|
|
enum Foo2 {
|
|
|
|
DarkBlack,
|
|
|
|
Dim { glow: usize },
|
|
|
|
BrightWhite,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_all_upper_case() {
|
|
|
|
assert_eq!("DARKBLACK", Foo2::DarkBlack.to_string());
|
|
|
|
assert_eq!(Foo2::DarkBlack, Foo2::from_str("DARKBLACK").unwrap());
|
|
|
|
assert_eq!("DARKBLACK", <&'static str>::from(Foo2::DarkBlack));
|
|
|
|
}
|