Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Lock down test platform implementation

Mikayla4184686e8dad
diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs
index 66f74a91b38..139d52b6404 100644
--- a/crates/gpui/src/app/test_context.rs
+++ b/crates/gpui/src/app/test_context.rs
@@ -352,7 +352,7 @@ impl TestAppContext {
}
/// Returns the `TestWindow` backing the given handle.
- pub fn test_window(&self, window: AnyWindowHandle) -> TestWindow {
+ pub(crate) fn test_window(&self, window: AnyWindowHandle) -> TestWindow {
self.app
.borrow_mut()
.windows
diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs
index f368b3c3509..feb0e2e5514 100644
--- a/crates/gpui/src/platform.rs
+++ b/crates/gpui/src/platform.rs
@@ -38,7 +38,7 @@ pub use keystroke::*;
#[cfg(target_os = "macos")]
pub(crate) use mac::*;
#[cfg(any(test, feature = "test-support"))]
-pub use test::*;
+pub(crate) use test::*;
use time::UtcOffset;
#[cfg(target_os = "macos")]
diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs
index acc8ffe41ce..d17739239ee 100644
--- a/crates/gpui/src/platform/test.rs
+++ b/crates/gpui/src/platform/test.rs
@@ -3,7 +3,7 @@ mod display;
mod platform;
mod window;
-pub use dispatcher::*;
-pub use display::*;
-pub use platform::*;
-pub use window::*;
+pub(crate) use dispatcher::*;
+pub(crate) use display::*;
+pub(crate) use platform::*;
+pub(crate) use window::*;
diff --git a/crates/gpui/src/platform/test/dispatcher.rs b/crates/gpui/src/platform/test/dispatcher.rs
index 9023627d1e2..9c59fce48c4 100644
--- a/crates/gpui/src/platform/test/dispatcher.rs
+++ b/crates/gpui/src/platform/test/dispatcher.rs
@@ -18,6 +18,7 @@ use util::post_inc;
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
struct TestDispatcherId(usize);
+#[doc(hidden)]
pub struct TestDispatcher {
id: TestDispatcherId,
state: Arc<Mutex<TestDispatcherState>>,
diff --git a/crates/gpui/src/platform/test/display.rs b/crates/gpui/src/platform/test/display.rs
index 838d600147b..48873160708 100644
--- a/crates/gpui/src/platform/test/display.rs
+++ b/crates/gpui/src/platform/test/display.rs
@@ -3,7 +3,7 @@ use anyhow::{Ok, Result};
use crate::{Bounds, DisplayId, GlobalPixels, PlatformDisplay, Point};
#[derive(Debug)]
-pub struct TestDisplay {
+pub(crate) struct TestDisplay {
id: DisplayId,
uuid: uuid::Uuid,
bounds: Bounds<GlobalPixels>,
diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs
index f5e2170b28a..9a33b4b3b58 100644
--- a/crates/gpui/src/platform/test/platform.rs
+++ b/crates/gpui/src/platform/test/platform.rs
@@ -15,7 +15,7 @@ use std::{
};
/// TestPlatform implements the Platform trait for use in tests.
-pub struct TestPlatform {
+pub(crate) struct TestPlatform {
background_executor: BackgroundExecutor,
foreground_executor: ForegroundExecutor,
@@ -178,20 +178,9 @@ impl Platform for TestPlatform {
fn set_display_link_output_callback(
&self,
_display_id: DisplayId,
- mut callback: Box<dyn FnMut(&crate::VideoTimestamp, &crate::VideoTimestamp) + Send>,
+ mut callback: Box<dyn FnMut() + Send>,
) {
- let timestamp = crate::VideoTimestamp {
- version: 0,
- video_time_scale: 0,
- video_time: 0,
- host_time: 0,
- rate_scalar: 0.0,
- video_refresh_period: 0,
- smpte_time: crate::SmtpeTime::default(),
- flags: 0,
- reserved: 0,
- };
- callback(&timestamp, &timestamp)
+ callback()
}
fn start_display_link(&self, _display_id: DisplayId) {}
diff --git a/crates/gpui/src/platform/test/window.rs b/crates/gpui/src/platform/test/window.rs
index 2f080bd7098..095af9b094a 100644
--- a/crates/gpui/src/platform/test/window.rs
+++ b/crates/gpui/src/platform/test/window.rs
@@ -10,7 +10,7 @@ use std::{
sync::{self, Arc},
};
-pub struct TestWindowState {
+pub(crate) struct TestWindowState {
pub(crate) bounds: WindowBounds,
pub(crate) handle: AnyWindowHandle,
display: Rc<dyn PlatformDisplay>,
@@ -23,11 +23,11 @@ pub struct TestWindowState {
active_status_change_callback: Option<Box<dyn FnMut(bool)>>,
resize_callback: Option<Box<dyn FnMut(Size<Pixels>, f32)>>,
moved_callback: Option<Box<dyn FnMut()>>,
- input_handler: Option<Box<dyn PlatformInputHandler>>,
+ input_handler: Option<PlatformInputHandler>,
}
#[derive(Clone)]
-pub struct TestWindow(pub(crate) Arc<Mutex<TestWindowState>>);
+pub(crate) struct TestWindow(pub(crate) Arc<Mutex<TestWindowState>>);
impl TestWindow {
pub fn new(
@@ -117,9 +117,6 @@ impl TestWindow {
self.0.lock().input_handler = Some(input_handler);
}
- pub fn edited(&self) -> bool {
- self.0.lock().edited
- }
}
impl PlatformWindow for TestWindow {
@@ -163,11 +160,11 @@ impl PlatformWindow for TestWindow {
self
}
- fn set_input_handler(&mut self, input_handler: Box<dyn crate::PlatformInputHandler>) {
+ fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
self.0.lock().input_handler = Some(input_handler);
}
- fn take_input_handler(&mut self) -> Option<Box<dyn PlatformInputHandler>> {
+ fn take_input_handler(&mut self) -> Option<PlatformInputHandler> {
self.0.lock().input_handler.take()
}
@@ -269,12 +266,12 @@ impl PlatformWindow for TestWindow {
}
}
-pub struct TestAtlasState {
+pub(crate) struct TestAtlasState {
next_id: u32,
tiles: HashMap<AtlasKey, AtlasTile>,
}
-pub struct TestAtlas(Mutex<TestAtlasState>);
+pub(crate) struct TestAtlas(Mutex<TestAtlasState>);
impl TestAtlas {
pub fn new() -> Self {
diff --git a/crates/vim/src/normal/repeat.rs b/crates/vim/src/normal/repeat.rs
index 796cfce7a3c..4850151d94d 100644
--- a/crates/vim/src/normal/repeat.rs
+++ b/crates/vim/src/normal/repeat.rs
@@ -202,7 +202,7 @@ mod test {
use futures::StreamExt;
use indoc::indoc;
- use gpui::InputHandler;
+ use gpui::ViewInputHandler;
use crate::{
state::Mode,
diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs
index 112c219d2d7..8010f3c1b9a 100644
--- a/crates/zed/src/zed.rs
+++ b/crates/zed/src/zed.rs
@@ -875,7 +875,7 @@ mod tests {
let window = cx.update(|cx| cx.windows()[0].downcast::<Workspace>().unwrap());
let window_is_edited = |window: WindowHandle<Workspace>, cx: &mut TestAppContext| {
- cx.test_window(window.into()).edited()
+ cx.update(|cx| window.read(cx).unwrap().is_edited())
};
let pane = window
.read_with(cx, |workspace, _| workspace.active_pane().clone())