1
use std::collections::HashMap;
2

            
3
use serde::Serialize;
4

            
5
#[derive(Serialize)]
6
struct Config {
7
    float: (f32, f64),
8
    tuple: TupleStruct,
9
    map: HashMap<u8, char>,
10
    nested: Nested,
11
    var: Variant,
12
    array: Vec<()>,
13
}
14

            
15
#[derive(Serialize)]
16
struct TupleStruct((), bool);
17

            
18
#[derive(Serialize)]
19
enum Variant {
20
    A(u8, &'static str),
21
}
22

            
23
#[derive(Serialize)]
24
struct Nested {
25
    a: String,
26
    b: char,
27
}
28

            
29
const EXPECTED: &str = "(
30
    float: (2.18, -1.1),
31
    tuple: ((), false),
32
    map: {8: '1'},
33
    nested: (a: \"a\", b: 'b'),
34
    var: A(255, \"\"),
35
    array: [(), (), ()],
36
)";
37

            
38
#[test]
39
4
fn depth_limit() {
40
4
    let data = Config {
41
4
        float: (2.18, -1.1),
42
4
        tuple: TupleStruct((), false),
43
4
        map: vec![(8, '1')].into_iter().collect(),
44
4
        nested: Nested {
45
4
            a: "a".to_owned(),
46
4
            b: 'b',
47
4
        },
48
4
        var: Variant::A(!0, ""),
49
4
        array: vec![(); 3],
50
4
    };
51
4

            
52
4
    let pretty = ron::ser::PrettyConfig::new()
53
4
        .depth_limit(1)
54
4
        .separate_tuple_members(true)
55
4
        .enumerate_arrays(true)
56
4
        .new_line("\n");
57
4
    let s = ron::ser::to_string_pretty(&data, pretty);
58
4

            
59
4
    assert_eq!(s, Ok(EXPECTED.to_string()));
60
4
}