| 1 | use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::*; |
| 2 | use pretty_assertionsrust-analyzer cargo pretty_assertions 1.4.1 crate/::assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!; |
| 3 | |
| 4 | /// Columns can set a custom padding. |
| 5 | /// Ensure these settings are working. |
| 6 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7 | fn custom_paddingrust-analyzer cargo comfy-table 7.2.2 all/padding_test/custom_padding().() { |
| 8 | let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().(); |
| 9 | table |
| 10 | .set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 11 | Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Header1"), |
| 12 | Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Header2"), |
| 13 | Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Header3"), |
| 14 | ]) |
| 15 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["One One", "One Two", "One Three"]) |
| 16 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Two One", "Two Two", "Two Three"]) |
| 17 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Three One", "Three Two", "Three Three"]); |
| 18 | |
| 19 | let column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 20 | column.set_paddingrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_padding().((5, 5)); |
| 21 | let column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 22 | column.set_paddingrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_padding().((0, 0)); |
| 23 | |
| 24 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/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_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(expected, "\n".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). &table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 36 | } |