-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a test to confirm that #357 is fixed
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
enum MyValue { | ||
Int(i64), | ||
String(String), | ||
Enum(Enum), | ||
List(Vec<MyValue>), | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
enum Enum { | ||
First(String), | ||
Second(i64), | ||
} | ||
|
||
#[test] | ||
fn untagged_enum_not_a_list() { | ||
// Contributed by @obi1kenobi in https://github.com/ron-rs/ron/issues/357 | ||
|
||
let value = MyValue::Enum(Enum::First("foo".to_string())); | ||
|
||
let ron = ron::to_string(&value).unwrap(); | ||
assert_eq!(ron, "First(\"foo\")"); | ||
|
||
let de = ron::from_str(&ron).unwrap(); | ||
|
||
// This used to fail as the value was deserialised as `List([String("foo")])` | ||
assert_eq!( | ||
value, | ||
de, | ||
"Serialized as: {}", | ||
ron::to_string(&value).unwrap() | ||
); | ||
} |