mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 16:58:51 +02:00
fix https://github.com/nushell/nushell/issues/7380
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
use std::collections::HashMap;
|
||||
mod common;
|
||||
|
||||
use nu_protocol::Config;
|
||||
use nu_table::{Alignments, Table, TableTheme as theme, TextStyle};
|
||||
use tabled::papergrid::records::{cell_info::CellInfo, tcell::TCell};
|
||||
use common::{create_row, create_table};
|
||||
use nu_table::{TableConfig, TableTheme as theme};
|
||||
|
||||
#[test]
|
||||
fn test_expand() {
|
||||
let table = create_table(
|
||||
vec![create_row(4); 3],
|
||||
TableConfig::new(theme::rounded(), true, false, false).expand(),
|
||||
50,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
draw_table(vec![row(4); 3], 4, true, theme::rounded(), 50),
|
||||
table.unwrap(),
|
||||
"╭────────────┬───────────┬───────────┬───────────╮\n\
|
||||
│ 0 │ 1 │ 2 │ 3 │\n\
|
||||
├────────────┼───────────┼───────────┼───────────┤\n\
|
||||
@@ -16,31 +21,3 @@ fn test_expand() {
|
||||
╰────────────┴───────────┴───────────┴───────────╯"
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_table(
|
||||
data: Vec<Vec<TCell<CellInfo<'static>, TextStyle>>>,
|
||||
count_columns: usize,
|
||||
with_header: bool,
|
||||
theme: theme,
|
||||
width: usize,
|
||||
) -> String {
|
||||
let size = (data.len(), count_columns);
|
||||
let table = Table::new(data, size, width, with_header, false);
|
||||
|
||||
let cfg = Config::default();
|
||||
let styles = HashMap::default();
|
||||
let alignments = Alignments::default();
|
||||
table
|
||||
.draw_table(&cfg, &styles, alignments, &theme, width, true)
|
||||
.expect("Unexpectdly got no table")
|
||||
}
|
||||
|
||||
fn row(count_columns: usize) -> Vec<TCell<CellInfo<'static>, TextStyle>> {
|
||||
let mut row = Vec::with_capacity(count_columns);
|
||||
|
||||
for i in 0..count_columns {
|
||||
row.push(Table::create_cell(i.to_string(), TextStyle::default()));
|
||||
}
|
||||
|
||||
row
|
||||
}
|
||||
|
Reference in New Issue
Block a user