2022-12-15 15:47:04 +01:00
|
|
|
mod common;
|
2022-07-18 18:45:21 +02:00
|
|
|
|
2023-04-26 20:56:10 +02:00
|
|
|
use common::create_row as row;
|
2023-08-04 20:50:47 +02:00
|
|
|
use nu_table::{NuTable, NuTableConfig, TableTheme as theme};
|
2024-08-24 00:35:42 +02:00
|
|
|
use tabled::grid::records::vec_records::Text;
|
2022-07-18 18:45:21 +02:00
|
|
|
|
|
|
|
#[test]
|
2022-07-19 19:35:13 +02:00
|
|
|
fn test_rounded() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::rounded()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"╭───┬───┬───┬───╮\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
├───┼───┼───┼───┤\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
╰───┴───┴───┴───╯"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::rounded()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"╭───┬───┬───┬───╮\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
├───┼───┼───┼───┤\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
╰───┴───┴───┴───╯"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::rounded()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"╭───┬───┬───┬───╮\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
╰───┴───┴───┴───╯"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::rounded()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"╭───┬───┬───┬───╮\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
╰───┴───┴───┴───╯"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::rounded()),
|
2022-10-03 18:40:16 +02:00
|
|
|
"╭───┬───┬───┬───╮\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
╰───┴───┴───┴───╯"
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
2022-10-03 18:40:16 +02:00
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::rounded()), "");
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basic() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::basic()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::basic()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::basic()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::basic()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::basic()),
|
2022-10-03 18:40:16 +02:00
|
|
|
"+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+\n\
|
|
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
|
|
+---+---+---+---+"
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
2022-10-03 18:40:16 +02:00
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::basic()), "");
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_reinforced() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::reinforced()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏───┬───┬───┬───┓\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
┗───┴───┴───┴───┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::reinforced()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏───┬───┬───┬───┓\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
┗───┴───┴───┴───┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::reinforced()),
|
2022-10-03 18:40:16 +02:00
|
|
|
"┏───┬───┬───┬───┓\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
┗───┴───┴───┴───┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::reinforced()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏───┬───┬───┬───┓\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
┗───┴───┴───┴───┛"
|
|
|
|
);
|
2022-07-18 18:45:21 +02:00
|
|
|
|
2022-07-19 19:35:13 +02:00
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::reinforced()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏───┬───┬───┬───┓\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
┗───┴───┴───┴───┛"
|
2022-07-18 18:45:21 +02:00
|
|
|
);
|
|
|
|
|
2022-07-19 19:35:13 +02:00
|
|
|
assert_eq!(
|
2024-05-02 19:29:03 +02:00
|
|
|
create_table_with_size(vec![], true, theme::reinforced()),
|
2022-07-19 19:35:13 +02:00
|
|
|
""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_compact() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::compact()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"───┬───┬───┬───\n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
"───┼───┼───┼───\n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
"───┴───┴───┴───",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::compact()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"───┬───┬───┬───\n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
"───┼───┼───┼───\n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
"───┴───┴───┴───",
|
|
|
|
)
|
|
|
|
);
|
2022-07-18 18:45:21 +02:00
|
|
|
|
2022-07-19 19:35:13 +02:00
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::compact()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!("───┬───┬───┬───\n", " 0 │ 1 │ 2 │ 3 \n", "───┴───┴───┴───",)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::compact()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!("───┬───┬───┬───\n", " 0 │ 1 │ 2 │ 3 \n", "───┴───┴───┴───",)
|
2022-07-18 18:45:21 +02:00
|
|
|
);
|
|
|
|
|
2022-07-19 19:35:13 +02:00
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::compact()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"───┬───┬───┬───\n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
|
|
"───┴───┴───┴───",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::compact()), "");
|
2022-07-18 18:45:21 +02:00
|
|
|
}
|
|
|
|
|
2022-07-19 19:35:13 +02:00
|
|
|
#[test]
|
|
|
|
fn test_compact_double() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::compact_double()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"═══╦═══╦═══╦═══\n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
"═══╬═══╬═══╬═══\n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
"═══╩═══╩═══╩═══",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::compact_double()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"═══╦═══╦═══╦═══\n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
"═══╬═══╬═══╬═══\n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
"═══╩═══╩═══╩═══",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::compact_double()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!("═══╦═══╦═══╦═══\n", " 0 ║ 1 ║ 2 ║ 3 \n", "═══╩═══╩═══╩═══",)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::compact_double()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!("═══╦═══╦═══╦═══\n", " 0 ║ 1 ║ 2 ║ 3 \n", "═══╩═══╩═══╩═══",)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::compact_double()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"═══╦═══╦═══╦═══\n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
|
|
"═══╩═══╩═══╩═══",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-05-02 19:29:03 +02:00
|
|
|
create_table_with_size(vec![], true, theme::compact_double()),
|
2022-07-19 19:35:13 +02:00
|
|
|
""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_heavy() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::heavy()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┣━━━╋━━━╋━━━╋━━━┫\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::heavy()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┣━━━╋━━━╋━━━╋━━━┫\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::heavy()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::heavy()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::heavy()),
|
2022-10-03 18:40:16 +02:00
|
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
2022-10-03 18:40:16 +02:00
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::heavy()), "");
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_light() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::light()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
" 0 1 2 3 \n",
|
|
|
|
"───────────────\n",
|
|
|
|
" 0 1 2 3 \n",
|
|
|
|
" 0 1 2 3 ",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::light()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(" 0 1 2 3 \n", "───────────────\n", " 0 1 2 3 ")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::light()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(" 0 1 2 3 ")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::light()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!(" 0 1 2 3 ")
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::light()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
2022-10-03 18:40:16 +02:00
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::light()), "");
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_none() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::none()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 \n", " 0 1 2 3 ")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::none()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::none()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(" 0 1 2 3 ")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::none()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!(" 0 1 2 3 ")
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::none()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
2022-10-03 18:40:16 +02:00
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::none()), "");
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_thin() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::thin()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┌───┬───┬───┬───┐\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
├───┼───┼───┼───┤\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
├───┼───┼───┼───┤\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
└───┴───┴───┴───┘"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::thin()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┌───┬───┬───┬───┐\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
├───┼───┼───┼───┤\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
└───┴───┴───┴───┘"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::thin()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┌───┬───┬───┬───┐\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
└───┴───┴───┴───┘"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::thin()),
|
2022-07-19 19:35:13 +02:00
|
|
|
"┌───┬───┬───┬───┐\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
└───┴───┴───┴───┘"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::thin()),
|
2022-10-03 18:40:16 +02:00
|
|
|
"┌───┬───┬───┬───┐\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
├───┼───┼───┼───┤\n\
|
|
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
|
|
└───┴───┴───┴───┘"
|
2022-07-19 19:35:13 +02:00
|
|
|
);
|
2022-10-03 18:40:16 +02:00
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::thin()), "");
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_love() {
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 3], true, theme::with_love()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], true, theme::with_love()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], true, theme::with_love()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!("❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n", " 0 ❤ 1 ❤ 2 ❤ 3 \n", "❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 1], false, theme::with_love()),
|
2022-10-03 18:40:16 +02:00
|
|
|
concat!("❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n", " 0 ❤ 1 ❤ 2 ❤ 3 \n", "❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2022-12-15 15:47:04 +01:00
|
|
|
create_table(vec![row(4); 2], false, theme::with_love()),
|
2022-07-19 19:35:13 +02:00
|
|
|
concat!(
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2024-05-02 19:29:03 +02:00
|
|
|
assert_eq!(create_table_with_size(vec![], true, theme::with_love()), "");
|
2022-12-15 15:47:04 +01:00
|
|
|
}
|
|
|
|
|
2024-08-24 00:35:42 +02:00
|
|
|
fn create_table(data: Vec<Vec<Text<String>>>, with_header: bool, theme: theme) -> String {
|
2023-08-04 20:50:47 +02:00
|
|
|
let config = NuTableConfig {
|
|
|
|
theme,
|
|
|
|
with_header,
|
|
|
|
..Default::default()
|
|
|
|
};
|
2023-04-26 20:56:10 +02:00
|
|
|
|
2022-12-15 15:47:04 +01:00
|
|
|
let out = common::create_table(data, config, usize::MAX);
|
|
|
|
|
|
|
|
out.expect("not expected to get None")
|
2022-07-19 19:35:13 +02:00
|
|
|
}
|
|
|
|
|
2024-08-24 00:35:42 +02:00
|
|
|
fn create_table_with_size(data: Vec<Vec<Text<String>>>, with_header: bool, theme: theme) -> String {
|
2023-08-04 20:50:47 +02:00
|
|
|
let config = NuTableConfig {
|
|
|
|
theme,
|
|
|
|
with_header,
|
|
|
|
..Default::default()
|
|
|
|
};
|
2022-07-19 19:35:13 +02:00
|
|
|
|
2023-04-26 20:56:10 +02:00
|
|
|
let table = NuTable::from(data);
|
2022-07-19 19:35:13 +02:00
|
|
|
|
2022-12-15 15:47:04 +01:00
|
|
|
table
|
|
|
|
.draw(config, usize::MAX)
|
|
|
|
.expect("not expected to get None")
|
2022-07-18 18:45:21 +02:00
|
|
|
}
|