mirror of
https://github.com/nushell/nushell
synced 2024-12-29 06:23:11 +00:00
a98b3124c5
Reverts nushell/nushell#9796 This is just draft since we're seeing some issues with the latest fixes to table drawing that just landed with #9796. We're hoping to get these fixed, but if we're not able to fix them before the next release, we'll need to revert (hence this PR, just in case we need it).
56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use nu_table::{string_width, NuTable, TableConfig};
|
|
use tabled::grid::records::vec_records::CellInfo;
|
|
|
|
pub struct TestCase {
|
|
cfg: TableConfig,
|
|
termwidth: usize,
|
|
expected: Option<String>,
|
|
}
|
|
|
|
impl TestCase {
|
|
pub fn new(cfg: TableConfig, 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: TableConfig, 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())
|
|
}
|