-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dab6194
commit 96e44ef
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use comfy_table::{presets::UTF8_FULL, *}; | ||
use pretty_assertions::assert_eq; | ||
|
||
fn get_preset_table() -> Table { | ||
let mut table = Table::new(); | ||
table.load_preset(UTF8_FULL); | ||
table.set_content_arrangement(ContentArrangement::Dynamic); | ||
table.set_width(85); | ||
|
||
let mut row = Row::new(); | ||
row.add_cell(Cell::new(format!( | ||
"hello{}cell1", | ||
console::style("123\n456").dim().blue() | ||
))); | ||
row.add_cell(Cell::new("cell2")); | ||
|
||
table.add_row(row); | ||
|
||
let mut row = Row::new(); | ||
row.add_cell(Cell::new( | ||
format!(r"cell sys-devices-pci00:00-0000:000:07:00.1-usb2-2\x2d1-2\x2d1.3-2\x2d1.3:1.0-host2-target2:0:0-2:0:0:1-block-sdb{}", console::style(".device").bold().red()) | ||
)); | ||
row.add_cell(Cell::new( | ||
"cell4 asdfasfsad asdfasdf sad fas df asdf as df asdf asdfasdfasdfasdfasdfasdfa dsfa sdf asdf asd f asdf as df sadf asd fas df " | ||
)); | ||
table.add_row(row); | ||
|
||
let mut row = Row::new(); | ||
row.add_cell(Cell::new("cell5")); | ||
row.add_cell(Cell::new("cell6")); | ||
table.add_row(row); | ||
|
||
table | ||
} | ||
|
||
#[test] | ||
fn styled_table() { | ||
console::set_colors_enabled(true); | ||
let mut table = get_preset_table(); | ||
table.force_no_tty().enforce_styling(); | ||
println!("{table}"); | ||
let expected = " | ||
┌─────────────────────────────────────────┬─────────────────────────────────────────┐ | ||
│ hello\u{1b}[34m\u{1b}[2m123\u{1b}[0m ┆ cell2 │ | ||
│ \u{1b}[34m\u{1b}[2m456\u{1b}[0mcell1 ┆ │ | ||
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ | ||
│ cell sys-devices-pci00:00-0000:000:07:0 ┆ cell4 asdfasfsad asdfasdf sad fas df │ | ||
│ 0.1-usb2-2\\x2d1-2\\x2d1.3-2\\x2d1.3:1.0-h ┆ asdf as df asdf │ | ||
│ ost2-target2:0:0-2:0:0:1-block-sdb\u{1b}[31m\u{1b}[1m.devi\u{1b}[0m ┆ asdfasdfasdfasdfasdfasdfa dsfa sdf asdf │ | ||
│ \u{1b}[31m\u{1b}[1mce\u{1b}[0m ┆ asd f asdf as df sadf asd fas df │ | ||
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ | ||
│ cell5 ┆ cell6 │ | ||
└─────────────────────────────────────────┴─────────────────────────────────────────┘"; | ||
assert_eq!("\n".to_string() + &table.to_string(), expected); | ||
} | ||
|
||
#[test] | ||
fn no_style_styled_table() { | ||
console::set_colors_enabled(true); | ||
let mut table = get_preset_table(); | ||
table.force_no_tty(); | ||
|
||
println!("{table}"); | ||
let expected = " | ||
┌─────────────────────────────────────────┬─────────────────────────────────────────┐ | ||
│ hello\u{1b}[34m\u{1b}[2m123\u{1b}[0m ┆ cell2 │ | ||
│ \u{1b}[34m\u{1b}[2m456\u{1b}[0mcell1 ┆ │ | ||
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ | ||
│ cell sys-devices-pci00:00-0000:000:07:0 ┆ cell4 asdfasfsad asdfasdf sad fas df │ | ||
│ 0.1-usb2-2\\x2d1-2\\x2d1.3-2\\x2d1.3:1.0-h ┆ asdf as df asdf │ | ||
│ ost2-target2:0:0-2:0:0:1-block-sdb\u{1b}[31m\u{1b}[1m.devi\u{1b}[0m ┆ asdfasdfasdfasdfasdfasdfa dsfa sdf asdf │ | ||
│ \u{1b}[31m\u{1b}[1mce\u{1b}[0m ┆ asd f asdf as df sadf asd fas df │ | ||
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ | ||
│ cell5 ┆ cell6 │ | ||
└─────────────────────────────────────────┴─────────────────────────────────────────┘"; | ||
assert_eq!("\n".to_string() + &table.to_string(), expected); | ||
} | ||
|
||
#[test] | ||
fn styled_text_only_table() { | ||
console::set_colors_enabled(true); | ||
let mut table = get_preset_table(); | ||
table.force_no_tty().enforce_styling().style_text_only(); | ||
println!("{table}"); | ||
let expected = " | ||
┌─────────────────────────────────────────┬─────────────────────────────────────────┐ | ||
│ hello\u{1b}[34m\u{1b}[2m123\u{1b}[0m ┆ cell2 │ | ||
│ \u{1b}[34m\u{1b}[2m456\u{1b}[0mcell1 ┆ │ | ||
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ | ||
│ cell sys-devices-pci00:00-0000:000:07:0 ┆ cell4 asdfasfsad asdfasdf sad fas df │ | ||
│ 0.1-usb2-2\\x2d1-2\\x2d1.3-2\\x2d1.3:1.0-h ┆ asdf as df asdf │ | ||
│ ost2-target2:0:0-2:0:0:1-block-sdb\u{1b}[31m\u{1b}[1m.devi\u{1b}[0m ┆ asdfasdfasdfasdfasdfasdfa dsfa sdf asdf │ | ||
│ \u{1b}[31m\u{1b}[1mce\u{1b}[0m ┆ asd f asdf as df sadf asd fas df │ | ||
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ | ||
│ cell5 ┆ cell6 │ | ||
└─────────────────────────────────────────┴─────────────────────────────────────────┘"; | ||
assert_eq!("\n".to_string() + &table.to_string(), expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters