From 760999d300a83adfe2a24dcdfae21525818f27f3 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Wed, 5 Jun 2024 10:36:49 -0400 Subject: [PATCH] Fix more tests --- cursive-core/src/buffer.rs | 15 +++++++++------ cursive-core/src/printer.rs | 13 ++++--------- cursive-core/src/utils/lines/spans/tests.rs | 2 -- cursive-core/src/view/scroll_base.rs | 7 +++---- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/cursive-core/src/buffer.rs b/cursive-core/src/buffer.rs index d8f457ad0..ad3543270 100644 --- a/cursive-core/src/buffer.rs +++ b/cursive-core/src/buffer.rs @@ -100,7 +100,7 @@ impl PrintBuffer { PrintBuffer { active_buffer: Vec::new(), frozen_buffer: Vec::new(), - current_style : ConcreteStyle::terminal_default(), + current_style: ConcreteStyle::terminal_default(), size: Vec2::ZERO, } } @@ -183,7 +183,10 @@ impl PrintBuffer { // TODO: Use some WithWidth(&str, usize) to not re-compute width a thousand times for g in text.graphemes(true) { let width = g.width(); - self.set_cell(pos, g, width, style); + if width == 0 { + continue; + } + self.set_cell(pos, g, CellWidth::from_usize(width), style); pos.x += width; } } @@ -207,8 +210,8 @@ impl PrintBuffer { /// Set a cell. /// /// width _must_ be grapheme.width(). - fn set_cell(&mut self, pos: Vec2, grapheme: &str, width: usize, style: ConcreteStyle) { - debug_assert_eq!(width, grapheme.width()); + fn set_cell(&mut self, pos: Vec2, grapheme: &str, width: CellWidth, style: ConcreteStyle) { + debug_assert_eq!(width.as_usize(), grapheme.width()); let id = self.cell_id(pos); @@ -216,10 +219,10 @@ impl PrintBuffer { cell.style = style; cell.text.clear(); cell.text.push_str(grapheme); - cell.width = CellWidth::from_usize(width); + cell.width = width; // If this is a double-wide grapheme, mark the next cell as blocked. - for dx in 1..width { + for dx in 1..width.as_usize() { if pos.x + dx >= self.size.x { break; } diff --git a/cursive-core/src/printer.rs b/cursive-core/src/printer.rs index a3d35f9a1..4a49d0b5a 100644 --- a/cursive-core/src/printer.rs +++ b/cursive-core/src/printer.rs @@ -409,13 +409,11 @@ impl<'a, 'b> Printer<'a, 'b> { /// ```rust /// # use cursive_core::Printer; /// # use cursive_core::theme; - /// # use cursive_core::buffer; - /// # let b = buffer::Dummy::init(); - /// # let t = theme::load_default(); - /// # let printer = Printer::new((6,4), &t, &*b); + /// # fn with_printer(printer: &Printer) { /// printer.with_style(theme::PaletteStyle::Highlight, |printer| { /// printer.print((0, 0), "This text is highlighted!"); /// }); + /// # } /// ``` pub fn with_style(&self, style: T, f: F) where @@ -485,12 +483,9 @@ impl<'a, 'b> Printer<'a, 'b> { /// /// ```rust /// # use cursive_core::Printer; - /// # use cursive_core::theme; - /// # use cursive_core::buffer; - /// # let b = buffer::Dummy::init(); - /// # let t = theme::load_default(); - /// # let printer = Printer::new((6,4), &t, &*b); + /// # fn with_printer(printer: &Printer) { /// printer.print_box((0, 0), (6, 4), false); + /// # } /// ``` pub fn print_box, S: Into>(&self, start: T, size: S, invert: bool) { let start = start.into(); diff --git a/cursive-core/src/utils/lines/spans/tests.rs b/cursive-core/src/utils/lines/spans/tests.rs index 6e484eb01..40c5ac804 100644 --- a/cursive-core/src/utils/lines/spans/tests.rs +++ b/cursive-core/src/utils/lines/spans/tests.rs @@ -45,8 +45,6 @@ fn test_line_breaks() { let rows: Vec<_> = iter.map(|row| row.resolve(&input)).collect(); - // println!("{:?}", rows); - assert_eq!( &rows[..], &[ diff --git a/cursive-core/src/view/scroll_base.rs b/cursive-core/src/view/scroll_base.rs index 54ba10205..5161c46da 100644 --- a/cursive-core/src/view/scroll_base.rs +++ b/cursive-core/src/view/scroll_base.rs @@ -216,15 +216,14 @@ impl ScrollBase { /// # Examples /// /// ```rust + /// # #[allow(deprecated)] + /// # fn with_printer(printer: &cursive_core::Printer) { /// # let scrollbase = cursive_core::view::ScrollBase::new(); - /// # let b = cursive_core::backend::Dummy::init(); - /// # let t = cursive_core::theme::load_default(); - /// # let printer = &cursive_core::Printer::new((5,1), &t, &*b); - /// # let printer = &printer; /// let lines = ["Line 1", "Line number 2"]; /// scrollbase.draw(printer, |printer, i| { /// printer.print((0, 0), lines[i]); /// }); + /// # } /// ``` pub fn draw(&self, printer: &Printer, line_drawer: F) where