fix widths for fallback to single column

This commit is contained in:
Terts Diepraam
2023-11-07 11:50:49 +01:00
parent b6d8ba188f
commit a96ad3d86d
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ impl<T: AsRef<str>> Grid<T> {
grid.dimensions = grid.width_dimensions(width).unwrap_or(Dimensions {
num_lines: grid.cells.len(),
widths: grid.widths.clone(),
widths: vec![widest_cell_width],
});
grid
+20
View File
@@ -1,6 +1,8 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore underflowed
use term_grid::{Direction, Filling, Grid, GridOptions};
#[test]
@@ -187,6 +189,24 @@ fn emoji() {
assert_eq!("🦀 hello\n👩‍🔬 hello\n", grid.to_string());
}
// This test once underflowed, which should never happen. The test is just
// checking that we do not get a panic.
#[test]
fn possible_underflow() {
let cells: Vec<_> = (0..48).map(|i| 2_isize.pow(i).to_string()).collect();
let grid = Grid::new(
cells,
GridOptions {
direction: Direction::TopToBottom,
filling: Filling::Text(" | ".into()),
width: 15,
},
);
println!("{}", grid);
}
// These test are based on the tests in uutils ls, to ensure we won't break
// it while editing this library.
mod uutils_ls {