1
use std::collections::BTreeMap;
2

            
3
use ron::{
4
    de::from_str,
5
    ser::{to_string_pretty, PrettyConfig},
6
};
7
use serde::{Deserialize, Serialize};
8

            
9
48
#[derive(Debug, Deserialize, Serialize)]
10
struct Config {
11
    boolean: bool,
12
    float: f32,
13
    map: BTreeMap<u8, char>,
14
    nested: Nested,
15
    tuple: (u32, u32),
16
}
17

            
18
24
#[derive(Debug, Deserialize, Serialize)]
19
struct Nested {
20
    a: String,
21
    b: char,
22
}
23

            
24
8
fn read_original(source: &str) -> String {
25
8
    source.to_string().replace("\r\n", "\n")
26
8
}
27

            
28
8
fn make_roundtrip(source: &str) -> String {
29
8
    let config: Config = from_str(source).unwrap();
30
8
    let pretty = PrettyConfig::new()
31
8
        .depth_limit(3)
32
8
        .separate_tuple_members(true)
33
8
        .enumerate_arrays(true)
34
8
        .new_line("\n");
35
8
    to_string_pretty(&config, pretty).expect("Serialization failed")
36
8
}
37

            
38
#[test]
39
4
fn test_sequence_ex1() {
40
4
    let file = include_str!("preserve_sequence_ex1.ron");
41
4
    assert_eq!(read_original(file), make_roundtrip(file));
42
4
}
43

            
44
#[test]
45
4
fn test_sequence_ex2() {
46
4
    let file = include_str!("preserve_sequence_ex2.ron");
47
4
    assert_eq!(read_original(file), make_roundtrip(file));
48
4
}