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

Update tests for new Selection API

This commit is contained in:
Joe Wilm 2017-06-17 10:29:59 -07:00 committed by Joe Wilm
parent 6b081dcc95
commit f12fd880fe
3 changed files with 53 additions and 39 deletions

View file

@ -496,6 +496,7 @@ mod tests {
use event::{Mouse, ClickState}; use event::{Mouse, ClickState};
use config::{self, Config, ClickHandler}; use config::{self, Config, ClickHandler};
use index::{Point, Side}; use index::{Point, Side};
use selection::Selection;
use super::{Action, Binding, Processor}; use super::{Action, Binding, Processor};
@ -510,7 +511,7 @@ mod tests {
struct ActionContext<'a> { struct ActionContext<'a> {
pub terminal: &'a mut Term, pub terminal: &'a mut Term,
pub selection: Option<&'a mut Selection>, pub selection: &'a mut Option<Selection>,
pub size_info: &'a SizeInfo, pub size_info: &'a SizeInfo,
pub mouse: &'a mut Mouse, pub mouse: &'a mut Mouse,
pub last_action: MultiClick, pub last_action: MultiClick,
@ -533,11 +534,9 @@ mod tests {
// STUBBED // STUBBED
} }
fn clear_selection(&mut self) { } fn clear_selection(&mut self) {}
fn update_selection(&mut self, _point: Point, _side: Side) {}
fn update_selection(&mut self, point: Point, side: Side) { fn simple_selection(&mut self, _point: Point, _side: Side) {}
self.selection.update(point, side);
}
fn semantic_selection(&mut self, _point: Point) { fn semantic_selection(&mut self, _point: Point) {
// set something that we can check for here // set something that we can check for here
@ -578,16 +577,16 @@ mod tests {
padding_y: 0.0, padding_y: 0.0,
}; };
use ::ansi::TermInfo;
let mut terminal = Term::new(&config, size); let mut terminal = Term::new(&config, size);
let mut mouse = Mouse::default(); let mut mouse = Mouse::default();
mouse.click_state = $initial_state; mouse.click_state = $initial_state;
let mut selection = None;
let context = ActionContext { let context = ActionContext {
terminal: &mut terminal, terminal: &mut terminal,
selection: None, selection: &mut selection,
mouse: &mut mouse, mouse: &mut mouse,
size_info: &size, size_info: &size,
last_action: MultiClick::None, last_action: MultiClick::None,

View file

@ -408,6 +408,27 @@ mod test {
use index::{Line, Column, Side, Point}; use index::{Line, Column, Side, Point};
use super::{Selection, Span, SpanType}; use super::{Selection, Span, SpanType};
struct Dimensions(Point);
impl<'a> super::Dimensions for &'a Dimensions {
fn dimensions(&self) -> Point {
self.0
}
}
impl Dimensions {
pub fn new(line: usize, col: usize) -> Self {
Dimensions(Point {
line: Line(line),
col: Column(col)
})
}
}
impl<'a> super::SemanticSearch for &'a Dimensions {
fn semantic_search_left(&self, _: Point) -> Point { unimplemented!(); }
fn semantic_search_right(&self, _: Point) -> Point { unimplemented!(); }
}
/// Test case of single cell selection /// Test case of single cell selection
/// ///
/// 1. [ ] /// 1. [ ]
@ -416,11 +437,11 @@ mod test {
#[test] #[test]
fn single_cell_left_to_right() { fn single_cell_left_to_right() {
let location = Point { line: Line(0), col: Column(0) }; let location = Point { line: Line(0), col: Column(0) };
let mut selection = Selection::new(Line(1), Column(1)); let mut selection = Selection::simple(location, Side::Left);
selection.update(location, Side::Left);
selection.update(location, Side::Right); selection.update(location, Side::Right);
assert_eq!(selection.span().unwrap(), Span { assert_eq!(selection.to_span(&Dimensions::new(1, 1)).unwrap(), Span {
cols: Column(1),
ty: SpanType::Inclusive, ty: SpanType::Inclusive,
front: location, front: location,
tail: location tail: location
@ -435,11 +456,11 @@ mod test {
#[test] #[test]
fn single_cell_right_to_left() { fn single_cell_right_to_left() {
let location = Point { line: Line(0), col: Column(0) }; let location = Point { line: Line(0), col: Column(0) };
let mut selection = Selection::new(Line(1), Column(1)); let mut selection = Selection::simple(location, Side::Right);
selection.update(location, Side::Right);
selection.update(location, Side::Left); selection.update(location, Side::Left);
assert_eq!(selection.span().unwrap(), Span { assert_eq!(selection.to_span(&Dimensions::new(1, 1)).unwrap(), Span {
cols: Column(1),
ty: SpanType::Inclusive, ty: SpanType::Inclusive,
front: location, front: location,
tail: location tail: location
@ -453,11 +474,10 @@ mod test {
/// 3. [ B][E ] /// 3. [ B][E ]
#[test] #[test]
fn between_adjacent_cells_left_to_right() { fn between_adjacent_cells_left_to_right() {
let mut selection = Selection::new(Line(1), Column(2)); let mut selection = Selection::simple(Point::new(Line(0), Column(0)), Side::Right);
selection.update(Point::new(Line(0), Column(0)), Side::Right);
selection.update(Point::new(Line(0), Column(1)), Side::Left); selection.update(Point::new(Line(0), Column(1)), Side::Left);
assert_eq!(selection.span(), None); assert_eq!(selection.to_span(&Dimensions::new(1, 2)), None);
} }
/// Test adjacent cell selection from right to left /// Test adjacent cell selection from right to left
@ -467,11 +487,10 @@ mod test {
/// 3. [ E][B ] /// 3. [ E][B ]
#[test] #[test]
fn between_adjacent_cells_right_to_left() { fn between_adjacent_cells_right_to_left() {
let mut selection = Selection::new(Line(1), Column(2)); let mut selection = Selection::simple(Point::new(Line(0), Column(1)), Side::Left);
selection.update(Point::new(Line(0), Column(1)), Side::Left);
selection.update(Point::new(Line(0), Column(0)), Side::Right); selection.update(Point::new(Line(0), Column(0)), Side::Right);
assert_eq!(selection.span(), None); assert_eq!(selection.to_span(&Dimensions::new(1, 2)), None);
} }
/// Test selection across adjacent lines /// Test selection across adjacent lines
@ -485,11 +504,11 @@ mod test {
/// [XX][XB][ ][ ][ ] /// [XX][XB][ ][ ][ ]
#[test] #[test]
fn across_adjacent_lines_upward_final_cell_exclusive() { fn across_adjacent_lines_upward_final_cell_exclusive() {
let mut selection = Selection::new(Line(2), Column(5)); let mut selection = Selection::simple(Point::new(Line(1), Column(1)), Side::Right);
selection.update(Point::new(Line(1), Column(1)), Side::Right);
selection.update(Point::new(Line(0), Column(1)), Side::Right); selection.update(Point::new(Line(0), Column(1)), Side::Right);
assert_eq!(selection.span().unwrap(), Span { assert_eq!(selection.to_span(&Dimensions::new(2, 5)).unwrap(), Span {
cols: Column(5),
front: Point::new(Line(0), Column(1)), front: Point::new(Line(0), Column(1)),
tail: Point::new(Line(1), Column(1)), tail: Point::new(Line(1), Column(1)),
ty: SpanType::ExcludeFront ty: SpanType::ExcludeFront
@ -509,12 +528,12 @@ mod test {
/// [XE][ ][ ][ ][ ] /// [XE][ ][ ][ ][ ]
#[test] #[test]
fn selection_bigger_then_smaller() { fn selection_bigger_then_smaller() {
let mut selection = Selection::new(Line(2), Column(5)); let mut selection = Selection::simple(Point::new(Line(0), Column(1)), Side::Right);
selection.update(Point::new(Line(0), Column(1)), Side::Right);
selection.update(Point::new(Line(1), Column(1)), Side::Right); selection.update(Point::new(Line(1), Column(1)), Side::Right);
selection.update(Point::new(Line(1), Column(0)), Side::Right); selection.update(Point::new(Line(1), Column(0)), Side::Right);
assert_eq!(selection.span().unwrap(), Span { assert_eq!(selection.to_span(&Dimensions::new(2, 5)).unwrap(), Span {
cols: Column(5),
front: Point::new(Line(0), Column(1)), front: Point::new(Line(0), Column(1)),
tail: Point::new(Line(1), Column(0)), tail: Point::new(Line(1), Column(0)),
ty: SpanType::ExcludeFront ty: SpanType::ExcludeFront

View file

@ -1841,21 +1841,18 @@ mod tests {
mem::swap(&mut term.semantic_escape_chars, &mut escape_chars); mem::swap(&mut term.semantic_escape_chars, &mut escape_chars);
{ {
let mut selection = Selection::new(grid.num_lines(), grid.num_cols()); let selection = Selection::semantic(Point { line: Line(0), col: Column(1) }, &term);
term.semantic_selection(&mut selection, Point { line: Line(0), col: Column(1) }); assert_eq!(term.string_from_selection(&selection.to_span(&term).unwrap()), "aa");
assert_eq!(term.string_from_selection(&selection.span().unwrap()), "aa");
} }
{ {
let mut selection = Selection::new(grid.num_lines(), grid.num_cols()); let selection = Selection::semantic(Point { line: Line(0), col: Column(4) }, &term);
term.semantic_selection(&mut selection, Point { line: Line(0), col: Column(4) }); assert_eq!(term.string_from_selection(&selection.to_span(&term).unwrap()), "aaa");
assert_eq!(term.string_from_selection(&selection.span().unwrap()), "aaa");
} }
{ {
let mut selection = Selection::new(grid.num_lines(), grid.num_cols()); let selection = Selection::semantic(Point { line: Line(1), col: Column(1) }, &term);
term.semantic_selection(&mut selection, Point { line: Line(1), col: Column(1) }); assert_eq!(term.string_from_selection(&selection.to_span(&term).unwrap()), "aaa");
assert_eq!(term.string_from_selection(&selection.span().unwrap()), "aaa");
} }
} }
@ -1880,9 +1877,8 @@ mod tests {
mem::swap(&mut term.grid, &mut grid); mem::swap(&mut term.grid, &mut grid);
let mut selection = Selection::new(grid.num_lines(), grid.num_cols()); let selection = Selection::lines(Point { line: Line(0), col: Column(3) });
term.line_selection(&mut selection, Point { line: Line(0), col: Column(3) }); match selection.to_span(&term) {
match selection.span() {
Some(span) => assert_eq!(term.string_from_selection(&span), "\"aa\"a"), Some(span) => assert_eq!(term.string_from_selection(&span), "\"aa\"a"),
_ => () _ => ()
} }