Start fixing up platform tests
This commit is contained in:
parent
7516e91a56
commit
b4cba64fd6
10 changed files with 72 additions and 72 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2270,6 +2270,7 @@ dependencies = [
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"git",
|
"git",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
"gpui_mac",
|
||||||
"indoc",
|
"indoc",
|
||||||
"itertools",
|
"itertools",
|
||||||
"language",
|
"language",
|
||||||
|
|
|
@ -18,7 +18,8 @@ test-support = [
|
||||||
"util/test-support",
|
"util/test-support",
|
||||||
"workspace/test-support",
|
"workspace/test-support",
|
||||||
"tree-sitter-rust",
|
"tree-sitter-rust",
|
||||||
"tree-sitter-typescript"
|
"tree-sitter-typescript",
|
||||||
|
"gpui_mac"
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -44,6 +45,7 @@ theme = { path = "../theme" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
sqlez = { path = "../sqlez" }
|
sqlez = { path = "../sqlez" }
|
||||||
workspace = { path = "../workspace" }
|
workspace = { path = "../workspace" }
|
||||||
|
gpui_mac = { path = "../gpui_mac", optional = true}
|
||||||
|
|
||||||
aho-corasick = "0.7"
|
aho-corasick = "0.7"
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
@ -79,6 +81,7 @@ project = { path = "../project", features = ["test-support"] }
|
||||||
settings = { path = "../settings", features = ["test-support"] }
|
settings = { path = "../settings", features = ["test-support"] }
|
||||||
workspace = { path = "../workspace", features = ["test-support"] }
|
workspace = { path = "../workspace", features = ["test-support"] }
|
||||||
|
|
||||||
|
|
||||||
ctor.workspace = true
|
ctor.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
|
|
|
@ -278,48 +278,3 @@ impl DerefMut for LineWrapperHandle {
|
||||||
self.wrapper.as_mut().unwrap()
|
self.wrapper.as_mut().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
fonts::{Style, Weight},
|
|
||||||
platform::{test, Platform as _},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_select_font() {
|
|
||||||
let platform = test::platform();
|
|
||||||
let fonts = FontCache::new(platform.fonts());
|
|
||||||
let arial = fonts
|
|
||||||
.load_family(
|
|
||||||
&["Arial"],
|
|
||||||
&Features {
|
|
||||||
calt: Some(false),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let arial_regular = fonts.select_font(arial, &Properties::new()).unwrap();
|
|
||||||
let arial_italic = fonts
|
|
||||||
.select_font(arial, Properties::new().style(Style::Italic))
|
|
||||||
.unwrap();
|
|
||||||
let arial_bold = fonts
|
|
||||||
.select_font(arial, Properties::new().weight(Weight::BOLD))
|
|
||||||
.unwrap();
|
|
||||||
assert_ne!(arial_regular, arial_italic);
|
|
||||||
assert_ne!(arial_regular, arial_bold);
|
|
||||||
assert_ne!(arial_italic, arial_bold);
|
|
||||||
|
|
||||||
let arial_with_calt = fonts
|
|
||||||
.load_family(
|
|
||||||
&["Arial"],
|
|
||||||
&Features {
|
|
||||||
calt: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert_ne!(arial_with_calt, arial);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ pub mod platform;
|
||||||
pub use gpui_macros::{test, Element};
|
pub use gpui_macros::{test, Element};
|
||||||
pub use window::{Axis, RectFExt, SizeConstraint, Vector2FExt, WindowContext};
|
pub use window::{Axis, RectFExt, SizeConstraint, Vector2FExt, WindowContext};
|
||||||
|
|
||||||
|
#[cfg(any(test, feature="test-support"))]
|
||||||
|
pub mod test;
|
||||||
pub use anyhow;
|
pub use anyhow;
|
||||||
pub use serde_json;
|
pub use serde_json;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
mod event;
|
mod event;
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub(super) mod test;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor,
|
executor,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::{AppVersion, CursorStyle, WindowBounds};
|
use super::{AppVersion, CursorStyle, WindowBounds};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use collections::VecDeque;
|
use collections::VecDeque;
|
||||||
use gpui::{
|
use crate::{
|
||||||
geometry::{
|
geometry::{
|
||||||
rect::RectF,
|
rect::RectF,
|
||||||
vector::{vec2f, Vector2F},
|
vector::{vec2f, Vector2F},
|
||||||
|
@ -64,7 +64,7 @@ impl super::ForegroundPlatform for ForegroundPlatform {
|
||||||
fn on_resign_active(&self, _: Box<dyn FnMut()>) {}
|
fn on_resign_active(&self, _: Box<dyn FnMut()>) {}
|
||||||
fn on_quit(&self, _: Box<dyn FnMut()>) {}
|
fn on_quit(&self, _: Box<dyn FnMut()>) {}
|
||||||
fn on_reopen(&self, _: Box<dyn FnMut()>) {}
|
fn on_reopen(&self, _: Box<dyn FnMut()>) {}
|
||||||
fn on_event(&self, _: Box<dyn FnMut(gpui::platform::Event) -> bool>) {}
|
fn on_event(&self, _: Box<dyn FnMut(super::Event) -> bool>) {}
|
||||||
fn on_open_urls(&self, _: Box<dyn FnMut(Vec<String>)>) {}
|
fn on_open_urls(&self, _: Box<dyn FnMut(Vec<String>)>) {}
|
||||||
|
|
||||||
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
|
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
|
||||||
|
@ -93,10 +93,6 @@ impl super::ForegroundPlatform for ForegroundPlatform {
|
||||||
fn reveal_path(&self, _: &Path) {}
|
fn reveal_path(&self, _: &Path) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn platform() -> Platform {
|
|
||||||
Platform::new()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Platform {
|
pub struct Platform {
|
||||||
dispatcher: Arc<dyn super::Dispatcher>,
|
dispatcher: Arc<dyn super::Dispatcher>,
|
||||||
fonts: Arc<dyn super::FontSystem>,
|
fonts: Arc<dyn super::FontSystem>,
|
||||||
|
@ -106,10 +102,10 @@ pub struct Platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Platform {
|
impl Platform {
|
||||||
fn new() -> Self {
|
pub fn new(fonts: Arc<dyn super::FontSystem>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
dispatcher: Arc::new(Dispatcher),
|
dispatcher: Arc::new(Dispatcher),
|
||||||
fonts: Arc::new(super::current::FontSystem::new()),
|
fonts,
|
||||||
current_clipboard_item: Default::default(),
|
current_clipboard_item: Default::default(),
|
||||||
cursor: Mutex::new(CursorStyle::Arrow),
|
cursor: Mutex::new(CursorStyle::Arrow),
|
||||||
active_window: Default::default(),
|
active_window: Default::default(),
|
||||||
|
@ -136,11 +132,11 @@ impl super::Platform for Platform {
|
||||||
|
|
||||||
fn quit(&self) {}
|
fn quit(&self) {}
|
||||||
|
|
||||||
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn gpui::platform::Screen>> {
|
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn super::Screen>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn screens(&self) -> Vec<Rc<dyn gpui::platform::Screen>> {
|
fn screens(&self) -> Vec<Rc<dyn super::Screen>> {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +161,7 @@ impl super::Platform for Platform {
|
||||||
self.active_window.lock().clone()
|
self.active_window.lock().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_status_item(&self, handle: AnyWindowHandle) -> Box<dyn gpui::platform::Window> {
|
fn add_status_item(&self, handle: AnyWindowHandle) -> Box<dyn super::Window> {
|
||||||
Box::new(Window::new(
|
Box::new(Window::new(
|
||||||
handle,
|
handle,
|
||||||
vec2f(24., 24.),
|
vec2f(24., 24.),
|
||||||
|
@ -263,7 +259,7 @@ pub struct Window {
|
||||||
handle: AnyWindowHandle,
|
handle: AnyWindowHandle,
|
||||||
pub(crate) size: Vector2F,
|
pub(crate) size: Vector2F,
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
current_scene: Option<gpui::Scene>,
|
current_scene: Option<crate::Scene>,
|
||||||
event_handlers: Vec<Box<dyn FnMut(super::Event) -> bool>>,
|
event_handlers: Vec<Box<dyn FnMut(super::Event) -> bool>>,
|
||||||
pub(crate) resize_handlers: Vec<Box<dyn FnMut()>>,
|
pub(crate) resize_handlers: Vec<Box<dyn FnMut()>>,
|
||||||
pub(crate) moved_handlers: Vec<Box<dyn FnMut()>>,
|
pub(crate) moved_handlers: Vec<Box<dyn FnMut()>>,
|
||||||
|
@ -324,11 +320,11 @@ impl super::Window for Window {
|
||||||
24.
|
24.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn appearance(&self) -> gpui::platform::Appearance {
|
fn appearance(&self) -> super::Appearance {
|
||||||
gpui::platform::Appearance::Light
|
super::Appearance::Light
|
||||||
}
|
}
|
||||||
|
|
||||||
fn screen(&self) -> Rc<dyn gpui::platform::Screen> {
|
fn screen(&self) -> Rc<dyn super::Screen> {
|
||||||
Rc::new(Screen)
|
Rc::new(Screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,11 +332,11 @@ impl super::Window for Window {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_input_handler(&mut self, _: Box<dyn gpui::platform::InputHandler>) {}
|
fn set_input_handler(&mut self, _: Box<dyn super::InputHandler>) {}
|
||||||
|
|
||||||
fn prompt(
|
fn prompt(
|
||||||
&self,
|
&self,
|
||||||
_: gpui::platform::PromptLevel,
|
_: super::PromptLevel,
|
||||||
_: &str,
|
_: &str,
|
||||||
_: &[&str],
|
_: &[&str],
|
||||||
) -> oneshot::Receiver<usize> {
|
) -> oneshot::Receiver<usize> {
|
||||||
|
@ -367,13 +363,13 @@ impl super::Window for Window {
|
||||||
|
|
||||||
fn zoom(&self) {}
|
fn zoom(&self) {}
|
||||||
|
|
||||||
fn present_scene(&mut self, scene: gpui::Scene) {
|
fn present_scene(&mut self, scene: crate::Scene) {
|
||||||
self.current_scene = Some(scene);
|
self.current_scene = Some(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_full_screen(&self) {}
|
fn toggle_full_screen(&self) {}
|
||||||
|
|
||||||
fn on_event(&mut self, callback: Box<dyn FnMut(gpui::platform::Event) -> bool>) {
|
fn on_event(&mut self, callback: Box<dyn FnMut(super::Event) -> bool>) {
|
||||||
self.event_handlers.push(callback);
|
self.event_handlers.push(callback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ fn init_logger() {
|
||||||
// static ALLOC: dhat::Alloc = dhat::Alloc;
|
// static ALLOC: dhat::Alloc = dhat::Alloc;
|
||||||
|
|
||||||
pub fn run_test(
|
pub fn run_test(
|
||||||
|
fonts: fn() -> std::sync::Arc<dyn crate::platform::FontSystem>,
|
||||||
mut num_iterations: u64,
|
mut num_iterations: u64,
|
||||||
mut starting_seed: u64,
|
mut starting_seed: u64,
|
||||||
max_retries: usize,
|
max_retries: usize,
|
||||||
|
@ -66,10 +67,10 @@ pub fn run_test(
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let result = panic::catch_unwind(|| {
|
let result = panic::catch_unwind(|| {
|
||||||
|
let fonts = fonts();
|
||||||
let foreground_platform = Rc::new(platform::test::foreground_platform());
|
let foreground_platform = Rc::new(platform::test::foreground_platform());
|
||||||
let platform = Arc::new(platform::test::platform());
|
let platform = Arc::new(platform::test::Platform::new(fonts.clone()));
|
||||||
let font_system = platform.fonts();
|
let font_cache = Arc::new(FontCache::new(fonts.clone()));
|
||||||
let font_cache = Arc::new(FontCache::new(font_system));
|
|
||||||
let mut prev_runnable_history: Option<Vec<ExecutorEvent>> = None;
|
let mut prev_runnable_history: Option<Vec<ExecutorEvent>> = None;
|
||||||
|
|
||||||
for _ in 0..num_iterations {
|
for _ in 0..num_iterations {
|
||||||
|
|
|
@ -668,4 +668,39 @@ mod tests {
|
||||||
// There's no glyph for \u{feff}
|
// There's no glyph for \u{feff}
|
||||||
assert_eq!(layout.runs[0].glyphs[1].id, 69); // b
|
assert_eq!(layout.runs[0].glyphs[1].id, 69); // b
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_select_font() {
|
||||||
|
let platform = test::platform(FontSystem::new());
|
||||||
|
let fonts = FontCache::new(platform.fonts());
|
||||||
|
let arial = fonts
|
||||||
|
.load_family(
|
||||||
|
&["Arial"],
|
||||||
|
&Features {
|
||||||
|
calt: Some(false),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let arial_regular = fonts.select_font(arial, &Properties::new()).unwrap();
|
||||||
|
let arial_italic = fonts
|
||||||
|
.select_font(arial, Properties::new().style(Style::Italic))
|
||||||
|
.unwrap();
|
||||||
|
let arial_bold = fonts
|
||||||
|
.select_font(arial, Properties::new().weight(Weight::BOLD))
|
||||||
|
.unwrap();
|
||||||
|
assert_ne!(arial_regular, arial_italic);
|
||||||
|
assert_ne!(arial_regular, arial_bold);
|
||||||
|
assert_ne!(arial_italic, arial_bold);
|
||||||
|
|
||||||
|
let arial_with_calt = fonts
|
||||||
|
.load_family(
|
||||||
|
&["Arial"],
|
||||||
|
&Features {
|
||||||
|
calt: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_ne!(arial_with_calt, arial);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,7 @@ mod renderer;
|
||||||
mod screen;
|
mod screen;
|
||||||
mod sprite_cache;
|
mod sprite_cache;
|
||||||
mod status_item;
|
mod status_item;
|
||||||
#[cfg(test)]
|
|
||||||
mod test;
|
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use cocoa::{
|
use cocoa::{
|
||||||
|
@ -104,3 +103,9 @@ unsafe impl objc::Encode for NSRange {
|
||||||
unsafe fn ns_string(string: &str) -> id {
|
unsafe fn ns_string(string: &str) -> id {
|
||||||
NSString::alloc(nil).init_str(string).autorelease()
|
NSString::alloc(nil).init_str(string).autorelease()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn font_system() -> Arc<dyn gpui::platform::FontSystem> {
|
||||||
|
Arc::new(FontSystem::new())
|
||||||
|
}
|
||||||
|
|
|
@ -157,8 +157,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
#[test]
|
#[test]
|
||||||
fn #outer_fn_name() {
|
fn #outer_fn_name() {
|
||||||
#inner_fn
|
#inner_fn
|
||||||
|
|
||||||
#namespace::test::run_test(
|
#namespace::test::run_test(
|
||||||
|
gpui_mac::font_system,
|
||||||
#num_iterations as u64,
|
#num_iterations as u64,
|
||||||
#starting_seed as u64,
|
#starting_seed as u64,
|
||||||
#max_retries,
|
#max_retries,
|
||||||
|
@ -234,8 +234,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
#[test]
|
#[test]
|
||||||
fn #outer_fn_name() {
|
fn #outer_fn_name() {
|
||||||
#inner_fn
|
#inner_fn
|
||||||
|
|
||||||
#namespace::test::run_test(
|
#namespace::test::run_test(
|
||||||
|
gpui_mac::font_system,
|
||||||
#num_iterations as u64,
|
#num_iterations as u64,
|
||||||
#starting_seed as u64,
|
#starting_seed as u64,
|
||||||
#max_retries,
|
#max_retries,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue