Skip to content

Commit

Permalink
add tests for TextArea::selection_range
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Aug 8, 2024
1 parent de736a5 commit 8d2c201
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,43 @@ fn test_paste_while_selection() {
assert!(!t.is_selecting());
}

#[test]
fn test_selection_range() {
#[rustfmt::skip]
let mut t = TextArea::from([
"あいうえお",
"Hello",
"🐶🐱🐰🐮🐹",
]);

assert_eq!(t.selection_range(), None);

for (from, to) in [
((0, 0), (0, 0)),
((2, 5), (2, 5)),
((0, 2), (2, 3)),
((2, 1), (0, 4)),
((0, 0), (2, 5)),
((2, 5), (0, 0)),
] {
let (x, y) = from;
t.move_cursor(CursorMove::Jump(x as _, y as _));

t.start_selection();

let (x, y) = to;
t.move_cursor(CursorMove::Jump(x as _, y as _));

let have = t.selection_range().unwrap();
let want = if from <= to { (from, to) } else { (to, from) };
assert_eq!(have, want, "selection from {from:?} to {to:?}");

t.cancel_selection();
let range = t.selection_range();
assert_eq!(range, None, "selection from {from:?} to {to:?}");
}
}

struct DeleteTester(&'static [&'static str], fn(&mut TextArea) -> bool);
impl DeleteTester {
fn test(&self, before: (usize, usize), after: (usize, usize, &[&str], &str)) {
Expand Down

0 comments on commit 8d2c201

Please sign in to comment.