1
use serde::{Deserialize, Serialize};
2

            
3
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
4
#[serde(untagged)]
5
enum MyValue {
6
    Int(i64),
7
    String(String),
8
    Enum(Enum),
9
    List(Vec<MyValue>),
10
}
11

            
12
8
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
13
enum Enum {
14
    First(String),
15
    Second(i64),
16
}
17

            
18
#[test]
19
4
fn untagged_enum_not_a_list() {
20
4
    // Contributed by @obi1kenobi in https://github.com/ron-rs/ron/issues/357
21
4

            
22
4
    let value = MyValue::Enum(Enum::First("foo".to_string()));
23
4

            
24
4
    let ron = ron::to_string(&value).unwrap();
25
4
    assert_eq!(ron, "First(\"foo\")");
26

            
27
4
    let de = ron::from_str(&ron).unwrap();
28
4

            
29
4
    println!("{}", ron);
30
4

            
31
4
    // This used to fail as the value was deserialised as `List([String("foo")])`
32
4
    assert_eq!(value, de);
33
4
}