mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 00:39:51 +00:00
Add test for BufferView::cancel
This commit is contained in:
parent
0622722ab7
commit
6f5e47d631
1 changed files with 74 additions and 0 deletions
|
@ -2632,6 +2632,80 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_canceling_pending_selection() {
|
||||
App::test((), |app| {
|
||||
let buffer =
|
||||
app.add_model(|ctx| Buffer::new(0, "aaaaaa\nbbbbbb\ncccccc\ndddddd\n", ctx));
|
||||
let settings = settings::channel(&app.font_cache()).unwrap().1;
|
||||
let (_, view) = app.add_window(|ctx| BufferView::for_buffer(buffer, settings, ctx));
|
||||
|
||||
view.update(app, |view, ctx| {
|
||||
view.begin_selection(DisplayPoint::new(2, 2), false, ctx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
[DisplayPoint::new(2, 2)..DisplayPoint::new(2, 2)]
|
||||
);
|
||||
|
||||
view.update(app, |view, ctx| {
|
||||
view.update_selection(DisplayPoint::new(3, 3), Vector2F::zero(), ctx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
[DisplayPoint::new(2, 2)..DisplayPoint::new(3, 3)]
|
||||
);
|
||||
|
||||
view.update(app, |view, ctx| {
|
||||
view.cancel(&(), ctx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), Vector2F::zero(), ctx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
[DisplayPoint::new(2, 2)..DisplayPoint::new(3, 3)]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cancel() {
|
||||
App::test((), |app| {
|
||||
let buffer =
|
||||
app.add_model(|ctx| Buffer::new(0, "aaaaaa\nbbbbbb\ncccccc\ndddddd\n", ctx));
|
||||
let settings = settings::channel(&app.font_cache()).unwrap().1;
|
||||
let (_, view) = app.add_window(|ctx| BufferView::for_buffer(buffer, settings, ctx));
|
||||
|
||||
view.update(app, |view, ctx| {
|
||||
view.begin_selection(DisplayPoint::new(3, 4), false, ctx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), Vector2F::zero(), ctx);
|
||||
view.end_selection(ctx);
|
||||
|
||||
view.begin_selection(DisplayPoint::new(0, 1), true, ctx);
|
||||
view.update_selection(DisplayPoint::new(0, 3), Vector2F::zero(), ctx);
|
||||
view.end_selection(ctx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
[
|
||||
DisplayPoint::new(0, 1)..DisplayPoint::new(0, 3),
|
||||
DisplayPoint::new(3, 4)..DisplayPoint::new(1, 1),
|
||||
]
|
||||
);
|
||||
|
||||
view.update(app, |view, ctx| view.cancel(&(), ctx));
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
[DisplayPoint::new(3, 4)..DisplayPoint::new(1, 1)]
|
||||
);
|
||||
|
||||
view.update(app, |view, ctx| view.cancel(&(), ctx));
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
[DisplayPoint::new(1, 1)..DisplayPoint::new(1, 1)]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_layout_line_numbers() {
|
||||
App::test((), |app| {
|
||||
|
|
Loading…
Reference in a new issue