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

            
3
8
#[derive(Debug, PartialEq, Serialize, Deserialize)]
4
enum Other {
5
    Env(String),
6
}
7

            
8
#[derive(Debug, PartialEq, Serialize, Deserialize)]
9
#[serde(untagged)]
10
enum MaybeEnv {
11
    Value(String),
12
    Other(Other),
13
}
14

            
15
#[test]
16
4
fn enum_in_untagged_enum() {
17
4
    check_roundtrip(&MaybeEnv::Value(String::from("foo")), "\"foo\"");
18
4
    check_roundtrip(
19
4
        &MaybeEnv::Other(Other::Env(String::from("bar"))),
20
4
        "Env(\"bar\")",
21
4
    );
22
4
}
23

            
24
8
fn check_roundtrip<T: Serialize + serde::de::DeserializeOwned + std::fmt::Debug + PartialEq>(
25
8
    val: &T,
26
8
    check: &str,
27
8
) {
28
8
    let ron = ron::to_string(&val).unwrap();
29
8
    assert_eq!(ron, check);
30

            
31
8
    let de = ron::from_str::<T>(&ron).unwrap();
32
8
    assert_eq!(&de, val);
33
8
}