mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
7e096e61d7
fix #9796 Sorry that you've had the issues. I've actually encountered them yesterday too (seems like they have appeared after some refactoring in the middle) but was not able to fix that rapid. Created a bunch of tests. cc: @fdncred Note: This option will be certainly slower then a default ones. (could be fixed but ... maybe later). Maybe it shall be cited somewhere. PS: Haven't tested on a wrapped/expanded tables. --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
507 lines
15 KiB
Rust
507 lines
15 KiB
Rust
mod common;
|
|
|
|
use common::create_row as row;
|
|
use nu_table::{NuTable, NuTableConfig, TableTheme as theme};
|
|
use tabled::grid::records::vec_records::CellInfo;
|
|
|
|
#[test]
|
|
fn test_rounded() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::rounded()),
|
|
"╭───┬───┬───┬───╮\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
├───┼───┼───┼───┤\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
╰───┴───┴───┴───╯"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::rounded()),
|
|
"╭───┬───┬───┬───╮\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
├───┼───┼───┼───┤\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
╰───┴───┴───┴───╯"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::rounded()),
|
|
"╭───┬───┬───┬───╮\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
╰───┴───┴───┴───╯"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::rounded()),
|
|
"╭───┬───┬───┬───╮\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
╰───┴───┴───┴───╯"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::rounded()),
|
|
"╭───┬───┬───┬───╮\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
╰───┴───┴───┴───╯"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::rounded()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_basic() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::basic()),
|
|
"+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::basic()),
|
|
"+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::basic()),
|
|
"+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::basic()),
|
|
"+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::basic()),
|
|
"+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+\n\
|
|
| 0 | 1 | 2 | 3 |\n\
|
|
+---+---+---+---+"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::basic()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_reinforced() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::reinforced()),
|
|
"┏───┬───┬───┬───┓\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
┗───┴───┴───┴───┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::reinforced()),
|
|
"┏───┬───┬───┬───┓\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
┗───┴───┴───┴───┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::reinforced()),
|
|
"┏───┬───┬───┬───┓\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
┗───┴───┴───┴───┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::reinforced()),
|
|
"┏───┬───┬───┬───┓\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
┗───┴───┴───┴───┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::reinforced()),
|
|
"┏───┬───┬───┬───┓\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
┗───┴───┴───┴───┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::reinforced()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_compact() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::compact()),
|
|
concat!(
|
|
"───┬───┬───┬───\n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
"───┼───┼───┼───\n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
"───┴───┴───┴───",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::compact()),
|
|
concat!(
|
|
"───┬───┬───┬───\n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
"───┼───┼───┼───\n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
"───┴───┴───┴───",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::compact()),
|
|
concat!("───┬───┬───┬───\n", " 0 │ 1 │ 2 │ 3 \n", "───┴───┴───┴───",)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::compact()),
|
|
concat!("───┬───┬───┬───\n", " 0 │ 1 │ 2 │ 3 \n", "───┴───┴───┴───",)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::compact()),
|
|
concat!(
|
|
"───┬───┬───┬───\n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
" 0 │ 1 │ 2 │ 3 \n",
|
|
"───┴───┴───┴───",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::compact()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_compact_double() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::compact_double()),
|
|
concat!(
|
|
"═══╦═══╦═══╦═══\n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
"═══╬═══╬═══╬═══\n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
"═══╩═══╩═══╩═══",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::compact_double()),
|
|
concat!(
|
|
"═══╦═══╦═══╦═══\n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
"═══╬═══╬═══╬═══\n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
"═══╩═══╩═══╩═══",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::compact_double()),
|
|
concat!("═══╦═══╦═══╦═══\n", " 0 ║ 1 ║ 2 ║ 3 \n", "═══╩═══╩═══╩═══",)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::compact_double()),
|
|
concat!("═══╦═══╦═══╦═══\n", " 0 ║ 1 ║ 2 ║ 3 \n", "═══╩═══╩═══╩═══",)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::compact_double()),
|
|
concat!(
|
|
"═══╦═══╦═══╦═══\n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
" 0 ║ 1 ║ 2 ║ 3 \n",
|
|
"═══╩═══╩═══╩═══",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::compact_double()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_heavy() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::heavy()),
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┣━━━╋━━━╋━━━╋━━━┫\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::heavy()),
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┣━━━╋━━━╋━━━╋━━━┫\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::heavy()),
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::heavy()),
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::heavy()),
|
|
"┏━━━┳━━━┳━━━┳━━━┓\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┃ 0 ┃ 1 ┃ 2 ┃ 3 ┃\n\
|
|
┗━━━┻━━━┻━━━┻━━━┛"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::heavy()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_light() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::light()),
|
|
concat!(
|
|
" 0 1 2 3 \n",
|
|
"───────────────\n",
|
|
" 0 1 2 3 \n",
|
|
" 0 1 2 3 ",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::light()),
|
|
concat!(" 0 1 2 3 \n", "───────────────\n", " 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::light()),
|
|
concat!(" 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::light()),
|
|
concat!(" 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::light()),
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::light()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_none() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::none()),
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 \n", " 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::none()),
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::none()),
|
|
concat!(" 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::none()),
|
|
concat!(" 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::none()),
|
|
concat!(" 0 1 2 3 \n", " 0 1 2 3 ")
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::none()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_thin() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::thin()),
|
|
"┌───┬───┬───┬───┐\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
├───┼───┼───┼───┤\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
├───┼───┼───┼───┤\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
└───┴───┴───┴───┘"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::thin()),
|
|
"┌───┬───┬───┬───┐\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
├───┼───┼───┼───┤\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
└───┴───┴───┴───┘"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::thin()),
|
|
"┌───┬───┬───┬───┐\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
└───┴───┴───┴───┘"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::thin()),
|
|
"┌───┬───┬───┬───┐\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
└───┴───┴───┴───┘"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::thin()),
|
|
"┌───┬───┬───┬───┐\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
├───┼───┼───┼───┤\n\
|
|
│ 0 │ 1 │ 2 │ 3 │\n\
|
|
└───┴───┴───┴───┘"
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::thin()),
|
|
""
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_with_love() {
|
|
assert_eq!(
|
|
create_table(vec![row(4); 3], true, theme::with_love()),
|
|
concat!(
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], true, theme::with_love()),
|
|
concat!(
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], true, theme::with_love()),
|
|
concat!("❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n", " 0 ❤ 1 ❤ 2 ❤ 3 \n", "❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 1], false, theme::with_love()),
|
|
concat!("❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n", " 0 ❤ 1 ❤ 2 ❤ 3 \n", "❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table(vec![row(4); 2], false, theme::with_love()),
|
|
concat!(
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤\n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
" 0 ❤ 1 ❤ 2 ❤ 3 \n",
|
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
create_table_with_size(vec![row(4); 0], true, theme::with_love()),
|
|
""
|
|
);
|
|
}
|
|
|
|
fn create_table(data: Vec<Vec<CellInfo<String>>>, with_header: bool, theme: theme) -> String {
|
|
let config = NuTableConfig {
|
|
theme,
|
|
with_header,
|
|
..Default::default()
|
|
};
|
|
|
|
let out = common::create_table(data, config, usize::MAX);
|
|
|
|
out.expect("not expected to get None")
|
|
}
|
|
|
|
fn create_table_with_size(
|
|
data: Vec<Vec<CellInfo<String>>>,
|
|
with_header: bool,
|
|
theme: theme,
|
|
) -> String {
|
|
let config = NuTableConfig {
|
|
theme,
|
|
with_header,
|
|
..Default::default()
|
|
};
|
|
|
|
let table = NuTable::from(data);
|
|
|
|
table
|
|
.draw(config, usize::MAX)
|
|
.expect("not expected to get None")
|
|
}
|