From e0ec5032e9ca0f81ddb0a8101ad5c8e143b51436 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:19:49 +0100 Subject: [PATCH] Fix highlight tests (and a quirky behaviour where the highlights were not dismissed when user clicks on something that's not a brace) --- .../editor2/src/highlight_matching_bracket.rs | 200 +++++++++--------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/crates/editor2/src/highlight_matching_bracket.rs b/crates/editor2/src/highlight_matching_bracket.rs index d7fd37745f0e1465ba5fec5f018834dec68df52f..1ed7700f37a56cd428015fdffbe25b78b2c02fad 100644 --- a/crates/editor2/src/highlight_matching_bracket.rs +++ b/crates/editor2/src/highlight_matching_bracket.rs @@ -5,7 +5,7 @@ use crate::{Editor, RangeToAnchorExt}; enum MatchingBracketHighlight {} pub fn refresh_matching_bracket_highlights(editor: &mut Editor, cx: &mut ViewContext) { - // editor.clear_background_highlights::(cx); + editor.clear_background_highlights::(cx); let newest_selection = editor.selections.newest::(cx); // Don't highlight brackets if the selection isn't empty @@ -30,109 +30,109 @@ pub fn refresh_matching_bracket_highlights(editor: &mut Editor, cx: &mut ViewCon } } -// #[cfg(test)] -// mod tests { -// use super::*; -// use crate::{editor_tests::init_test, test::editor_lsp_test_context::EditorLspTestContext}; -// use indoc::indoc; -// use language::{BracketPair, BracketPairConfig, Language, LanguageConfig}; +#[cfg(test)] +mod tests { + use super::*; + use crate::{editor_tests::init_test, test::editor_lsp_test_context::EditorLspTestContext}; + use indoc::indoc; + use language::{BracketPair, BracketPairConfig, Language, LanguageConfig}; -// #[gpui::test] -// async fn test_matching_bracket_highlights(cx: &mut gpui::TestAppContext) { -// init_test(cx, |_| {}); + #[gpui::test] + async fn test_matching_bracket_highlights(cx: &mut gpui::TestAppContext) { + init_test(cx, |_| {}); -// let mut cx = EditorLspTestContext::new( -// Language::new( -// LanguageConfig { -// name: "Rust".into(), -// path_suffixes: vec!["rs".to_string()], -// brackets: BracketPairConfig { -// pairs: vec![ -// BracketPair { -// start: "{".to_string(), -// end: "}".to_string(), -// close: false, -// newline: true, -// }, -// BracketPair { -// start: "(".to_string(), -// end: ")".to_string(), -// close: false, -// newline: true, -// }, -// ], -// ..Default::default() -// }, -// ..Default::default() -// }, -// Some(tree_sitter_rust::language()), -// ) -// .with_brackets_query(indoc! {r#" -// ("{" @open "}" @close) -// ("(" @open ")" @close) -// "#}) -// .unwrap(), -// Default::default(), -// cx, -// ) -// .await; + let mut cx = EditorLspTestContext::new( + Language::new( + LanguageConfig { + name: "Rust".into(), + path_suffixes: vec!["rs".to_string()], + brackets: BracketPairConfig { + pairs: vec![ + BracketPair { + start: "{".to_string(), + end: "}".to_string(), + close: false, + newline: true, + }, + BracketPair { + start: "(".to_string(), + end: ")".to_string(), + close: false, + newline: true, + }, + ], + ..Default::default() + }, + ..Default::default() + }, + Some(tree_sitter_rust::language()), + ) + .with_brackets_query(indoc! {r#" + ("{" @open "}" @close) + ("(" @open ")" @close) + "#}) + .unwrap(), + Default::default(), + cx, + ) + .await; -// // positioning cursor inside bracket highlights both -// cx.set_state(indoc! {r#" -// pub fn test("Test ˇargument") { -// another_test(1, 2, 3); -// } -// "#}); -// cx.assert_editor_background_highlights::(indoc! {r#" -// pub fn test«(»"Test argument"«)» { -// another_test(1, 2, 3); -// } -// "#}); + // positioning cursor inside bracket highlights both + cx.set_state(indoc! {r#" + pub fn test("Test ˇargument") { + another_test(1, 2, 3); + } + "#}); + cx.assert_editor_background_highlights::(indoc! {r#" + pub fn test«(»"Test argument"«)» { + another_test(1, 2, 3); + } + "#}); -// cx.set_state(indoc! {r#" -// pub fn test("Test argument") { -// another_test(1, ˇ2, 3); -// } -// "#}); -// cx.assert_editor_background_highlights::(indoc! {r#" -// pub fn test("Test argument") { -// another_test«(»1, 2, 3«)»; -// } -// "#}); + cx.set_state(indoc! {r#" + pub fn test("Test argument") { + another_test(1, ˇ2, 3); + } + "#}); + cx.assert_editor_background_highlights::(indoc! {r#" + pub fn test("Test argument") { + another_test«(»1, 2, 3«)»; + } + "#}); -// cx.set_state(indoc! {r#" -// pub fn test("Test argument") { -// anotherˇ_test(1, 2, 3); -// } -// "#}); -// cx.assert_editor_background_highlights::(indoc! {r#" -// pub fn test("Test argument") «{» -// another_test(1, 2, 3); -// «}» -// "#}); + cx.set_state(indoc! {r#" + pub fn test("Test argument") { + anotherˇ_test(1, 2, 3); + } + "#}); + cx.assert_editor_background_highlights::(indoc! {r#" + pub fn test("Test argument") «{» + another_test(1, 2, 3); + «}» + "#}); -// // positioning outside of brackets removes highlight -// cx.set_state(indoc! {r#" -// pub fˇn test("Test argument") { -// another_test(1, 2, 3); -// } -// "#}); -// cx.assert_editor_background_highlights::(indoc! {r#" -// pub fn test("Test argument") { -// another_test(1, 2, 3); -// } -// "#}); + // positioning outside of brackets removes highlight + cx.set_state(indoc! {r#" + pub fˇn test("Test argument") { + another_test(1, 2, 3); + } + "#}); + cx.assert_editor_background_highlights::(indoc! {r#" + pub fn test("Test argument") { + another_test(1, 2, 3); + } + "#}); -// // non empty selection dismisses highlight -// cx.set_state(indoc! {r#" -// pub fn test("Te«st argˇ»ument") { -// another_test(1, 2, 3); -// } -// "#}); -// cx.assert_editor_background_highlights::(indoc! {r#" -// pub fn test("Test argument") { -// another_test(1, 2, 3); -// } -// "#}); -// } -// } + // non empty selection dismisses highlight + cx.set_state(indoc! {r#" + pub fn test("Te«st argˇ»ument") { + another_test(1, 2, 3); + } + "#}); + cx.assert_editor_background_highlights::(indoc! {r#" + pub fn test("Test argument") { + another_test(1, 2, 3); + } + "#}); + } +}