summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ron/tests/to_string_pretty.rs
blob: 0e1f93d1aa3e05dfc31a8e96ab05fc2f86c2f4a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use ron::ser::{to_string_pretty, PrettyConfig};
use ron::to_string;
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Point {
    x: f64,
    y: f64,
}

#[test]
fn test_struct_names() {
    let value = Point { x: 1.0, y: 2.0 };
    let struct_name = to_string_pretty(&value, PrettyConfig::default().struct_names(true));
    assert_eq!(
        struct_name,
        Ok("Point(\n    x: 1.0,\n    y: 2.0,\n)".to_string())
    );
    let no_struct_name = to_string(&value);
    assert_eq!(no_struct_name, Ok("(x:1.0,y:2.0)".to_string()));
}