| 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 | /// Create a table with a custom delimiter on Table, Column and Cell level. |
| 5 | /// The first column should be split with the table's delimiter. |
| 6 | /// The first cell of the second column should be split with the custom column delimiter |
| 7 | /// The second cell of the second column should be split with the custom cell delimiter |
| 8 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 9 | fn full_custom_delimitersrust-analyzer cargo comfy-table 7.2.2 all/custom_delimiter_test/full_custom_delimiters().() { |
| 10 | 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().(); |
| 11 | |
| 12 | table |
| 13 | .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!!["Header1", "Header2"]) |
| 14 | .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#) |
| 15 | .set_delimiterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_delimiter().('-') |
| 16 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(40) |
| 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!![ |
| 18 | "This shouldn't be split with any logic, since there's no matching delimiter", |
| 19 | "Test-Test-Test-Test-Test-This_should_only_be_splitted_by_underscore_and not by space or hyphens", |
| 20 | ]); |
| 21 | |
| 22 | // Give the bottom right cell a special delimiter |
| 23 | table.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!![ |
| 24 | Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Test_Test_Test_Test_Test_This-should-only-be-splitted-by-hyphens-not by space or underscore",), |
| 25 | Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().( |
| 26 | "Test-Test-Test-Test-Test-Test_Test_Test_Test_Test_Test_Test_This/should/only/be/splitted/by/backspace/and not by space or hyphens or anything else.", |
| 27 | ) |
| 28 | .set_delimiterrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]set_delimiter().('/'), |
| 29 | ]); |
| 30 | |
| 31 | let column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 32 | column.set_delimiterrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_delimiter().('_'); |
| 33 | |
| 34 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 35 | let expected = " |
| 36 | +-------------------+------------------+ |
| 37 | | Header1 | Header2 | |
| 38 | +======================================+ |
| 39 | | This shouldn't be | Test-Test-Test-T | |
| 40 | | split with any l | est-Test-This | |
| 41 | | ogic, since there | should_only_be | |
| 42 | | 's no matching de | splitted_by | |
| 43 | | limiter | underscore_and n | |
| 44 | | | ot by space or h | |
| 45 | | | yphens | |
| 46 | |-------------------+------------------| |
| 47 | | Test_Test_Test_Te | Test-Test-Test-T | |
| 48 | | st_Test_This | est-Test-Test_Te | |
| 49 | | should-only-be | st_Test_Test_Tes | |
| 50 | | splitted-by | t_Test_Test_This | |
| 51 | | hyphens-not by sp | should/only/be | |
| 52 | | ace or underscore | splitted/by | |
| 53 | | | backspace/and no | |
| 54 | | | t by space or hy | |
| 55 | | | phens or anythin | |
| 56 | | | g else. | |
| 57 | +-------------------+------------------+"; |
| 58 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 59 | 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().()); |
| 60 | } |