1
use std::collections::HashMap;
2

            
3
use serde::{Deserialize, Serialize};
4

            
5
4
#[derive(Debug, PartialEq, Deserialize, Serialize)]
6
struct UnitStruct;
7

            
8
4
#[derive(Debug, PartialEq, Deserialize, Serialize)]
9
struct NewType(f32);
10

            
11
4
#[derive(Debug, PartialEq, Deserialize, Serialize)]
12
struct TupleStruct(UnitStruct, i8);
13

            
14
8
#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
15
struct Key(u32);
16

            
17
24
#[derive(Debug, PartialEq, Deserialize, Serialize)]
18
struct Struct {
19
    tuple: ((), NewType, TupleStruct),
20
    vec: Vec<Option<UnitStruct>>,
21
    map: HashMap<Key, i32>,
22
    deep_vec: HashMap<Key, Vec<()>>,
23
    deep_map: HashMap<Key, HashMap<Key, i32>>,
24
}
25

            
26
#[test]
27
4
fn empty_sets_arrays() {
28
4
    let value = Struct {
29
4
        tuple: ((), NewType(0.5), TupleStruct(UnitStruct, -5)),
30
4
        vec: vec![],
31
4
        map: vec![].into_iter().collect(),
32
4
        deep_vec: vec![(Key(0), vec![])].into_iter().collect(),
33
4
        deep_map: vec![(Key(0), vec![].into_iter().collect())]
34
4
            .into_iter()
35
4
            .collect(),
36
4
    };
37
4

            
38
4
    let pretty = ron::ser::PrettyConfig::new()
39
4
        .enumerate_arrays(true)
40
4
        .new_line("\n");
41
4
    let serial = ron::ser::to_string_pretty(&value, pretty).unwrap();
42
4

            
43
4
    println!("Serialized: {}", serial);
44
4

            
45
4
    assert_eq!(
46
4
        "(
47
4
    tuple: ((), (0.5), ((), -5)),
48
4
    vec: [],
49
4
    map: {},
50
4
    deep_vec: {
51
4
        (0): [],
52
4
    },
53
4
    deep_map: {
54
4
        (0): {},
55
4
    },
56
4
)",
57
4
        serial
58
4
    );
59

            
60
4
    let deserial = ron::de::from_str(&serial);
61
4

            
62
4
    assert_eq!(Ok(value), deserial);
63
4
}