mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-02 00:06:08 +00:00
Fix test failures
This commit is contained in:
parent
cae35d3334
commit
a99ee5e599
3 changed files with 40 additions and 51 deletions
|
@ -185,31 +185,27 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
|
||||||
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let window_a = cx_a.add_empty_window();
|
let cx_a = cx_a.add_empty_window();
|
||||||
let editor_a =
|
let editor_a = cx_a.new_view(|cx| Editor::for_buffer(buffer_a, Some(project_a), cx));
|
||||||
window_a.build_view(cx_a, |cx| Editor::for_buffer(buffer_a, Some(project_a), cx));
|
|
||||||
|
|
||||||
let mut editor_cx_a = EditorTestContext {
|
let mut editor_cx_a = EditorTestContext {
|
||||||
cx: VisualTestContext::from_window(window_a, cx_a),
|
cx: cx_a.clone(),
|
||||||
window: window_a.into(),
|
window: cx_a.handle(),
|
||||||
editor: editor_a,
|
editor: editor_a,
|
||||||
assertion_cx: AssertionContextManager::new(),
|
assertion_cx: AssertionContextManager::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let window_b = cx_b.add_empty_window();
|
let cx_b = cx_b.add_empty_window();
|
||||||
let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
|
|
||||||
|
|
||||||
// Open a buffer as client B
|
// Open a buffer as client B
|
||||||
let buffer_b = project_b
|
let buffer_b = project_b
|
||||||
.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let editor_b = window_b.build_view(&mut cx_b, |cx| {
|
let editor_b = cx_b.new_view(|cx| Editor::for_buffer(buffer_b, Some(project_b), cx));
|
||||||
Editor::for_buffer(buffer_b, Some(project_b), cx)
|
|
||||||
});
|
|
||||||
let mut editor_cx_b = EditorTestContext {
|
let mut editor_cx_b = EditorTestContext {
|
||||||
cx: cx_b,
|
cx: cx_b.clone(),
|
||||||
window: window_b.into(),
|
window: cx_b.handle(),
|
||||||
editor: editor_b,
|
editor: editor_b,
|
||||||
assertion_cx: AssertionContextManager::new(),
|
assertion_cx: AssertionContextManager::new(),
|
||||||
};
|
};
|
||||||
|
@ -311,10 +307,9 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
|
||||||
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let window_b = cx_b.add_empty_window();
|
let cx_b = cx_b.add_empty_window();
|
||||||
let editor_b = window_b.build_view(cx_b, |cx| {
|
let editor_b =
|
||||||
Editor::for_buffer(buffer_b.clone(), Some(project_b.clone()), cx)
|
cx_b.new_view(|cx| Editor::for_buffer(buffer_b.clone(), Some(project_b.clone()), cx));
|
||||||
});
|
|
||||||
|
|
||||||
let fake_language_server = fake_language_servers.next().await.unwrap();
|
let fake_language_server = fake_language_servers.next().await.unwrap();
|
||||||
cx_a.background_executor.run_until_parked();
|
cx_a.background_executor.run_until_parked();
|
||||||
|
@ -323,10 +318,8 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
|
||||||
assert!(!buffer.completion_triggers().is_empty())
|
assert!(!buffer.completion_triggers().is_empty())
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
|
|
||||||
|
|
||||||
// Type a completion trigger character as the guest.
|
// Type a completion trigger character as the guest.
|
||||||
editor_b.update(&mut cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
||||||
editor.handle_input(".", cx);
|
editor.handle_input(".", cx);
|
||||||
});
|
});
|
||||||
|
@ -392,8 +385,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
|
||||||
});
|
});
|
||||||
|
|
||||||
// Confirm a completion on the guest.
|
// Confirm a completion on the guest.
|
||||||
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
editor_b.update(&mut cx_b, |editor, cx| {
|
|
||||||
assert!(editor.context_menu_visible());
|
assert!(editor.context_menu_visible());
|
||||||
editor.confirm_completion(&ConfirmCompletion { item_ix: Some(0) }, cx);
|
editor.confirm_completion(&ConfirmCompletion { item_ix: Some(0) }, cx);
|
||||||
assert_eq!(editor.text(cx), "fn main() { a.first_method() }");
|
assert_eq!(editor.text(cx), "fn main() { a.first_method() }");
|
||||||
|
@ -431,7 +423,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
buffer_b.read_with(&mut cx_b, |buffer, _| {
|
buffer_b.read_with(cx_b, |buffer, _| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
buffer.text(),
|
buffer.text(),
|
||||||
"use d::SomeTrait;\nfn main() { a.first_method() }"
|
"use d::SomeTrait;\nfn main() { a.first_method() }"
|
||||||
|
@ -960,7 +952,7 @@ async fn test_share_project(
|
||||||
cx_c: &mut TestAppContext,
|
cx_c: &mut TestAppContext,
|
||||||
) {
|
) {
|
||||||
let executor = cx_a.executor();
|
let executor = cx_a.executor();
|
||||||
let window_b = cx_b.add_empty_window();
|
let cx_b = cx_b.add_empty_window();
|
||||||
let mut server = TestServer::start(executor.clone()).await;
|
let mut server = TestServer::start(executor.clone()).await;
|
||||||
let client_a = server.create_client(cx_a, "user_a").await;
|
let client_a = server.create_client(cx_a, "user_a").await;
|
||||||
let client_b = server.create_client(cx_b, "user_b").await;
|
let client_b = server.create_client(cx_b, "user_b").await;
|
||||||
|
@ -1075,7 +1067,7 @@ async fn test_share_project(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let editor_b = window_b.build_view(cx_b, |cx| Editor::for_buffer(buffer_b, None, cx));
|
let editor_b = cx_b.new_view(|cx| Editor::for_buffer(buffer_b, None, cx));
|
||||||
|
|
||||||
// Client A sees client B's selection
|
// Client A sees client B's selection
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
|
@ -1089,8 +1081,7 @@ async fn test_share_project(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Edit the buffer as client B and see that edit as client A.
|
// Edit the buffer as client B and see that edit as client A.
|
||||||
let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
|
editor_b.update(cx_b, |editor, cx| editor.handle_input("ok, ", cx));
|
||||||
editor_b.update(&mut cx_b, |editor, cx| editor.handle_input("ok, ", cx));
|
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
|
|
||||||
buffer_a.read_with(cx_a, |buffer, _| {
|
buffer_a.read_with(cx_a, |buffer, _| {
|
||||||
|
@ -1099,7 +1090,7 @@ async fn test_share_project(
|
||||||
|
|
||||||
// Client B can invite client C on a project shared by client A.
|
// Client B can invite client C on a project shared by client A.
|
||||||
active_call_b
|
active_call_b
|
||||||
.update(&mut cx_b, |call, cx| {
|
.update(cx_b, |call, cx| {
|
||||||
call.invite(client_c.user_id().unwrap(), Some(project_b.clone()), cx)
|
call.invite(client_c.user_id().unwrap(), Some(project_b.clone()), cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
@ -1190,12 +1181,8 @@ async fn test_on_input_format_from_host_to_guest(
|
||||||
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let window_a = cx_a.add_empty_window();
|
let cx_a = cx_a.add_empty_window();
|
||||||
let editor_a = window_a
|
let editor_a = cx_a.new_view(|cx| Editor::for_buffer(buffer_a, Some(project_a.clone()), cx));
|
||||||
.update(cx_a, |_, cx| {
|
|
||||||
cx.new_view(|cx| Editor::for_buffer(buffer_a, Some(project_a.clone()), cx))
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let fake_language_server = fake_language_servers.next().await.unwrap();
|
let fake_language_server = fake_language_servers.next().await.unwrap();
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
|
@ -1226,10 +1213,9 @@ async fn test_on_input_format_from_host_to_guest(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut cx_a = VisualTestContext::from_window(window_a, cx_a);
|
|
||||||
// Type a on type formatting trigger character as the guest.
|
// Type a on type formatting trigger character as the guest.
|
||||||
cx_a.focus_view(&editor_a);
|
cx_a.focus_view(&editor_a);
|
||||||
editor_a.update(&mut cx_a, |editor, cx| {
|
editor_a.update(cx_a, |editor, cx| {
|
||||||
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
||||||
editor.handle_input(">", cx);
|
editor.handle_input(">", cx);
|
||||||
});
|
});
|
||||||
|
@ -1241,7 +1227,7 @@ async fn test_on_input_format_from_host_to_guest(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Undo should remove LSP edits first
|
// Undo should remove LSP edits first
|
||||||
editor_a.update(&mut cx_a, |editor, cx| {
|
editor_a.update(cx_a, |editor, cx| {
|
||||||
assert_eq!(editor.text(cx), "fn main() { a>~< }");
|
assert_eq!(editor.text(cx), "fn main() { a>~< }");
|
||||||
editor.undo(&Undo, cx);
|
editor.undo(&Undo, cx);
|
||||||
assert_eq!(editor.text(cx), "fn main() { a> }");
|
assert_eq!(editor.text(cx), "fn main() { a> }");
|
||||||
|
@ -1252,7 +1238,7 @@ async fn test_on_input_format_from_host_to_guest(
|
||||||
assert_eq!(buffer.text(), "fn main() { a> }")
|
assert_eq!(buffer.text(), "fn main() { a> }")
|
||||||
});
|
});
|
||||||
|
|
||||||
editor_a.update(&mut cx_a, |editor, cx| {
|
editor_a.update(cx_a, |editor, cx| {
|
||||||
assert_eq!(editor.text(cx), "fn main() { a> }");
|
assert_eq!(editor.text(cx), "fn main() { a> }");
|
||||||
editor.undo(&Undo, cx);
|
editor.undo(&Undo, cx);
|
||||||
assert_eq!(editor.text(cx), "fn main() { a }");
|
assert_eq!(editor.text(cx), "fn main() { a }");
|
||||||
|
@ -1323,17 +1309,15 @@ async fn test_on_input_format_from_guest_to_host(
|
||||||
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let window_b = cx_b.add_empty_window();
|
let cx_b = cx_b.add_empty_window();
|
||||||
let editor_b = window_b.build_view(cx_b, |cx| {
|
let editor_b = cx_b.new_view(|cx| Editor::for_buffer(buffer_b, Some(project_b.clone()), cx));
|
||||||
Editor::for_buffer(buffer_b, Some(project_b.clone()), cx)
|
|
||||||
});
|
|
||||||
|
|
||||||
let fake_language_server = fake_language_servers.next().await.unwrap();
|
let fake_language_server = fake_language_servers.next().await.unwrap();
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
|
|
||||||
// Type a on type formatting trigger character as the guest.
|
// Type a on type formatting trigger character as the guest.
|
||||||
cx_b.focus_view(&editor_b);
|
cx_b.focus_view(&editor_b);
|
||||||
editor_b.update(&mut cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
|
||||||
editor.handle_input(":", cx);
|
editor.handle_input(":", cx);
|
||||||
});
|
});
|
||||||
|
@ -1374,7 +1358,7 @@ async fn test_on_input_format_from_guest_to_host(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Undo should remove LSP edits first
|
// Undo should remove LSP edits first
|
||||||
editor_b.update(&mut cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
assert_eq!(editor.text(cx), "fn main() { a:~: }");
|
assert_eq!(editor.text(cx), "fn main() { a:~: }");
|
||||||
editor.undo(&Undo, cx);
|
editor.undo(&Undo, cx);
|
||||||
assert_eq!(editor.text(cx), "fn main() { a: }");
|
assert_eq!(editor.text(cx), "fn main() { a: }");
|
||||||
|
@ -1385,7 +1369,7 @@ async fn test_on_input_format_from_guest_to_host(
|
||||||
assert_eq!(buffer.text(), "fn main() { a: }")
|
assert_eq!(buffer.text(), "fn main() { a: }")
|
||||||
});
|
});
|
||||||
|
|
||||||
editor_b.update(&mut cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
assert_eq!(editor.text(cx), "fn main() { a: }");
|
assert_eq!(editor.text(cx), "fn main() { a: }");
|
||||||
editor.undo(&Undo, cx);
|
editor.undo(&Undo, cx);
|
||||||
assert_eq!(editor.text(cx), "fn main() { a }");
|
assert_eq!(editor.text(cx), "fn main() { a }");
|
||||||
|
|
|
@ -568,6 +568,11 @@ pub struct VisualTestContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VisualTestContext {
|
impl<'a> VisualTestContext {
|
||||||
|
/// Get the underlying window handle underlying this context.
|
||||||
|
pub fn handle(&self) -> AnyWindowHandle {
|
||||||
|
self.window
|
||||||
|
}
|
||||||
|
|
||||||
/// Provides the `WindowContext` for the duration of the closure.
|
/// Provides the `WindowContext` for the duration of the closure.
|
||||||
pub fn update<R>(&mut self, f: impl FnOnce(&mut WindowContext) -> R) -> R {
|
pub fn update<R>(&mut self, f: impl FnOnce(&mut WindowContext) -> R) -> R {
|
||||||
self.cx.update_window(self.window, |_, cx| f(cx)).unwrap()
|
self.cx.update_window(self.window, |_, cx| f(cx)).unwrap()
|
||||||
|
|
|
@ -1081,7 +1081,7 @@ mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use editor::{DisplayPoint, Editor};
|
use editor::{DisplayPoint, Editor};
|
||||||
use gpui::{Context, EmptyView, Hsla, TestAppContext, VisualTestContext};
|
use gpui::{Context, Hsla, TestAppContext, VisualTestContext};
|
||||||
use language::Buffer;
|
use language::Buffer;
|
||||||
use smol::stream::StreamExt as _;
|
use smol::stream::StreamExt as _;
|
||||||
use unindent::Unindent as _;
|
use unindent::Unindent as _;
|
||||||
|
@ -1114,7 +1114,7 @@ mod tests {
|
||||||
.unindent(),
|
.unindent(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let (_, cx) = cx.add_window_view(|_| EmptyView {});
|
let cx = cx.add_empty_window();
|
||||||
let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx));
|
let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||||
|
|
||||||
let search_bar = cx.new_view(|cx| {
|
let search_bar = cx.new_view(|cx| {
|
||||||
|
@ -1461,7 +1461,7 @@ mod tests {
|
||||||
"Should pick a query with multiple results"
|
"Should pick a query with multiple results"
|
||||||
);
|
);
|
||||||
let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text));
|
let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text));
|
||||||
let window = cx.add_window(|_| EmptyView {});
|
let window = cx.add_window(|_| ());
|
||||||
|
|
||||||
let editor = window.build_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
let editor = window.build_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||||
|
|
||||||
|
@ -1657,7 +1657,7 @@ mod tests {
|
||||||
"#
|
"#
|
||||||
.unindent();
|
.unindent();
|
||||||
let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text));
|
let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text));
|
||||||
let (_, cx) = cx.add_window_view(|_| EmptyView {});
|
let cx = cx.add_empty_window();
|
||||||
|
|
||||||
let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx));
|
let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue