From a96ad3d86dda9ea9937c1f282d45967ae84dc0f3 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 3 Nov 2023 21:25:03 +0100 Subject: [PATCH] fix widths for fallback to single column --- src/lib.rs | 2 +- tests/test.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index faf43bf..5300dd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ impl> Grid { grid.dimensions = grid.width_dimensions(width).unwrap_or(Dimensions { num_lines: grid.cells.len(), - widths: grid.widths.clone(), + widths: vec![widest_cell_width], }); grid diff --git a/tests/test.rs b/tests/test.rs index 3cad808..03532d5 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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 {