mirror of
https://github.com/helix-editor/helix.git
synced 2024-08-17 06:40:47 +03:00
test: match around closest pair tree-sitter version
This commit is contained in:
parent
81dc8e8d6b
commit
839ec4ad39
@ -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)
|
||||
)
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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 rust<ret>mrm'",
|
||||
r#"\
|
||||
fn foo() {
|
||||
if let Some(_) = None {
|
||||
todo!('f#[|o]#o)');
|
||||
}
|
||||
}
|
||||
"#,
|
||||
))
|
||||
.await?;
|
||||
|
||||
test((
|
||||
INPUT,
|
||||
":lang rust<ret>3mrm[",
|
||||
r#"\
|
||||
fn foo() {
|
||||
if let Some(_) = None [
|
||||
todo!("f#[|o]#o)");
|
||||
]
|
||||
}
|
||||
"#,
|
||||
))
|
||||
.await?;
|
||||
|
||||
test((
|
||||
INPUT,
|
||||
":lang rust<ret>2mrm{",
|
||||
r#"\
|
||||
fn foo() {
|
||||
if let Some(_) = None {
|
||||
todo!{"f#[|o]#o)"};
|
||||
}
|
||||
}
|
||||
"#,
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -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")]
|
||||
|
Loading…
Reference in New Issue
Block a user