From da7cb69c27b8a94325f4b9b2f31b58ed78ecacb6 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 25 Mar 2018 21:09:18 +0200 Subject: [PATCH] Fix selection tests The latest selection changes broke a few tests, these have been corrected. Two of these tests were broken because they assumed different span types, the test have been changed here because the result was correct. One test did actually catch a bug where selection of two cells from right to left would incorrectly mark the cells as selected even though they should not have been, this has been fixed in the `simple_span` method. --- src/input.rs | 5 +++++ src/selection.rs | 43 ++++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/input.rs b/src/input.rs index 57b49ffc..fd86c8df 100644 --- a/src/input.rs +++ b/src/input.rs @@ -620,6 +620,7 @@ mod tests { use config::{self, Config, ClickHandler}; use index::{Point, Side}; use selection::Selection; + use grid::Scroll; use super::{Action, Binding, Processor}; @@ -673,6 +674,10 @@ mod tests { self.last_action = MultiClick::TripleClick; } + fn scroll(&mut self, scroll: Scroll) { + self.terminal.scroll_display(scroll); + } + fn mouse_coords(&self) -> Option { self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize) } diff --git a/src/selection.rs b/src/selection.rs index 20b1d601..188df348 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -251,13 +251,6 @@ impl Selection { let end_side = region.end.side; let cols = grid.dimensions().col; - // No selection for single cell with identical sides or two cell with right+left sides - if (start == end && start_side == end_side) - || (start_side == Side::Right && end_side == Side::Left && end.col == start.col + 1) - { - return None; - } - // Make sure front is always the "bottom" and tail is always the "top" let (mut front, mut tail, front_side, tail_side) = if start.line > end.line || start.line == end.line && start.col <= end.col { @@ -268,6 +261,14 @@ impl Selection { (start, end, start_side, end_side) }; + // No selection for single cell with identical sides or two cell with right+left sides + if (front == tail && front_side == tail_side) + || (tail_side == Side::Right && front_side == Side::Left && front.line == tail.line + && front.col == tail.col + 1) + { + return None; + } + // Remove last cell if selection ends to the left of a cell if front_side == Side::Left && start != end { if front.col != Column(0) { @@ -475,10 +476,10 @@ mod test { /// /// 1. [ ][ ][ ][ ][ ] /// [ ][ ][ ][ ][ ] - /// 2. [ ][ ][ ][ ][ ] - /// [ ][ B][ ][ ][ ] - /// 3. [ ][ E][XX][XX][XX] - /// [XX][XB][ ][ ][ ] + /// 2. [ ][ B][ ][ ][ ] + /// [ ][ ][ ][ ][ ] + /// 3. [ ][ B][XX][XX][XX] + /// [XX][XE][ ][ ][ ] #[test] fn across_adjacent_lines_upward_final_cell_exclusive() { let mut selection = Selection::simple(Point::new(1, Column(1)), Side::Right); @@ -487,8 +488,8 @@ mod test { assert_eq!(selection.to_span(&Dimensions::new(2, 5)).unwrap(), Span { cols: Column(5), front: Point::new(0, Column(1)), - tail: Point::new(1, Column(1)), - ty: SpanType::ExcludeFront + tail: Point::new(1, Column(2)), + ty: SpanType::Inclusive, }); } @@ -497,12 +498,12 @@ mod test { /// /// 1. [ ][ ][ ][ ][ ] /// [ ][ ][ ][ ][ ] - /// 2. [ ][ B][ ][ ][ ] - /// [ ][ ][ ][ ][ ] - /// 3. [ ][ B][XX][XX][XX] - /// [XX][XE][ ][ ][ ] - /// 4. [ ][ B][XX][XX][XX] - /// [XE][ ][ ][ ][ ] + /// 2. [ ][ ][ ][ ][ ] + /// [ ][ B][ ][ ][ ] + /// 3. [ ][ E][XX][XX][XX] + /// [XX][XB][ ][ ][ ] + /// 4. [ E][XX][XX][XX][XX] + /// [XX][XB][ ][ ][ ] #[test] fn selection_bigger_then_smaller() { let mut selection = Selection::simple(Point::new(0, Column(1)), Side::Right); @@ -512,8 +513,8 @@ mod test { assert_eq!(selection.to_span(&Dimensions::new(2, 5)).unwrap(), Span { cols: Column(5), front: Point::new(0, Column(1)), - tail: Point::new(1, Column(0)), - ty: SpanType::ExcludeFront + tail: Point::new(1, Column(1)), + ty: SpanType::Inclusive, }); } }