summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ron/tests/289_enumerate_arrays.rs
blob: 6e0d5c30716087b9eedb6b091cb602086e934b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const EXPTECTED: &str = "[
    /*[0]*/ None,
    /*[1]*/ Some([]),
    /*[2]*/ Some([
        /*[0]*/ 42,
    ]),
    /*[3]*/ Some([
        /*[0]*/ 4,
        /*[1]*/ 2,
    ]),
    /*[4]*/ None,
]";

const EXPTECTED_COMPACT: &str = "[/*[0]*/ None, /*[1]*/ Some([]), /*[2]*/ Some([/*[0]*/ 42]), \
/*[3]*/ Some([/*[0]*/ 4, /*[1]*/ 2]), /*[4]*/ None]";

#[test]
fn enumerate_arrays() {
    let v: Vec<Option<Vec<u8>>> = vec![None, Some(vec![]), Some(vec![42]), Some(vec![4, 2]), None];

    let pretty = ron::ser::PrettyConfig::new().enumerate_arrays(true);

    let ser = ron::ser::to_string_pretty(&v, pretty).unwrap();

    assert_eq!(ser, EXPTECTED);

    let de: Vec<Option<Vec<u8>>> = ron::from_str(&ser).unwrap();

    assert_eq!(v, de)
}

#[test]
fn enumerate_compact_arrays() {
    let v: Vec<Option<Vec<u8>>> = vec![None, Some(vec![]), Some(vec![42]), Some(vec![4, 2]), None];

    let pretty = ron::ser::PrettyConfig::new()
        .enumerate_arrays(true)
        .compact_arrays(true);

    let ser = ron::ser::to_string_pretty(&v, pretty).unwrap();

    assert_eq!(ser, EXPTECTED_COMPACT);

    let de: Vec<Option<Vec<u8>>> = ron::from_str(&ser).unwrap();

    assert_eq!(v, de)
}