File: padding_test.rs

package info (click to toggle)
rust-comfy-table 7.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 612 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download | duplicates (2)
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
use pretty_assertions::assert_eq;

use comfy_table::*;

#[test]
/// Columns can set a custom padding.
/// Ensure these settings are working.
fn custom_padding() {
    let mut table = Table::new();
    table
        .set_header(vec![
            Cell::new("Header1"),
            Cell::new("Header2"),
            Cell::new("Header3"),
        ])
        .add_row(vec!["One One", "One Two", "One Three"])
        .add_row(vec!["Two One", "Two Two", "Two Three"])
        .add_row(vec!["Three One", "Three Two", "Three Three"]);

    let column = table.column_mut(0).unwrap();
    column.set_padding((5, 5));
    let column = table.column_mut(2).unwrap();
    column.set_padding((0, 0));

    println!("{table}");
    let expected = "
+-------------------+-----------+-----------+
|     Header1       | Header2   |Header3    |
+===========================================+
|     One One       | One Two   |One Three  |
|-------------------+-----------+-----------|
|     Two One       | Two Two   |Two Three  |
|-------------------+-----------+-----------|
|     Three One     | Three Two |Three Three|
+-------------------+-----------+-----------+";
    assert_eq!(expected, "\n".to_string() + &table.to_string());
}