1pub use enum_display_macro::*;
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[allow(dead_code)]
44 #[derive(EnumDisplay)]
45 enum TestEnum {
46 Name,
47 Address {
48 street: String,
49 city: String,
50 state: String,
51 zip: String,
52 },
53 DateOfBirth(u32, u32, u32),
54 }
55
56 #[allow(dead_code)]
57 #[derive(EnumDisplay)]
58 #[enum_display(case = "Kebab")]
59 enum TestEnumWithAttribute {
60 Name,
61 Address {
62 street: String,
63 city: String,
64 state: String,
65 zip: String,
66 },
67 DateOfBirth(u32, u32, u32),
68 }
69
70 #[test]
71 fn test_unit_field_variant() {
72 assert_eq!(TestEnum::Name.to_string(), "Name");
73 }
74
75 #[test]
76 fn test_named_fields_variant() {
77 assert_eq!(
78 TestEnum::Address {
79 street: "123 Main St".to_string(),
80 city: "Any Town".to_string(),
81 state: "CA".to_string(),
82 zip: "12345".to_string()
83 }
84 .to_string(),
85 "Address"
86 );
87 }
88
89 #[test]
90 fn test_unnamed_fields_variant() {
91 assert_eq!(TestEnum::DateOfBirth(1, 1, 2000).to_string(), "DateOfBirth");
92 }
93
94 #[test]
95 fn test_unit_field_variant_case_transform() {
96 assert_eq!(TestEnumWithAttribute::Name.to_string(), "name");
97 }
98
99 #[test]
100 fn test_named_fields_variant_case_transform() {
101 assert_eq!(
102 TestEnumWithAttribute::Address {
103 street: "123 Main St".to_string(),
104 city: "Any Town".to_string(),
105 state: "CA".to_string(),
106 zip: "12345".to_string()
107 }
108 .to_string(),
109 "address"
110 );
111 }
112
113 #[test]
114 fn test_unnamed_fields_variant_case_transform() {
115 assert_eq!(
116 TestEnumWithAttribute::DateOfBirth(1, 1, 2000).to_string(),
117 "date-of-birth"
118 );
119 }
120}