| 1 | use comfy_table::{presets::UTF8_FULL, *}; |
| 2 | use pretty_assertions::assert_eq; |
| 3 | |
| 4 | fn get_preset_table() -> Table { |
| 5 | let mut table = Table::new(); |
| 6 | table.load_preset(UTF8_FULL) |
| 7 | .set_content_arrangement(ContentArrangement::Dynamic) |
| 8 | .set_width(80) |
| 9 | .set_header(vec![ |
| 10 | Cell::new("Header1").add_attribute(Attribute::Bold), |
| 11 | Cell::new("Header2").fg(Color::Green), |
| 12 | Cell::new("Header3"), |
| 13 | ]) |
| 14 | .add_row(vec![ |
| 15 | Cell::new("This is a bold text").add_attribute(Attribute::Bold), |
| 16 | Cell::new("This is a green text").fg(Color::Green), |
| 17 | Cell::new("This one has black background").bg(Color::Black), |
| 18 | ]) |
| 19 | .add_row(vec![ |
| 20 | Cell::new("Blinky boi").add_attribute(Attribute::SlowBlink), |
| 21 | Cell::new("This table's content is dynamically arranged. The table is exactly 80 characters wide.\nHere comes a reallylongwordthatshoulddynamicallywrap"), |
| 22 | Cell::new("COMBINE ALL THE THINGS") |
| 23 | .fg(Color::Green) |
| 24 | .bg(Color::Black) |
| 25 | .add_attributes(vec![ |
| 26 | Attribute::Bold, |
| 27 | Attribute::SlowBlink, |
| 28 | ]) |
| 29 | ]); |
| 30 | |
| 31 | table |
| 32 | } |
| 33 | |
| 34 | #[test] |
| 35 | fn combined_features() { |
| 36 | let mut table = get_preset_table(); |
| 37 | table.force_no_tty().enforce_styling(); |
| 38 | println!("{table}"); |
| 39 | let expected = " |
| 40 | ┌─────────────────────┬───────────────────────────────┬────────────────────────┐ |
| 41 | │\u{1b}[1m Header1 \u{1b}[0m┆\u{1b}[38;5;10m Header2 \u{1b}[39m┆ Header3 │ |
| 42 | ╞═════════════════════╪═══════════════════════════════╪════════════════════════╡ |
| 43 | │\u{1b}[1m This is a bold text \u{1b}[0m┆\u{1b}[38;5;10m This is a green text \u{1b}[39m┆\u{1b}[48;5;0m This one has black \u{1b}[49m│ |
| 44 | │ ┆ ┆\u{1b}[48;5;0m background \u{1b}[49m│ |
| 45 | ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ |
| 46 | │\u{1b}[5m Blinky boi \u{1b}[0m┆ This table\'s content is ┆\u{1b}[48;5;0m\u{1b}[38;5;10m\u{1b}[1m\u{1b}[5m COMBINE ALL THE THINGS \u{1b}[0m│ |
| 47 | │ ┆ dynamically arranged. The ┆ │ |
| 48 | │ ┆ table is exactly 80 ┆ │ |
| 49 | │ ┆ characters wide. ┆ │ |
| 50 | │ ┆ Here comes a reallylongwordth ┆ │ |
| 51 | │ ┆ atshoulddynamicallywrap ┆ │ |
| 52 | └─────────────────────┴───────────────────────────────┴────────────────────────┘"; |
| 53 | println!("{expected}"); |
| 54 | assert_eq!(expected, "\n".to_string() + &table.to_string()); |
| 55 | } |