mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-09 03:57:39 +00:00
Lock down test platform implementation
This commit is contained in:
parent
017661818d
commit
4184686e8d
9 changed files with 20 additions and 33 deletions
|
@ -352,7 +352,7 @@ impl TestAppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `TestWindow` backing the given handle.
|
/// 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
|
self.app
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.windows
|
.windows
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub use keystroke::*;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub(crate) use mac::*;
|
pub(crate) use mac::*;
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub use test::*;
|
pub(crate) use test::*;
|
||||||
use time::UtcOffset;
|
use time::UtcOffset;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod display;
|
||||||
mod platform;
|
mod platform;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
pub use dispatcher::*;
|
pub(crate) use dispatcher::*;
|
||||||
pub use display::*;
|
pub(crate) use display::*;
|
||||||
pub use platform::*;
|
pub(crate) use platform::*;
|
||||||
pub use window::*;
|
pub(crate) use window::*;
|
||||||
|
|
|
@ -18,6 +18,7 @@ use util::post_inc;
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
struct TestDispatcherId(usize);
|
struct TestDispatcherId(usize);
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
pub struct TestDispatcher {
|
pub struct TestDispatcher {
|
||||||
id: TestDispatcherId,
|
id: TestDispatcherId,
|
||||||
state: Arc<Mutex<TestDispatcherState>>,
|
state: Arc<Mutex<TestDispatcherState>>,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use anyhow::{Ok, Result};
|
||||||
use crate::{Bounds, DisplayId, GlobalPixels, PlatformDisplay, Point};
|
use crate::{Bounds, DisplayId, GlobalPixels, PlatformDisplay, Point};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TestDisplay {
|
pub(crate) struct TestDisplay {
|
||||||
id: DisplayId,
|
id: DisplayId,
|
||||||
uuid: uuid::Uuid,
|
uuid: uuid::Uuid,
|
||||||
bounds: Bounds<GlobalPixels>,
|
bounds: Bounds<GlobalPixels>,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// TestPlatform implements the Platform trait for use in tests.
|
/// TestPlatform implements the Platform trait for use in tests.
|
||||||
pub struct TestPlatform {
|
pub(crate) struct TestPlatform {
|
||||||
background_executor: BackgroundExecutor,
|
background_executor: BackgroundExecutor,
|
||||||
foreground_executor: ForegroundExecutor,
|
foreground_executor: ForegroundExecutor,
|
||||||
|
|
||||||
|
@ -178,20 +178,9 @@ impl Platform for TestPlatform {
|
||||||
fn set_display_link_output_callback(
|
fn set_display_link_output_callback(
|
||||||
&self,
|
&self,
|
||||||
_display_id: DisplayId,
|
_display_id: DisplayId,
|
||||||
mut callback: Box<dyn FnMut(&crate::VideoTimestamp, &crate::VideoTimestamp) + Send>,
|
mut callback: Box<dyn FnMut() + Send>,
|
||||||
) {
|
) {
|
||||||
let timestamp = crate::VideoTimestamp {
|
callback()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_display_link(&self, _display_id: DisplayId) {}
|
fn start_display_link(&self, _display_id: DisplayId) {}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
sync::{self, Arc},
|
sync::{self, Arc},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct TestWindowState {
|
pub(crate) struct TestWindowState {
|
||||||
pub(crate) bounds: WindowBounds,
|
pub(crate) bounds: WindowBounds,
|
||||||
pub(crate) handle: AnyWindowHandle,
|
pub(crate) handle: AnyWindowHandle,
|
||||||
display: Rc<dyn PlatformDisplay>,
|
display: Rc<dyn PlatformDisplay>,
|
||||||
|
@ -23,11 +23,11 @@ pub struct TestWindowState {
|
||||||
active_status_change_callback: Option<Box<dyn FnMut(bool)>>,
|
active_status_change_callback: Option<Box<dyn FnMut(bool)>>,
|
||||||
resize_callback: Option<Box<dyn FnMut(Size<Pixels>, f32)>>,
|
resize_callback: Option<Box<dyn FnMut(Size<Pixels>, f32)>>,
|
||||||
moved_callback: Option<Box<dyn FnMut()>>,
|
moved_callback: Option<Box<dyn FnMut()>>,
|
||||||
input_handler: Option<Box<dyn PlatformInputHandler>>,
|
input_handler: Option<PlatformInputHandler>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TestWindow(pub(crate) Arc<Mutex<TestWindowState>>);
|
pub(crate) struct TestWindow(pub(crate) Arc<Mutex<TestWindowState>>);
|
||||||
|
|
||||||
impl TestWindow {
|
impl TestWindow {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -117,9 +117,6 @@ impl TestWindow {
|
||||||
|
|
||||||
self.0.lock().input_handler = Some(input_handler);
|
self.0.lock().input_handler = Some(input_handler);
|
||||||
}
|
}
|
||||||
pub fn edited(&self) -> bool {
|
|
||||||
self.0.lock().edited
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlatformWindow for TestWindow {
|
impl PlatformWindow for TestWindow {
|
||||||
|
@ -163,11 +160,11 @@ impl PlatformWindow for TestWindow {
|
||||||
self
|
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);
|
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()
|
self.0.lock().input_handler.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,12 +266,12 @@ impl PlatformWindow for TestWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestAtlasState {
|
pub(crate) struct TestAtlasState {
|
||||||
next_id: u32,
|
next_id: u32,
|
||||||
tiles: HashMap<AtlasKey, AtlasTile>,
|
tiles: HashMap<AtlasKey, AtlasTile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestAtlas(Mutex<TestAtlasState>);
|
pub(crate) struct TestAtlas(Mutex<TestAtlasState>);
|
||||||
|
|
||||||
impl TestAtlas {
|
impl TestAtlas {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
|
@ -202,7 +202,7 @@ mod test {
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
|
|
||||||
use gpui::InputHandler;
|
use gpui::ViewInputHandler;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
state::Mode,
|
state::Mode,
|
||||||
|
|
|
@ -875,7 +875,7 @@ mod tests {
|
||||||
let window = cx.update(|cx| cx.windows()[0].downcast::<Workspace>().unwrap());
|
let window = cx.update(|cx| cx.windows()[0].downcast::<Workspace>().unwrap());
|
||||||
|
|
||||||
let window_is_edited = |window: WindowHandle<Workspace>, cx: &mut TestAppContext| {
|
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
|
let pane = window
|
||||||
.read_with(cx, |workspace, _| workspace.active_pane().clone())
|
.read_with(cx, |workspace, _| workspace.active_pane().clone())
|
||||||
|
|
Loading…
Reference in a new issue