Lock down test platform implementation

This commit is contained in:
Mikayla 2024-01-20 14:56:50 -08:00
parent 017661818d
commit 4184686e8d
No known key found for this signature in database
9 changed files with 20 additions and 33 deletions

View File

@ -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

View File

@ -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")]

View File

@ -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::*;

View File

@ -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>>,

View File

@ -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>,

View File

@ -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) {}

View File

@ -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 {

View File

@ -202,7 +202,7 @@ mod test {
use futures::StreamExt;
use indoc::indoc;
use gpui::InputHandler;
use gpui::ViewInputHandler;
use crate::{
state::Mode,

View File

@ -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())