1
#[test]
2
4
fn serialize_backslash_string() {
3
4
    check_roundtrip('\\', r"'\\'", r"'\\'");
4
4
    check_roundtrip(String::from("\\"), r#""\\""#, "r#\"\\\"#");
5
4
}
6

            
7
8
fn check_roundtrip<
8
8
    T: PartialEq + std::fmt::Debug + serde::Serialize + serde::de::DeserializeOwned,
9
8
>(
10
8
    val: T,
11
8
    cmp: &str,
12
8
    cmp_raw: &str,
13
8
) {
14
8
    let ron = ron::to_string(&val).unwrap();
15
8
    assert_eq!(ron, cmp);
16

            
17
8
    let ron_escaped =
18
8
        ron::ser::to_string_pretty(&val, ron::ser::PrettyConfig::default().escape_strings(true))
19
8
            .unwrap();
20
8
    assert_eq!(ron_escaped, cmp);
21

            
22
8
    let ron_raw = ron::ser::to_string_pretty(
23
8
        &val,
24
8
        ron::ser::PrettyConfig::default().escape_strings(false),
25
8
    )
26
8
    .unwrap();
27
8
    assert_eq!(ron_raw, cmp_raw);
28

            
29
8
    let de = ron::from_str::<T>(&ron).unwrap();
30
8
    assert_eq!(de, val);
31

            
32
8
    let de_raw = ron::from_str::<T>(&ron_raw).unwrap();
33
8
    assert_eq!(de_raw, val);
34
8
}