From 643ae307532b7b8a3e1f9451535abc0b289402b6 Mon Sep 17 00:00:00 2001 From: MrSubidubi Date: Mon, 10 Nov 2025 12:06:17 +0100 Subject: [PATCH] Extend tests --- crates/editor/src/bracket_colorization.rs | 37 +++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/bracket_colorization.rs b/crates/editor/src/bracket_colorization.rs index d1c9ce49709ea31ceb99d53b1fa56632fa7d8d65..621476c0b373283780ba2bcbc45a58204ccce800 100644 --- a/crates/editor/src/bracket_colorization.rs +++ b/crates/editor/src/bracket_colorization.rs @@ -111,10 +111,11 @@ impl Editor { #[cfg(test)] mod tests { - use std::{ops::Range, time::Duration}; + use std::{collections::HashSet, ops::Range, time::Duration}; use super::*; use crate::{ + display_map::{DisplayRow, ToDisplayPoint}, editor_tests::init_test, test::{ editor_lsp_test_context::EditorLspTestContext, editor_test_context::EditorTestContext, @@ -461,7 +462,8 @@ mod tests { }); cx.executor().run_until_parked(); - for (color, range) in collect_colored_brackets(&mut cx) { + let colored_brackets = collect_colored_brackets(&mut cx); + for (color, range) in colored_brackets.iter().cloned() { assert!( highlighted_brackets .entry(range.clone()) @@ -470,6 +472,37 @@ mod tests { "Colors should stay consistent while scrolling!" ); } + + let snapshot = cx.update_editor(|editor, window, cx| editor.snapshot(window, cx)); + let scroll_position = snapshot.scroll_position(); + let visible_lines = + cx.update_editor(|editor, _, _| editor.visible_line_count().unwrap()); + let visible_range = DisplayRow(scroll_position.y as u32) + ..DisplayRow((scroll_position.y + visible_lines) as u32); + + let current_highlighted_bracket_set: HashSet = HashSet::from_iter( + colored_brackets + .iter() + .flat_map(|(_, range)| [range.start, range.end]), + ); + + for highlight_range in + highlighted_brackets + .iter() + .map(|(range, _)| range) + .filter(|bracket_range| { + visible_range + .contains(&bracket_range.start.to_display_point(&snapshot).row()) + || visible_range + .contains(&bracket_range.end.to_display_point(&snapshot).row()) + }) + { + assert!( + current_highlighted_bracket_set.contains(&highlight_range.start) + || current_highlighted_bracket_set.contains(&highlight_range.end), + "Should not lose highlights while scrolling in the visible range!" + ); + } } // todo! more tests, check no brackets missing in range, settings toggle