Debian Codegraph @

tests/all/padding_test.rs

raw symbols SCIP
1 use comfy_table::*;
2 use pretty_assertions::assert_eq;
3
4 /// Columns can set a custom padding.
5 /// Ensure these settings are working.
6 #[test]
7 fn custom_padding() {
8 let mut table = Table::new();
9 table
10 .set_header(vec![
11 Cell::new("Header1"),
12 Cell::new("Header2"),
13 Cell::new("Header3"),
14 ])
15 .add_row(vec!["One One", "One Two", "One Three"])
16 .add_row(vec!["Two One", "Two Two", "Two Three"])
17 .add_row(vec!["Three One", "Three Two", "Three Three"]);
18
19 let column = table.column_mut(0).unwrap();
20 column.set_padding((5, 5));
21 let column = table.column_mut(2).unwrap();
22 column.set_padding((0, 0));
23
24 println!("{table}");
25 let expected = "
26 +-------------------+-----------+-----------+
27 | Header1 | Header2 |Header3 |
28 +===========================================+
29 | One One | One Two |One Three |
30 |-------------------+-----------+-----------|
31 | Two One | Two Two |Two Three |
32 |-------------------+-----------+-----------|
33 | Three One | Three Two |Three Three|
34 +-------------------+-----------+-----------+";
35 assert_eq!(expected, "\n".to_string() + &table.to_string());
36 }