WIP start setting up test infrastructure for editor diff actions

Julia and Kay Simmons created

Co-Authored-By: Kay Simmons <kay@zed.dev>

Change summary

crates/editor/src/editor_tests.rs                 | 10 ++
crates/editor/src/test.rs                         |  1 
crates/editor/src/test/editor_git_test_context.rs | 56 +++++++++++++++++
crates/project/src/worktree.rs                    |  1 
4 files changed, 65 insertions(+), 3 deletions(-)

Detailed changes

crates/editor/src/editor_tests.rs 🔗

@@ -7,8 +7,9 @@ use unindent::Unindent;
 
 use super::*;
 use crate::test::{
-    assert_text_with_selections, build_editor, editor_lsp_test_context::EditorLspTestContext,
-    editor_test_context::EditorTestContext, select_ranges,
+    assert_text_with_selections, build_editor, editor_git_test_context::EditorGitTestContext,
+    editor_lsp_test_context::EditorLspTestContext, editor_test_context::EditorTestContext,
+    select_ranges,
 };
 use gpui::{
     geometry::rect::RectF,
@@ -5079,6 +5080,11 @@ fn test_combine_syntax_and_fuzzy_match_highlights() {
     );
 }
 
+#[gpui::test]
+fn go_to_hunk(cx: &mut gpui::TestAppContext) {
+    let mut cx = EditorGitTestContext::new(cx);
+}
+
 fn empty_range(row: usize, column: usize) -> Range<DisplayPoint> {
     let point = DisplayPoint::new(row as u32, column as u32);
     point..point

crates/editor/src/test/editor_git_test_context.rs 🔗

@@ -0,0 +1,56 @@
+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
+    }
+}