mirror of
https://github.com/nushell/nushell.git
synced 2024-12-12 18:20:55 +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>
57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use nu_table::{string_width, NuTable, NuTableConfig};
|
|
use tabled::grid::records::vec_records::CellInfo;
|
|
|
|
pub struct TestCase {
|
|
cfg: NuTableConfig,
|
|
termwidth: usize,
|
|
expected: Option<String>,
|
|
}
|
|
|
|
impl TestCase {
|
|
pub fn new(cfg: NuTableConfig, termwidth: usize, expected: Option<String>) -> Self {
|
|
Self {
|
|
cfg,
|
|
termwidth,
|
|
expected,
|
|
}
|
|
}
|
|
}
|
|
|
|
type Data = Vec<Vec<CellInfo<String>>>;
|
|
|
|
pub fn test_table<I: IntoIterator<Item = TestCase>>(data: Data, tests: I) {
|
|
for (i, test) in tests.into_iter().enumerate() {
|
|
let actual = create_table(data.clone(), test.cfg.clone(), test.termwidth);
|
|
|
|
assert_eq!(
|
|
actual, test.expected,
|
|
"\nfail i={:?} termwidth={}",
|
|
i, test.termwidth
|
|
);
|
|
|
|
if let Some(table) = actual {
|
|
assert!(string_width(&table) <= test.termwidth);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn create_table(data: Data, config: NuTableConfig, termwidth: usize) -> Option<String> {
|
|
let table = NuTable::from(data);
|
|
table.draw(config, termwidth)
|
|
}
|
|
|
|
pub fn create_row(count_columns: usize) -> Vec<CellInfo<String>> {
|
|
let mut row = Vec::with_capacity(count_columns);
|
|
for i in 0..count_columns {
|
|
row.push(CellInfo::new(i.to_string()));
|
|
}
|
|
|
|
row
|
|
}
|
|
|
|
pub fn cell(text: &str) -> CellInfo<String> {
|
|
CellInfo::new(text.to_string())
|
|
}
|