mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -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:
parent
187e120156
commit
5b8553ba40
2 changed files with 27 additions and 21 deletions
|
@ -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<Point> {
|
||||
self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue