1
use std::collections::BTreeMap;
2

            
3
use ron::ser::{to_string, to_string_pretty, PrettyConfig};
4

            
5
#[derive(serde_derive::Serialize)]
6
struct Struct {
7
    a: u8,
8
    b: u8,
9
}
10

            
11
#[test]
12
4
fn compact_structs() {
13
4
    let s = Struct { a: 4, b: 2 };
14
4

            
15
4
    assert_eq!(to_string(&s).unwrap(), "(a:4,b:2)");
16
4
    assert_eq!(
17
4
        to_string_pretty(&s, PrettyConfig::default()).unwrap(),
18
4
        "(\n    a: 4,\n    b: 2,\n)"
19
4
    );
20
4
    assert_eq!(
21
4
        to_string_pretty(&s, PrettyConfig::default().compact_structs(true)).unwrap(),
22
4
        "(a: 4, b: 2)"
23
4
    );
24
4
}
25

            
26
#[test]
27
4
fn compact_maps() {
28
4
    let m: BTreeMap<&str, i32> = BTreeMap::from_iter([("a", 4), ("b", 2)]);
29
4

            
30
4
    assert_eq!(to_string(&m).unwrap(), "{\"a\":4,\"b\":2}");
31
4
    assert_eq!(
32
4
        to_string_pretty(&m, PrettyConfig::default()).unwrap(),
33
4
        "{\n    \"a\": 4,\n    \"b\": 2,\n}"
34
4
    );
35
4
    assert_eq!(
36
4
        to_string_pretty(&m, PrettyConfig::default().compact_maps(true)).unwrap(),
37
4
        "{\"a\": 4, \"b\": 2}"
38
4
    );
39
4
}