Skip to content

Commit

Permalink
Add a test to confirm that #357 is fixed (#477)
Browse files Browse the repository at this point in the history
Add a test to confirm that #357 is fixed
  • Loading branch information
juntyr authored Aug 18, 2023
1 parent 709486e commit 0d91151
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/357_untagged_enum_roundtrip.rs
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()
);
}

0 comments on commit 0d91151

Please sign in to comment.