1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

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.
This commit is contained in:
Christian Duerr 2018-03-25 21:09:18 +02:00 committed by Joe Wilm
parent 313bea4014
commit da7cb69c27
2 changed files with 27 additions and 21 deletions

View file

@ -620,6 +620,7 @@ mod tests {
use config::{self, Config, ClickHandler}; use config::{self, Config, ClickHandler};
use index::{Point, Side}; use index::{Point, Side};
use selection::Selection; use selection::Selection;
use grid::Scroll;
use super::{Action, Binding, Processor}; use super::{Action, Binding, Processor};
@ -673,6 +674,10 @@ mod tests {
self.last_action = MultiClick::TripleClick; self.last_action = MultiClick::TripleClick;
} }
fn scroll(&mut self, scroll: Scroll) {
self.terminal.scroll_display(scroll);
}
fn mouse_coords(&self) -> Option<Point> { fn mouse_coords(&self) -> Option<Point> {
self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize) self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize)
} }

View file

@ -251,13 +251,6 @@ impl Selection {
let end_side = region.end.side; let end_side = region.end.side;
let cols = grid.dimensions().col; 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" // Make sure front is always the "bottom" and tail is always the "top"
let (mut front, mut tail, front_side, tail_side) = let (mut front, mut tail, front_side, tail_side) =
if start.line > end.line || start.line == end.line && start.col <= end.col { 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) (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 // Remove last cell if selection ends to the left of a cell
if front_side == Side::Left && start != end { if front_side == Side::Left && start != end {
if front.col != Column(0) { if front.col != Column(0) {
@ -475,10 +476,10 @@ mod test {
/// ///
/// 1. [ ][ ][ ][ ][ ] /// 1. [ ][ ][ ][ ][ ]
/// [ ][ ][ ][ ][ ] /// [ ][ ][ ][ ][ ]
/// 2. [ ][ ][ ][ ][ ] /// 2. [ ][ B][ ][ ][ ]
/// [ ][ B][ ][ ][ ] /// [ ][ ][ ][ ][ ]
/// 3. [ ][ E][XX][XX][XX] /// 3. [ ][ B][XX][XX][XX]
/// [XX][XB][ ][ ][ ] /// [XX][XE][ ][ ][ ]
#[test] #[test]
fn across_adjacent_lines_upward_final_cell_exclusive() { fn across_adjacent_lines_upward_final_cell_exclusive() {
let mut selection = Selection::simple(Point::new(1, Column(1)), Side::Right); 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 { assert_eq!(selection.to_span(&Dimensions::new(2, 5)).unwrap(), Span {
cols: Column(5), cols: Column(5),
front: Point::new(0, Column(1)), front: Point::new(0, Column(1)),
tail: Point::new(1, Column(1)), tail: Point::new(1, Column(2)),
ty: SpanType::ExcludeFront ty: SpanType::Inclusive,
}); });
} }
@ -497,12 +498,12 @@ mod test {
/// ///
/// 1. [ ][ ][ ][ ][ ] /// 1. [ ][ ][ ][ ][ ]
/// [ ][ ][ ][ ][ ] /// [ ][ ][ ][ ][ ]
/// 2. [ ][ B][ ][ ][ ] /// 2. [ ][ ][ ][ ][ ]
/// [ ][ ][ ][ ][ ] /// [ ][ B][ ][ ][ ]
/// 3. [ ][ B][XX][XX][XX] /// 3. [ ][ E][XX][XX][XX]
/// [XX][XE][ ][ ][ ] /// [XX][XB][ ][ ][ ]
/// 4. [ ][ B][XX][XX][XX] /// 4. [ E][XX][XX][XX][XX]
/// [XE][ ][ ][ ][ ] /// [XX][XB][ ][ ][ ]
#[test] #[test]
fn selection_bigger_then_smaller() { fn selection_bigger_then_smaller() {
let mut selection = Selection::simple(Point::new(0, Column(1)), Side::Right); 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 { assert_eq!(selection.to_span(&Dimensions::new(2, 5)).unwrap(), Span {
cols: Column(5), cols: Column(5),
front: Point::new(0, Column(1)), front: Point::new(0, Column(1)),
tail: Point::new(1, Column(0)), tail: Point::new(1, Column(1)),
ty: SpanType::ExcludeFront ty: SpanType::Inclusive,
}); });
} }
} }