1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use strong_xml::{XmlRead, XmlWrite};
use crate::__xml_test_suites;
use crate::document::GridColumn;
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:tblGrid")]
pub struct TableGrid {
#[xml(child = "w:gridCol")]
pub columns: Vec<GridColumn>,
}
impl TableGrid {
pub fn push_column<T: Into<GridColumn>>(mut self, col: T) -> Self {
self.columns.push(col.into());
self
}
}
impl From<Vec<isize>> for TableGrid {
fn from(cols: Vec<isize>) -> TableGrid {
TableGrid {
columns: cols.into_iter().map(Into::into).collect(),
}
}
}
__xml_test_suites!(
TableGrid,
TableGrid::default(),
"<w:tblGrid/>",
TableGrid::default().push_column(42),
r#"<w:tblGrid><w:gridCol w:w="42"/></w:tblGrid>"#,
TableGrid::default().push_column(42).push_column(42),
r#"<w:tblGrid><w:gridCol w:w="42"/><w:gridCol w:w="42"/></w:tblGrid>"#,
TableGrid::from(vec![42, 42]),
r#"<w:tblGrid><w:gridCol w:w="42"/><w:gridCol w:w="42"/></w:tblGrid>"#,
);