Add test for go-to hunk and fix discovered bugs

This commit is contained in:
Julia
2022-10-28 15:08:13 -04:00
parent ae2021e073
commit 8361b4d47a
8 changed files with 145 additions and 72 deletions
@@ -1,56 +0,0 @@
use std::ops::{Deref, DerefMut};
use gpui::ModelHandle;
use language::Buffer;
use settings::Settings;
use crate::MultiBuffer;
use super::{build_editor, editor_test_context::EditorTestContext};
pub struct EditorGitTestContext<'a> {
pub cx: EditorTestContext<'a>,
pub buffer: ModelHandle<Buffer>,
}
impl<'a> EditorGitTestContext<'a> {
pub async fn new(cx: &'a mut gpui::TestAppContext) -> EditorGitTestContext<'a> {
let (window_id, buffer, editor) = cx.update(|cx| {
cx.set_global(Settings::test(cx));
crate::init(cx);
let buffer = cx.add_model(|cx| Buffer::new(0, "", cx));
let multibuffer = cx.add_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
let (window_id, editor) =
cx.add_window(Default::default(), |cx| build_editor(multibuffer, cx));
editor.update(cx, |_, cx| cx.focus_self());
(window_id, buffer, editor)
});
Self {
cx: EditorTestContext {
cx,
window_id,
editor,
},
buffer,
}
}
}
impl<'a> Deref for EditorGitTestContext<'a> {
type Target = EditorTestContext<'a>;
fn deref(&self) -> &Self::Target {
&self.cx
}
}
impl<'a> DerefMut for EditorGitTestContext<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.cx
}
}
@@ -151,6 +151,11 @@ impl<'a> EditorTestContext<'a> {
snapshot.anchor_before(ranges[0].start)..snapshot.anchor_after(ranges[0].end)
}
pub fn set_diff_base(&mut self, diff_base: Option<&str>) {
let diff_base = diff_base.map(String::from);
self.update_buffer(|buffer, cx| buffer.set_diff_base(diff_base, cx));
}
/// Change the editor's text and selections using a string containing
/// embedded range markers that represent the ranges and directions of
/// each selection.