From e7b5880af0599aab13567db8fb2b55c13abc3fa4 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 14 Sep 2023 23:53:56 +0300 Subject: [PATCH] Combine both text and inlay highlights in randomized tests --- crates/editor/src/display_map/inlay_map.rs | 49 +++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index a67e8484eb..124b32c234 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -1669,30 +1669,31 @@ mod tests { } let mut text_highlights = TextHighlights::default(); + let text_highlight_count = rng.gen_range(0_usize..10); + let mut text_highlight_ranges = (0..text_highlight_count) + .map(|_| buffer_snapshot.random_byte_range(0, &mut rng)) + .collect::>(); + text_highlight_ranges.sort_by_key(|range| (range.start, Reverse(range.end))); + log::info!("highlighting text ranges {text_highlight_ranges:?}"); + text_highlights.insert( + Some(TypeId::of::<()>()), + Arc::new(( + HighlightStyle::default(), + text_highlight_ranges + .into_iter() + .map(|range| { + buffer_snapshot.anchor_before(range.start) + ..buffer_snapshot.anchor_after(range.end) + }) + .collect(), + )), + ); + let mut inlay_highlights = InlayHighlights::default(); - let highlight_count = rng.gen_range(0_usize..10); - if false && rng.gen_bool(0.5) { - let mut highlight_ranges = (0..highlight_count) - .map(|_| buffer_snapshot.random_byte_range(0, &mut rng)) - .collect::>(); - highlight_ranges.sort_by_key(|range| (range.start, Reverse(range.end))); - log::info!("highlighting text ranges {highlight_ranges:?}"); - text_highlights.insert( - Some(TypeId::of::<()>()), - Arc::new(( - HighlightStyle::default(), - highlight_ranges - .into_iter() - .map(|range| { - buffer_snapshot.anchor_before(range.start) - ..buffer_snapshot.anchor_after(range.end) - }) - .collect(), - )), - ); - } else { + if !inlays.is_empty() { + let inlay_highlight_count = rng.gen_range(0..inlays.len()); let mut inlay_indices = BTreeSet::default(); - while inlay_indices.len() < highlight_count.min(inlays.len()) { + while inlay_indices.len() < inlay_highlight_count { inlay_indices.insert(rng.gen_range(0..inlays.len())); } let new_highlights = inlay_indices @@ -1729,7 +1730,7 @@ mod tests { .collect(); log::info!("highlighting inlay ranges {new_highlights:?}"); inlay_highlights.insert(TypeId::of::<()>(), new_highlights); - }; + } for _ in 0..5 { let mut end = rng.gen_range(0..=inlay_snapshot.len().0); @@ -1738,7 +1739,7 @@ mod tests { start = expected_text.clip_offset(start, Bias::Right); let range = InlayOffset(start)..InlayOffset(end); - log::info!("calling inlay_snapshot.chunks({:?})", range); + log::info!("calling inlay_snapshot.chunks({range:?})"); let actual_text = inlay_snapshot .chunks( range,