Debian Codegraph @

tests/depth_limit.rs

raw symbols SCIP
1 use std::collections::HashMap;
2
3 use serde::Serialize;
4
5 #[derive(Serialize)]
6 struct Config {
7 float: (f32, f64),
8 tuple: TupleStruct,
9 map: HashMap<u8, char>,
10 nested: Nested,
11 var: Variant,
12 array: Vec<()>,
13 }
14
15 #[derive(Serialize)]
16 struct TupleStruct((), bool);
17
18 #[derive(Serialize)]
19 enum Variant {
20 A(u8, &'static str),
21 }
22
23 #[derive(Serialize)]
24 struct Nested {
25 a: String,
26 b: char,
27 }
28
29 const EXPECTED: &str = "(
30 float: (2.18, -1.1),
31 tuple: ((), false),
32 map: {8: '1'},
33 nested: (a: \"a\", b: 'b'),
34 var: A(255, \"\"),
35 array: [(), (), ()],
36 )";
37
38 #[test]
39 fn depth_limit() {
40 let data = Config {
41 float: (2.18, -1.1),
42 tuple: TupleStruct((), false),
43 map: vec![(8, '1')].into_iter().collect(),
44 nested: Nested {
45 a: "a".to_owned(),
46 b: 'b',
47 },
48 var: Variant::A(!0, ""),
49 array: vec![(); 3],
50 };
51
52 let pretty = ron::ser::PrettyConfig::new()
53 .depth_limit(1)
54 .separate_tuple_members(true)
55 .enumerate_arrays(true)
56 .new_line("\n");
57 let s = ron::ser::to_string_pretty(&data, pretty);
58
59 assert_eq!(s, Ok(EXPECTED.to_string()));
60 }