From 4184686e8dadfacc295530bf15dcb8227785892f Mon Sep 17 00:00:00 2001 From: Mikayla Date: Sat, 20 Jan 2024 14:56:50 -0800 Subject: [PATCH] Lock down test platform implementation --- crates/gpui/src/app/test_context.rs | 2 +- crates/gpui/src/platform.rs | 2 +- crates/gpui/src/platform/test.rs | 8 ++++---- crates/gpui/src/platform/test/dispatcher.rs | 1 + crates/gpui/src/platform/test/display.rs | 2 +- crates/gpui/src/platform/test/platform.rs | 17 +++-------------- crates/gpui/src/platform/test/window.rs | 17 +++++++---------- crates/vim/src/normal/repeat.rs | 2 +- crates/zed/src/zed.rs | 2 +- 9 files changed, 20 insertions(+), 33 deletions(-) diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index 66f74a91b3..139d52b640 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 f368b3c350..feb0e2e551 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 acc8ffe41c..d17739239e 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 9023627d1e..9c59fce48c 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>, diff --git a/crates/gpui/src/platform/test/display.rs b/crates/gpui/src/platform/test/display.rs index 838d600147..4887316070 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, diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index f5e2170b28..9a33b4b3b5 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, + mut callback: Box, ) { - 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(×tamp, ×tamp) + 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 2f080bd709..095af9b094 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, @@ -23,11 +23,11 @@ pub struct TestWindowState { active_status_change_callback: Option>, resize_callback: Option, f32)>>, moved_callback: Option>, - input_handler: Option>, + input_handler: Option, } #[derive(Clone)] -pub struct TestWindow(pub(crate) Arc>); +pub(crate) struct TestWindow(pub(crate) Arc>); 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) { + fn set_input_handler(&mut self, input_handler: PlatformInputHandler) { self.0.lock().input_handler = Some(input_handler); } - fn take_input_handler(&mut self) -> Option> { + fn take_input_handler(&mut self) -> Option { 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, } -pub struct TestAtlas(Mutex); +pub(crate) struct TestAtlas(Mutex); impl TestAtlas { pub fn new() -> Self { diff --git a/crates/vim/src/normal/repeat.rs b/crates/vim/src/normal/repeat.rs index 796cfce7a3..4850151d94 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 112c219d2d..8010f3c1b9 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::().unwrap()); let window_is_edited = |window: WindowHandle, 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())