Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Test different enum serializations
  • Loading branch information
webmaster128 committed May 18, 2020
commit 9bc96511a591d5abc10e4b6682696292beda2b33
27 changes: 18 additions & 9 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,25 @@ mod tests {
#[test]
fn enum_() {
#[derive(Serialize)]
enum Type {
#[serde(rename = "boolean")]
Boolean,
#[serde(rename = "number")]
Number,
enum Animal {
Ant,
#[serde(rename = "kitty")]
Cat,
// serialize_tuple_variant not implemented right now
// Dog(),
Horse {},
Zebra {
height: u32,
},
}

assert_eq!(to_string(&Type::Boolean).unwrap(), r#""boolean""#);

assert_eq!(to_string(&Type::Number).unwrap(), r#""number""#);
assert_eq!(to_string(&Animal::Ant).unwrap(), r#""Ant""#);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this is what would make Go crazy.

assert_eq!(to_string(&Animal::Cat).unwrap(), r#""kitty""#);
// assert_eq!(to_string(&Animal::Dog()).unwrap(), r#"{"Dog":[]}"#);
assert_eq!(to_string(&Animal::Horse {}).unwrap(), r#"{"Horse":{}}"#);
assert_eq!(
to_string(&Animal::Zebra { height: 273 }).unwrap(),
r#"{"Zebra":{"height":273}}"#
);
}

#[test]
Expand Down