1
use std::borrow::Cow;
2

            
3
use ron::{de::from_str, ser::to_string};
4
use serde::{Deserialize, Serialize};
5

            
6
12
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
7
pub struct BuildSystem<'m> {
8
    version: Cow<'m, str>,
9
    flags: Vec<Flag<'m>>,
10
}
11

            
12
4
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
13
#[serde(untagged)]
14
pub enum Flag<'m> {
15
    Value(Cow<'m, str>),
16
    If(Cow<'m, str>, Vec<Cow<'m, str>>),
17
}
18

            
19
#[test]
20
4
fn test_ebkalderon_case() {
21
4
    let file = r#"BuildSystem(
22
4
    version: "1.0.0",
23
4
    flags: [
24
4
        "--enable-thing",
25
4
        "--enable-other-thing",
26
4
        ("some-conditional", ["--enable-third-thing"]),
27
4
    ]
28
4
)
29
4
"#;
30
4

            
31
4
    assert_eq!(
32
4
        from_str::<BuildSystem>(file).unwrap(),
33
4
        BuildSystem {
34
4
            version: "1.0.0".into(),
35
4
            flags: vec![
36
4
                Flag::Value("--enable-thing".into()),
37
4
                Flag::Value("--enable-other-thing".into()),
38
4
                Flag::If(
39
4
                    "some-conditional".into(),
40
4
                    vec!["--enable-third-thing".into()]
41
4
                )
42
4
            ]
43
4
        },
44
4
    );
45
4
}
46

            
47
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
48
#[serde(untagged)]
49
enum Foo {
50
    Bar(usize),
51
}
52

            
53
#[test]
54
4
fn test_vessd_case() {
55
4
    let foo_vec = vec![Foo::Bar(0); 5];
56
4
    let foo_str = to_string(&foo_vec).unwrap();
57
4
    assert_eq!(foo_str.as_str(), "[0,0,0,0,0]");
58
4
    assert_eq!(from_str::<Vec<Foo>>(&foo_str).unwrap(), foo_vec);
59
4
}