From 8c53f1b9c205a3a2db01af9866a71f32df9bc31b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 27 Nov 2023 19:14:58 +0100 Subject: [PATCH] Uncomment hover popover tests --- crates/editor2/src/hover_popover.rs | 206 ++++++++++++++-------------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/crates/editor2/src/hover_popover.rs b/crates/editor2/src/hover_popover.rs index d4886120435c6e7b298b10c3f9c2580ecf8ab9fd..e7980758e046cda1adb4c6eb43ff272f864c92b9 100644 --- a/crates/editor2/src/hover_popover.rs +++ b/crates/editor2/src/hover_popover.rs @@ -868,48 +868,49 @@ mod tests { fn test_render_blocks(cx: &mut gpui::TestAppContext) { init_test(cx, |_| {}); - cx.add_window(|cx| { - let editor = Editor::single_line(cx); - let style = editor.style.clone().unwrap(); - - struct Row { - blocks: Vec, - expected_marked_text: String, - expected_styles: Vec, - } + let editor = cx.add_window(|cx| Editor::single_line(cx)); + editor + .update(cx, |editor, cx| { + let style = editor.style.clone().unwrap(); + + struct Row { + blocks: Vec, + expected_marked_text: String, + expected_styles: Vec, + } - let rows = &[ - // Strong emphasis - Row { - blocks: vec![HoverBlock { - text: "one **two** three".to_string(), - kind: HoverBlockKind::Markdown, - }], - expected_marked_text: "one «two» three".to_string(), - expected_styles: vec![HighlightStyle { - font_weight: Some(FontWeight::BOLD), - ..Default::default() - }], - }, - // Links - Row { - blocks: vec![HoverBlock { - text: "one [two](https://the-url) three".to_string(), - kind: HoverBlockKind::Markdown, - }], - expected_marked_text: "one «two» three".to_string(), - expected_styles: vec![HighlightStyle { - underline: Some(UnderlineStyle { - thickness: 1.0.into(), + let rows = &[ + // Strong emphasis + Row { + blocks: vec![HoverBlock { + text: "one **two** three".to_string(), + kind: HoverBlockKind::Markdown, + }], + expected_marked_text: "one «two» three".to_string(), + expected_styles: vec![HighlightStyle { + font_weight: Some(FontWeight::BOLD), ..Default::default() - }), - ..Default::default() - }], - }, - // Lists - Row { - blocks: vec![HoverBlock { - text: " + }], + }, + // Links + Row { + blocks: vec![HoverBlock { + text: "one [two](https://the-url) three".to_string(), + kind: HoverBlockKind::Markdown, + }], + expected_marked_text: "one «two» three".to_string(), + expected_styles: vec![HighlightStyle { + underline: Some(UnderlineStyle { + thickness: 1.0.into(), + ..Default::default() + }), + ..Default::default() + }], + }, + // Lists + Row { + blocks: vec![HoverBlock { + text: " lists: * one - a @@ -917,10 +918,10 @@ mod tests { * two - [c](https://the-url) - d" - .unindent(), - kind: HoverBlockKind::Markdown, - }], - expected_marked_text: " + .unindent(), + kind: HoverBlockKind::Markdown, + }], + expected_marked_text: " lists: - one - a @@ -928,19 +929,19 @@ mod tests { - two - «c» - d" - .unindent(), - expected_styles: vec![HighlightStyle { - underline: Some(UnderlineStyle { - thickness: 1.0.into(), + .unindent(), + expected_styles: vec![HighlightStyle { + underline: Some(UnderlineStyle { + thickness: 1.0.into(), + ..Default::default() + }), ..Default::default() - }), - ..Default::default() - }], - }, - // Multi-paragraph list items - Row { - blocks: vec![HoverBlock { - text: " + }], + }, + // Multi-paragraph list items + Row { + blocks: vec![HoverBlock { + text: " * one two three @@ -951,10 +952,10 @@ mod tests { nine * ten * six" - .unindent(), - kind: HoverBlockKind::Markdown, - }], - expected_marked_text: " + .unindent(), + kind: HoverBlockKind::Markdown, + }], + expected_marked_text: " - one two three - four five - six seven eight @@ -962,52 +963,51 @@ mod tests { nine - ten - six" - .unindent(), - expected_styles: vec![HighlightStyle { - underline: Some(UnderlineStyle { - thickness: 1.0.into(), + .unindent(), + expected_styles: vec![HighlightStyle { + underline: Some(UnderlineStyle { + thickness: 1.0.into(), + ..Default::default() + }), ..Default::default() - }), - ..Default::default() - }], - }, - ]; - - for Row { - blocks, - expected_marked_text, - expected_styles, - } in &rows[0..] - { - let rendered = smol::block_on(parse_blocks(&blocks, &Default::default(), None)); - - let (expected_text, ranges) = marked_text_ranges(expected_marked_text, false); - let expected_highlights = ranges - .into_iter() - .zip(expected_styles.iter().cloned()) - .collect::>(); - assert_eq!( - rendered.text, expected_text, - "wrong text for input {blocks:?}" - ); - - let rendered_highlights: Vec<_> = rendered - .highlights - .iter() - .filter_map(|(range, highlight)| { - let highlight = highlight.to_highlight_style(&style.syntax)?; - Some((range.clone(), highlight)) - }) - .collect(); + }], + }, + ]; - assert_eq!( - rendered_highlights, expected_highlights, - "wrong highlights for input {blocks:?}" - ); - } + for Row { + blocks, + expected_marked_text, + expected_styles, + } in &rows[0..] + { + let rendered = smol::block_on(parse_blocks(&blocks, &Default::default(), None)); + + let (expected_text, ranges) = marked_text_ranges(expected_marked_text, false); + let expected_highlights = ranges + .into_iter() + .zip(expected_styles.iter().cloned()) + .collect::>(); + assert_eq!( + rendered.text, expected_text, + "wrong text for input {blocks:?}" + ); - editor - }); + let rendered_highlights: Vec<_> = rendered + .highlights + .iter() + .filter_map(|(range, highlight)| { + let highlight = highlight.to_highlight_style(&style.syntax)?; + Some((range.clone(), highlight)) + }) + .collect(); + + assert_eq!( + rendered_highlights, expected_highlights, + "wrong highlights for input {blocks:?}" + ); + } + }) + .unwrap(); } #[gpui::test]