Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement serialize_all=UPPERCASE (#48)
* Implement serialize_all=UPPERCASE * applying rustfmt 1.2.2-stable * handling of all options listed in serde docs for compatibility See https://serde.rs/container-attrs.html#container-attributes
- Loading branch information
1 parent
96daaf4
commit 640c0bb
Showing
4 changed files
with
170 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// test serialize_all cooperation with other macroses | ||
extern crate strum; | ||
#[macro_use] | ||
extern crate strum_macros; | ||
|
||
use std::str::FromStr; | ||
use std::string::ToString; | ||
|
||
#[derive(Debug, Eq, PartialEq, EnumString, ToString, IntoStaticStr)] | ||
#[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)); | ||
} | ||
|
||
#[derive(Debug, Eq, PartialEq, EnumString, ToString, IntoStaticStr)] | ||
#[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)); | ||
} |