From 8262afd1fb3b0de008270f15e02a3997305502d4 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 7 Sep 2021 21:46:36 -0600 Subject: [PATCH] Fix compile errors in tests --- zed/src/editor/display_map.rs | 88 ++++++++++++----------------------- zed/src/editor/movement.rs | 2 +- 2 files changed, 32 insertions(+), 58 deletions(-) diff --git a/zed/src/editor/display_map.rs b/zed/src/editor/display_map.rs index 4f2328ce5bcdd40604a9385ad3bff3093ad43474..ffad1b9c795604efaa8f695c019ff797d2672ee3 100644 --- a/zed/src/editor/display_map.rs +++ b/zed/src/editor/display_map.rs @@ -608,17 +608,11 @@ mod tests { fn test_chunks_at(cx: &mut gpui::MutableAppContext) { let text = sample_text(6, 6); let buffer = cx.add_model(|cx| Buffer::new(0, text, cx)); - let map = cx.add_model(|cx| { - DisplayMap::new( - buffer.clone(), - Settings { - tab_size: 4, - ..Settings::test(cx) - }, - None, - cx, - ) + let settings = watch::channel_with(Settings { + tab_size: 4, + ..Settings::test(cx) }); + let map = cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings.1, None, cx)); buffer.update(cx, |buffer, cx| { buffer.edit( vec![ @@ -690,17 +684,13 @@ mod tests { }); buffer.condition(&cx, |buf, _| !buf.is_parsing()).await; - let map = cx.add_model(|cx| { - DisplayMap::new( - buffer, - Settings { - tab_size: 2, - ..Settings::test(cx) - }, - None, - cx, - ) + let settings = cx.update(|cx| { + watch::channel_with(Settings { + tab_size: 2, + ..Settings::test(cx) + }) }); + let map = cx.add_model(|cx| DisplayMap::new(buffer, settings.1, None, cx)); assert_eq!( cx.update(|cx| highlighted_chunks(0..5, &map, &theme, cx)), vec![ @@ -781,13 +771,15 @@ mod tests { buffer.condition(&cx, |buf, _| !buf.is_parsing()).await; let font_cache = cx.font_cache(); - let settings = Settings { - tab_size: 4, - buffer_font_family: font_cache.load_family(&["Courier"]).unwrap(), - buffer_font_size: 16.0, - ..cx.read(Settings::test) - }; - let map = cx.add_model(|cx| DisplayMap::new(buffer, settings, Some(40.0), cx)); + let settings = cx.update(|cx| { + watch::channel_with(Settings { + tab_size: 4, + buffer_font_family: font_cache.load_family(&["Courier"]).unwrap(), + buffer_font_size: 16.0, + ..Settings::test(cx) + }) + }); + let map = cx.add_model(|cx| DisplayMap::new(buffer, settings.1, Some(40.0), cx)); assert_eq!( cx.update(|cx| highlighted_chunks(0..5, &map, &theme, cx)), [ @@ -822,17 +814,11 @@ mod tests { let text = "\n'a', 'α',\t'✋',\t'❎', '🍐'\n"; let display_text = "\n'a', 'α', '✋', '❎', '🍐'\n"; let buffer = cx.add_model(|cx| Buffer::new(0, text, cx)); - let map = cx.add_model(|cx| { - DisplayMap::new( - buffer.clone(), - Settings { - tab_size: 4, - ..Settings::test(cx) - }, - None, - cx, - ) + let settings = watch::channel_with(Settings { + tab_size: 4, + ..Settings::test(cx) }); + let map = cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings.1, None, cx)); let map = map.update(cx, |map, cx| map.snapshot(cx)); assert_eq!(map.text(), display_text); @@ -866,17 +852,11 @@ mod tests { fn test_tabs_with_multibyte_chars(cx: &mut gpui::MutableAppContext) { let text = "✅\t\tα\nβ\t\n🏀β\t\tγ"; let buffer = cx.add_model(|cx| Buffer::new(0, text, cx)); - let map = cx.add_model(|cx| { - DisplayMap::new( - buffer.clone(), - Settings { - tab_size: 4, - ..Settings::test(cx) - }, - None, - cx, - ) + let settings = watch::channel_with(Settings { + tab_size: 4, + ..Settings::test(cx) }); + let map = cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings.1, None, cx)); let map = map.update(cx, |map, cx| map.snapshot(cx)); assert_eq!(map.text(), "✅ α\nβ \n🏀β γ"); assert_eq!( @@ -933,17 +913,11 @@ mod tests { #[gpui::test] fn test_max_point(cx: &mut gpui::MutableAppContext) { let buffer = cx.add_model(|cx| Buffer::new(0, "aaa\n\t\tbbb", cx)); - let map = cx.add_model(|cx| { - DisplayMap::new( - buffer.clone(), - Settings { - tab_size: 4, - ..Settings::test(cx) - }, - None, - cx, - ) + let settings = watch::channel_with(Settings { + tab_size: 4, + ..Settings::test(cx) }); + let map = cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings.1, None, cx)); assert_eq!( map.update(cx, |map, cx| map.snapshot(cx)).max_point(), DisplayPoint::new(1, 11) diff --git a/zed/src/editor/movement.rs b/zed/src/editor/movement.rs index 0e244995e7c78c8b148f9210e5ff22bbb0fd552e..aec3932a7d9ad96154f44e95783e9d8a70801c61 100644 --- a/zed/src/editor/movement.rs +++ b/zed/src/editor/movement.rs @@ -187,7 +187,7 @@ mod tests { #[gpui::test] fn test_prev_next_word_boundary_multibyte(cx: &mut gpui::MutableAppContext) { - let settings = test_app_state(cx).settings.borrow().clone(); + let settings = test_app_state(cx).settings.clone(); let buffer = cx.add_model(|cx| Buffer::new(0, "a bcΔ defγ", cx)); let display_map = cx.add_model(|cx| DisplayMap::new(buffer, settings, None, cx)); let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));