use pretty_assertions::assert_eq;
use super_table::*;
#[test]
fn multi_character_utf8_symbols() {
let mut table = Table::new();
table
.set_header(vec!["Header1", "Header2", "Header3"])
.add_row(vec![
"This is a text",
"This is another text",
"This is the third text",
])
.add_row(vec![
"This is another text",
"Now\nadd some\nmulti line stuff",
"✅",
]);
println!("{table}");
let expected = "
+----------------------+----------------------+------------------------+
| Header1 | Header2 | Header3 |
+======================================================================+
| This is a text | This is another text | This is the third text |
|----------------------+----------------------+------------------------|
| This is another text | Now | ✅ |
| | add some | |
| | multi line stuff | |
+----------------------+----------------------+------------------------+";
assert_eq!(expected, "\n".to_string() + &table.to_string());
}
#[test]
fn multi_character_utf8_word_splitting() {
let mut table = Table::new();
table
.set_width(8)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_header(vec!["test"])
.add_row(vec!["abc✅def"]);
println!("{table}");
let expected = "
+------+
| test |
+======+
| abc |
| ✅de |
| f |
+------+";
println!("{expected}");
assert_eq!(expected, "\n".to_string() + &table.to_string());
}
#[test]
fn multi_character_cjk_word_splitting() {
let mut table = Table::new();
table
.set_width(8)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_header(vec!["test"])
.add_row(vec!["abc新年快乐edf"]);
println!("{table}");
let expected = "
+------+
| test |
+======+
| abc |
| 新年 |
| 快乐 |
| edf |
+------+";
println!("{expected}");
assert_eq!(expected, "\n".to_string() + &table.to_string());
}
#[test]
fn zwj_utf8_word_splitting() {
let mut table = Table::new();
table
.set_width(8)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_header(vec!["test"])
.add_row(vec!["ab🙂↕️def"]);
println!("{table}");
let expected = "
+------+
| test |
+======+
| ab🙂↕️ |
| def |
+------+";
println!("{expected}");
assert_eq!(expected, "\n".to_string() + &table.to_string());
}