1 use snapbox::assert_eq;
2 
3 use toml_edit::{Document, Item, Value};
4 
5 #[test]
table_into_inline()6 fn table_into_inline() {
7     let toml = r#"
8 [table]
9 string = "value"
10 array = [1, 2, 3]
11 inline = { "1" = 1, "2" = 2 }
12 
13 [table.child]
14 other = "world"
15 "#;
16     let mut doc = toml.parse::<Document>().unwrap();
17 
18     doc.get_mut("table").unwrap().make_value();
19 
20     let actual = doc.to_string();
21     // `table=` is because we didn't re-format the table key, only the value
22     let expected = r#"table= { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }
23 "#;
24     assert_eq(expected, actual);
25 }
26 
27 #[test]
inline_table_to_table()28 fn inline_table_to_table() {
29     let toml = r#"table = { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }
30 "#;
31     let mut doc = toml.parse::<Document>().unwrap();
32 
33     let t = doc.remove("table").unwrap();
34     let t = match t {
35         Item::Value(Value::InlineTable(t)) => t,
36         _ => unreachable!("Unexpected {:?}", t),
37     };
38     let t = t.into_table();
39     doc.insert("table", Item::Table(t));
40 
41     let actual = doc.to_string();
42     let expected = r#"[table]
43 string = "value"
44 array = [1, 2, 3]
45 inline = { "1" = 1, "2" = 2 }
46 child = { other = "world" }
47 "#;
48     assert_eq(expected, actual);
49 }
50 
51 #[test]
array_of_tables_to_array()52 fn array_of_tables_to_array() {
53     let toml = r#"
54 [[table]]
55 string = "value"
56 array = [1, 2, 3]
57 inline = { "1" = 1, "2" = 2 }
58 
59 [table.child]
60 other = "world"
61 
62 [[table]]
63 string = "value"
64 array = [1, 2, 3]
65 inline = { "1" = 1, "2" = 2 }
66 
67 [table.child]
68 other = "world"
69 "#;
70     let mut doc = toml.parse::<Document>().unwrap();
71 
72     doc.get_mut("table").unwrap().make_value();
73 
74     let actual = doc.to_string();
75     // `table=` is because we didn't re-format the table key, only the value
76     let expected = r#"table= [{ string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }, { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }]
77 "#;
78     assert_eq(expected, actual);
79 }
80