From d0f287772bb8bbc10c8d01ac462b1a6d74b4841c Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 23 Aug 2023 01:13:04 +0200 Subject: [PATCH] chore: fmt --- crates/gpui/src/platform/test.rs | 11 +- crates/gpui_platform/src/tests/mod.rs | 240 +++++++++++++------------- crates/zed/src/main.rs | 3 +- 3 files changed, 124 insertions(+), 130 deletions(-) diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs index a88b420a06..ce6a6658e1 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui/src/platform/test.rs @@ -1,6 +1,4 @@ use super::{AppVersion, CursorStyle, WindowBounds}; -use anyhow::{anyhow, Result}; -use collections::VecDeque; use crate::{ geometry::{ rect::RectF, @@ -9,6 +7,8 @@ use crate::{ keymap_matcher::KeymapMatcher, Action, AnyWindowHandle, ClipboardItem, Menu, }; +use anyhow::{anyhow, Result}; +use collections::VecDeque; use parking_lot::Mutex; use postage::oneshot; use std::{ @@ -330,12 +330,7 @@ impl super::Window for Window { fn set_input_handler(&mut self, _: Box) {} - fn prompt( - &self, - _: super::PromptLevel, - _: &str, - _: &[&str], - ) -> oneshot::Receiver { + fn prompt(&self, _: super::PromptLevel, _: &str, _: &[&str]) -> oneshot::Receiver { let (done_tx, done_rx) = oneshot::channel(); self.pending_prompts.borrow_mut().push_back(done_tx); done_rx diff --git a/crates/gpui_platform/src/tests/mod.rs b/crates/gpui_platform/src/tests/mod.rs index 949c9c3e27..7c7d5b4f55 100644 --- a/crates/gpui_platform/src/tests/mod.rs +++ b/crates/gpui_platform/src/tests/mod.rs @@ -1,125 +1,123 @@ +use gpui::fonts::{Properties, Weight}; +use gpui::text_layout::*; - use gpui::text_layout::*; - use gpui::fonts::{Properties, Weight}; - - #[gpui::test] - fn test_wrap_line(cx: &mut gpui::AppContext) { - let font_cache = cx.font_cache().clone(); - let font_system = cx.platform().fonts(); - let family = font_cache - .load_family(&["Courier"], &Default::default()) - .unwrap(); - let font_id = font_cache.select_font(family, &Default::default()).unwrap(); - - let mut wrapper = LineWrapper::new(font_id, 16., font_system); - assert_eq!( - wrapper - .wrap_line("aa bbb cccc ddddd eeee", 72.0) - .collect::>(), - &[ - Boundary::new(7, 0), - Boundary::new(12, 0), - Boundary::new(18, 0) - ], - ); - assert_eq!( - wrapper - .wrap_line("aaa aaaaaaaaaaaaaaaaaa", 72.0) - .collect::>(), - &[ - Boundary::new(4, 0), - Boundary::new(11, 0), - Boundary::new(18, 0) - ], - ); - assert_eq!( - wrapper.wrap_line(" aaaaaaa", 72.).collect::>(), - &[ - Boundary::new(7, 5), - Boundary::new(9, 5), - Boundary::new(11, 5), - ] - ); - assert_eq!( - wrapper - .wrap_line(" ", 72.) - .collect::>(), - &[ - Boundary::new(7, 0), - Boundary::new(14, 0), - Boundary::new(21, 0) - ] - ); - assert_eq!( - wrapper - .wrap_line(" aaaaaaaaaaaaaa", 72.) - .collect::>(), - &[ - Boundary::new(7, 0), - Boundary::new(14, 3), - Boundary::new(18, 3), - Boundary::new(22, 3), - ] - ); - } - - #[gpui::test(retries = 5)] - fn test_wrap_shaped_line(cx: &mut gpui::AppContext) { - // This is failing intermittently on CI and we don't have time to figure it out - let font_cache = cx.font_cache().clone(); - let font_system = cx.platform().fonts(); - let text_layout_cache = TextLayoutCache::new(font_system.clone()); - - let family = font_cache - .load_family(&["Helvetica"], &Default::default()) - .unwrap(); - let font_id = font_cache.select_font(family, &Default::default()).unwrap(); - let normal = RunStyle { - font_id, - color: Default::default(), - underline: Default::default(), - }; - let bold = RunStyle { - font_id: font_cache - .select_font( - family, - &Properties { - weight: Weight::BOLD, - ..Default::default() - }, - ) - .unwrap(), - color: Default::default(), - underline: Default::default(), - }; - - let text = "aa bbb cccc ddddd eeee"; - let line = text_layout_cache.layout_str( - text, - 16.0, - &[(4, normal), (5, bold), (6, normal), (1, bold), (7, normal)], - ); - - let mut wrapper = LineWrapper::new(font_id, 16., font_system); - assert_eq!( - wrapper - .wrap_shaped_line(text, &line, 72.0) - .collect::>(), - &[ - ShapedBoundary { - run_ix: 1, - glyph_ix: 3 - }, - ShapedBoundary { - run_ix: 2, - glyph_ix: 3 - }, - ShapedBoundary { - run_ix: 4, - glyph_ix: 2 - } - ], - ); +#[gpui::test] +fn test_wrap_line(cx: &mut gpui::AppContext) { + let font_cache = cx.font_cache().clone(); + let font_system = cx.platform().fonts(); + let family = font_cache + .load_family(&["Courier"], &Default::default()) + .unwrap(); + let font_id = font_cache.select_font(family, &Default::default()).unwrap(); + let mut wrapper = LineWrapper::new(font_id, 16., font_system); + assert_eq!( + wrapper + .wrap_line("aa bbb cccc ddddd eeee", 72.0) + .collect::>(), + &[ + Boundary::new(7, 0), + Boundary::new(12, 0), + Boundary::new(18, 0) + ], + ); + assert_eq!( + wrapper + .wrap_line("aaa aaaaaaaaaaaaaaaaaa", 72.0) + .collect::>(), + &[ + Boundary::new(4, 0), + Boundary::new(11, 0), + Boundary::new(18, 0) + ], + ); + assert_eq!( + wrapper.wrap_line(" aaaaaaa", 72.).collect::>(), + &[ + Boundary::new(7, 5), + Boundary::new(9, 5), + Boundary::new(11, 5), + ] + ); + assert_eq!( + wrapper + .wrap_line(" ", 72.) + .collect::>(), + &[ + Boundary::new(7, 0), + Boundary::new(14, 0), + Boundary::new(21, 0) + ] + ); + assert_eq!( + wrapper + .wrap_line(" aaaaaaaaaaaaaa", 72.) + .collect::>(), + &[ + Boundary::new(7, 0), + Boundary::new(14, 3), + Boundary::new(18, 3), + Boundary::new(22, 3), + ] + ); +} + +#[gpui::test(retries = 5)] +fn test_wrap_shaped_line(cx: &mut gpui::AppContext) { + // This is failing intermittently on CI and we don't have time to figure it out + let font_cache = cx.font_cache().clone(); + let font_system = cx.platform().fonts(); + let text_layout_cache = TextLayoutCache::new(font_system.clone()); + + let family = font_cache + .load_family(&["Helvetica"], &Default::default()) + .unwrap(); + let font_id = font_cache.select_font(family, &Default::default()).unwrap(); + let normal = RunStyle { + font_id, + color: Default::default(), + underline: Default::default(), + }; + let bold = RunStyle { + font_id: font_cache + .select_font( + family, + &Properties { + weight: Weight::BOLD, + ..Default::default() + }, + ) + .unwrap(), + color: Default::default(), + underline: Default::default(), + }; + + let text = "aa bbb cccc ddddd eeee"; + let line = text_layout_cache.layout_str( + text, + 16.0, + &[(4, normal), (5, bold), (6, normal), (1, bold), (7, normal)], + ); + + let mut wrapper = LineWrapper::new(font_id, 16., font_system); + assert_eq!( + wrapper + .wrap_shaped_line(text, &line, 72.0) + .collect::>(), + &[ + ShapedBoundary { + run_ix: 1, + glyph_ix: 3 + }, + ShapedBoundary { + run_ix: 2, + glyph_ix: 3 + }, + ShapedBoundary { + run_ix: 4, + glyph_ix: 2 + } + ], + ); } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 0f6612b8ff..0b740e8767 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -75,7 +75,8 @@ fn main() { log::info!("========== starting zed =========="); let platform = platform(); - let foreground = std::rc::Rc::new(gpui::executor::Foreground::platform(platform.dispatcher()).unwrap()); + let foreground = + std::rc::Rc::new(gpui::executor::Foreground::platform(platform.dispatcher()).unwrap()); let fplatform = foreground_platform(foreground); let mut app = gpui::App::new(Assets, platform, fplatform).unwrap();