Move settings::test helper into zed::test

This commit is contained in:
Antonio Scandurra 2021-10-05 11:00:33 +02:00
parent 5105596918
commit 0022c6b828
3 changed files with 45 additions and 42 deletions

View file

@ -14,39 +14,13 @@ pub struct Settings {
}
impl Settings {
#[cfg(any(test, feature = "test-support"))]
pub fn test(cx: &gpui::AppContext) -> Self {
use crate::assets::Assets;
use gpui::AssetSource;
lazy_static::lazy_static! {
static ref DEFAULT_THEME: parking_lot::Mutex<Option<Arc<Theme>>> = Default::default();
static ref FONTS: Vec<Arc<Vec<u8>>> = Assets
.list("fonts")
.into_iter()
.map(|f| Arc::new(Assets.load(&f).unwrap().to_vec()))
.collect();
}
cx.platform().fonts().add_fonts(&FONTS).unwrap();
let mut theme_guard = DEFAULT_THEME.lock();
let theme = if let Some(theme) = theme_guard.as_ref() {
theme.clone()
} else {
let theme = ThemeRegistry::new(Assets, cx.font_cache().clone())
.get(DEFAULT_THEME_NAME)
.expect("failed to load default theme in tests");
*theme_guard = Some(theme.clone());
theme
};
Self::new(cx.font_cache(), theme).unwrap()
}
pub fn new(font_cache: &FontCache, theme: Arc<Theme>) -> Result<Self> {
pub fn new(
buffer_font_family: &str,
font_cache: &FontCache,
theme: Arc<Theme>,
) -> Result<Self> {
Ok(Self {
buffer_font_family: font_cache.load_family(&["Inconsolata"])?,
buffer_font_family: font_cache.load_family(&[buffer_font_family])?,
buffer_font_size: 16.,
tab_size: 4,
theme,
@ -59,12 +33,8 @@ impl Settings {
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn test(cx: &gpui::AppContext) -> (watch::Sender<Settings>, watch::Receiver<Settings>) {
watch::channel_with(Settings::test(cx))
}
pub fn channel(
buffer_font_family: &str,
font_cache: &FontCache,
themes: &ThemeRegistry,
) -> Result<(watch::Sender<Settings>, watch::Receiver<Settings>)> {
@ -74,5 +44,9 @@ pub fn channel(
panic!("failed to deserialize default theme: {:?}", err)
}
};
Ok(watch::channel_with(Settings::new(font_cache, theme)?))
Ok(watch::channel_with(Settings::new(
buffer_font_family,
font_cache,
theme,
)?))
}