From 839ec4ad3934b3c390bfd54a30462789cc90cc5c Mon Sep 17 00:00:00 2001 From: woojiq Date: Tue, 9 Apr 2024 18:29:54 +0300 Subject: [PATCH] test: match around closest pair tree-sitter version --- helix-core/src/surround.rs | 10 +++--- helix-core/src/textobject.rs | 3 +- helix-term/tests/test/commands.rs | 60 +++++++++++++++++++++++++++++++ helix-term/tests/test/movement.rs | 43 ++++++++++++++++++++++ 4 files changed, 110 insertions(+), 6 deletions(-) diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs index 879c2adf1..e45346c92 100644 --- a/helix-core/src/surround.rs +++ b/helix-core/src/surround.rs @@ -331,7 +331,7 @@ fn test_get_surround_pos() { ); assert_eq!( - get_surround_pos(doc.slice(..), &selection, Some('('), 1).unwrap(), + get_surround_pos(None, doc.slice(..), &selection, Some('('), 1).unwrap(), expectations ); } @@ -346,7 +346,7 @@ fn test_get_surround_pos_bail_different_surround_chars() { ); assert_eq!( - get_surround_pos(doc.slice(..), &selection, Some('('), 1), + get_surround_pos(None, doc.slice(..), &selection, Some('('), 1), Err(Error::PairNotFound) ); } @@ -361,7 +361,7 @@ fn test_get_surround_pos_bail_overlapping_surround_chars() { ); assert_eq!( - get_surround_pos(doc.slice(..), &selection, Some('('), 1), + get_surround_pos(None, doc.slice(..), &selection, Some('('), 1), Err(Error::PairNotFound) // overlapping surround chars ); } @@ -376,7 +376,7 @@ fn test_get_surround_pos_bail_cursor_overlap() { ); assert_eq!( - get_surround_pos(doc.slice(..), &selection, Some('['), 1), + get_surround_pos(None, doc.slice(..), &selection, Some('['), 1), Err(Error::CursorOverlap) ); } @@ -440,7 +440,7 @@ fn test_find_nth_closest_pairs_pos_index_range_panic() { ); assert_eq!( - find_nth_closest_pairs_pos(doc.slice(..), selection.primary(), 1), + find_nth_closest_pairs_pos(None, doc.slice(..), selection.primary(), 1), Err(Error::PairNotFound) ) } diff --git a/helix-core/src/textobject.rs b/helix-core/src/textobject.rs index 412301261..7576b3a78 100644 --- a/helix-core/src/textobject.rs +++ b/helix-core/src/textobject.rs @@ -576,7 +576,8 @@ fn test_textobject_surround() { let slice = doc.slice(..); for &case in scenario { let (pos, objtype, expected_range, ch, count) = case; - let result = textobject_pair_surround(slice, Range::point(pos), objtype, ch, count); + let result = + textobject_pair_surround(None, slice, Range::point(pos), objtype, ch, count); assert_eq!( result, expected_range.into(), diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 6b904aa30..1c5c6196b 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -664,3 +664,63 @@ async fn test_read_file() -> anyhow::Result<()> { Ok(()) } + +#[tokio::test(flavor = "multi_thread")] +async fn surround_delete() -> anyhow::Result<()> { + // Test `surround_delete` when head < anchor + test(("(#[| ]#)", "mdm", "#[| ]#")).await?; + test(("(#[| ]#)", "md(", "#[| ]#")).await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn surround_replace_ts() -> anyhow::Result<()> { + const INPUT: &str = r#"\ +fn foo() { + if let Some(_) = None { + todo!("f#[|o]#o)"); + } +} +"#; + test(( + INPUT, + ":lang rustmrm'", + r#"\ +fn foo() { + if let Some(_) = None { + todo!('f#[|o]#o)'); + } +} +"#, + )) + .await?; + + test(( + INPUT, + ":lang rust3mrm[", + r#"\ +fn foo() { + if let Some(_) = None [ + todo!("f#[|o]#o)"); + ] +} +"#, + )) + .await?; + + test(( + INPUT, + ":lang rust2mrm{", + r#"\ +fn foo() { + if let Some(_) = None { + todo!{"f#[|o]#o)"}; + } +} +"#, + )) + .await?; + + Ok(()) +} diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 3fa850929..77098a336 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -107,6 +107,14 @@ async fn surround_by_character() -> anyhow::Result<()> { )) .await?; + // Selection direction is preserved + test(( + "(so [many {go#[|od]#} text] here)", + "mi{", + "(so [many {#[|good]#} text] here)", + )) + .await?; + Ok(()) } @@ -366,6 +374,41 @@ async fn surround_around_pair() -> anyhow::Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread")] +async fn match_around_closest_ts() -> anyhow::Result<()> { + test_with_config( + AppBuilder::new().with_file("foo.rs", None), + ( + r#"fn main() {todo!{"f#[|oo]#)"};}"#, + "mam", + r#"fn main() {todo!{#[|"foo)"]#};}"#, + ), + ) + .await?; + + test_with_config( + AppBuilder::new().with_file("foo.rs", None), + ( + r##"fn main() { let _ = ("#[|1]#23", "#(|1)#23"); } "##, + "3mam", + r##"fn main() #[|{ let _ = ("123", "123"); }]# "##, + ), + ) + .await?; + + test_with_config( + AppBuilder::new().with_file("foo.rs", None), + ( + r##" fn main() { let _ = ("12#[|3", "12]#3"); } "##, + "1mam", + r##" fn main() { let _ = #[|("123", "123")]#; } "##, + ), + ) + .await?; + + Ok(()) +} + /// Ensure the very initial cursor in an opened file is the width of /// the first grapheme #[tokio::test(flavor = "multi_thread")]