serialize tuple enums with single element directly as the value instead of a sequence

This commit is contained in:
Oliver Schneider
2015-07-17 15:19:11 +02:00
parent 5885111863
commit 24787195a1
8 changed files with 94 additions and 4 deletions
+9 -1
View File
@@ -28,7 +28,7 @@ enum Animal {
Dog,
Frog(String, Vec<isize>),
Cat { age: usize, name: String },
AntHive(Vec<String>),
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -534,6 +534,10 @@ fn test_write_enum() {
Animal::Cat { age: 5, name: "Kate".to_string() },
"{\"Cat\":{\"age\":5,\"name\":\"Kate\"}}"
),
(
Animal::AntHive(vec!["Bob".to_string(), "Stuart".to_string()]),
"{\"AntHive\":[\"Bob\",\"Stuart\"]}",
),
]);
test_pretty_encode_ok(&[
@@ -976,6 +980,10 @@ fn test_parse_enum() {
" { \"Cat\" : { \"age\" : 5 , \"name\" : \"Kate\" } } ",
Animal::Cat { age: 5, name: "Kate".to_string() },
),
(
" { \"AntHive\" : [\"Bob\", \"Stuart\"] } ",
Animal::AntHive(vec!["Bob".to_string(), "Stuart".to_string()]),
),
]);
test_parse_ok(vec![