Uncomment hover popover tests

This commit is contained in:
Antonio Scandurra 2023-11-27 19:14:58 +01:00
parent 1e6214440d
commit 8c53f1b9c2

View file

@ -868,48 +868,49 @@ mod tests {
fn test_render_blocks(cx: &mut gpui::TestAppContext) { fn test_render_blocks(cx: &mut gpui::TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
cx.add_window(|cx| { let editor = cx.add_window(|cx| Editor::single_line(cx));
let editor = Editor::single_line(cx); editor
let style = editor.style.clone().unwrap(); .update(cx, |editor, cx| {
let style = editor.style.clone().unwrap();
struct Row { struct Row {
blocks: Vec<HoverBlock>, blocks: Vec<HoverBlock>,
expected_marked_text: String, expected_marked_text: String,
expected_styles: Vec<HighlightStyle>, expected_styles: Vec<HighlightStyle>,
} }
let rows = &[ let rows = &[
// Strong emphasis // Strong emphasis
Row { Row {
blocks: vec![HoverBlock { blocks: vec![HoverBlock {
text: "one **two** three".to_string(), text: "one **two** three".to_string(),
kind: HoverBlockKind::Markdown, kind: HoverBlockKind::Markdown,
}], }],
expected_marked_text: "one «two» three".to_string(), expected_marked_text: "one «two» three".to_string(),
expected_styles: vec![HighlightStyle { expected_styles: vec![HighlightStyle {
font_weight: Some(FontWeight::BOLD), 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(),
..Default::default() ..Default::default()
}), }],
..Default::default() },
}], // Links
}, Row {
// Lists blocks: vec![HoverBlock {
Row { text: "one [two](https://the-url) three".to_string(),
blocks: vec![HoverBlock { kind: HoverBlockKind::Markdown,
text: " }],
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: lists:
* one * one
- a - a
@ -917,10 +918,10 @@ mod tests {
* two * two
- [c](https://the-url) - [c](https://the-url)
- d" - d"
.unindent(), .unindent(),
kind: HoverBlockKind::Markdown, kind: HoverBlockKind::Markdown,
}], }],
expected_marked_text: " expected_marked_text: "
lists: lists:
- one - one
- a - a
@ -928,19 +929,19 @@ mod tests {
- two - two
- «c» - «c»
- d" - d"
.unindent(), .unindent(),
expected_styles: vec![HighlightStyle { expected_styles: vec![HighlightStyle {
underline: Some(UnderlineStyle { underline: Some(UnderlineStyle {
thickness: 1.0.into(), thickness: 1.0.into(),
..Default::default()
}),
..Default::default() ..Default::default()
}), }],
..Default::default() },
}], // Multi-paragraph list items
}, Row {
// Multi-paragraph list items blocks: vec![HoverBlock {
Row { text: "
blocks: vec![HoverBlock {
text: "
* one two * one two
three three
@ -951,10 +952,10 @@ mod tests {
nine nine
* ten * ten
* six" * six"
.unindent(), .unindent(),
kind: HoverBlockKind::Markdown, kind: HoverBlockKind::Markdown,
}], }],
expected_marked_text: " expected_marked_text: "
- one two three - one two three
- four five - four five
- six seven eight - six seven eight
@ -962,52 +963,51 @@ mod tests {
nine nine
- ten - ten
- six" - six"
.unindent(), .unindent(),
expected_styles: vec![HighlightStyle { expected_styles: vec![HighlightStyle {
underline: Some(UnderlineStyle { underline: Some(UnderlineStyle {
thickness: 1.0.into(), thickness: 1.0.into(),
..Default::default()
}),
..Default::default() ..Default::default()
}), }],
..Default::default() },
}], ];
},
];
for Row { for Row {
blocks, blocks,
expected_marked_text, expected_marked_text,
expected_styles, expected_styles,
} in &rows[0..] } in &rows[0..]
{ {
let rendered = smol::block_on(parse_blocks(&blocks, &Default::default(), None)); let rendered = smol::block_on(parse_blocks(&blocks, &Default::default(), None));
let (expected_text, ranges) = marked_text_ranges(expected_marked_text, false); let (expected_text, ranges) = marked_text_ranges(expected_marked_text, false);
let expected_highlights = ranges let expected_highlights = ranges
.into_iter() .into_iter()
.zip(expected_styles.iter().cloned()) .zip(expected_styles.iter().cloned())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!( assert_eq!(
rendered.text, expected_text, rendered.text, expected_text,
"wrong text for input {blocks:?}" "wrong text for input {blocks:?}"
); );
let rendered_highlights: Vec<_> = rendered let rendered_highlights: Vec<_> = rendered
.highlights .highlights
.iter() .iter()
.filter_map(|(range, highlight)| { .filter_map(|(range, highlight)| {
let highlight = highlight.to_highlight_style(&style.syntax)?; let highlight = highlight.to_highlight_style(&style.syntax)?;
Some((range.clone(), highlight)) Some((range.clone(), highlight))
}) })
.collect(); .collect();
assert_eq!( assert_eq!(
rendered_highlights, expected_highlights, rendered_highlights, expected_highlights,
"wrong highlights for input {blocks:?}" "wrong highlights for input {blocks:?}"
); );
} }
})
editor .unwrap();
});
} }
#[gpui::test] #[gpui::test]