Debian Codegraph @

tests/all/custom_delimiter_test.rs

raw symbols SCIP
1 use comfy_table::*;
2 use pretty_assertions::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 #[test]
9 fn full_custom_delimiters() {
10 let mut table = Table::new();
11
12 table
13 .set_header(vec!["Header1", "Header2"])
14 .set_content_arrangement(ContentArrangement::Dynamic)
15 .set_delimiter('-')
16 .set_width(40)
17 .add_row(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_row(vec![
24 Cell::new("Test_Test_Test_Test_Test_This-should-only-be-splitted-by-hyphens-not by space or underscore",),
25 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_delimiter('/'),
29 ]);
30
31 let column = table.column_mut(1).unwrap();
32 column.set_delimiter('_');
33
34 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 println!("{expected}");
59 assert_eq!(expected, "\n".to_string() + &table.to_string());
60 }