| 1 |
use super::*; |
| 2 |
|
| 3 |
#[tokio::test(flavor = "multi_thread")] |
| 4 |
async fn insert_mode_cursor_position() -> anyhow::Result<()> { |
| 5 |
test(TestCase { |
| 6 |
in_text: String::new(), |
| 7 |
in_selection: Selection::single(0, 0), |
| 8 |
in_keys: "i".into(), |
| 9 |
out_text: String::new(), |
| 10 |
out_selection: Selection::single(0, 0), |
| 11 |
line_feed_handling: LineFeedHandling::AsIs, |
| 12 |
}) |
| 13 |
.await?; |
| 14 |
|
| 15 |
test(("#[\n|]#", "i", "#[|\n]#")).await?; |
| 16 |
test(("#[\n|]#", "i<esc>", "#[|\n]#")).await?; |
| 17 |
test(("#[\n|]#", "i<esc>i", "#[|\n]#")).await?; |
| 18 |
|
| 19 |
Ok(()) |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
#[tokio::test(flavor = "multi_thread")] |
| 24 |
async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> { |
| 25 |
test(("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n")).await?; |
| 26 |
test(( |
| 27 |
indoc! {"\ |
| 28 |
#[f|]#oo |
| 29 |
#(b|)#ar" |
| 30 |
}, |
| 31 |
"vll<A-;><esc>", |
| 32 |
indoc! {"\ |
| 33 |
#[|foo]# |
| 34 |
#(|bar)#" |
| 35 |
}, |
| 36 |
)) |
| 37 |
.await?; |
| 38 |
|
| 39 |
test(( |
| 40 |
indoc! {"\ |
| 41 |
#[f|]#oo |
| 42 |
#(b|)#ar" |
| 43 |
}, |
| 44 |
"a", |
| 45 |
indoc! {"\ |
| 46 |
#[fo|]#o |
| 47 |
#(ba|)#r" |
| 48 |
}, |
| 49 |
)) |
| 50 |
.await?; |
| 51 |
|
| 52 |
test(( |
| 53 |
indoc! {"\ |
| 54 |
#[f|]#oo |
| 55 |
#(b|)#ar" |
| 56 |
}, |
| 57 |
"a<esc>", |
| 58 |
indoc! {"\ |
| 59 |
#[f|]#oo |
| 60 |
#(b|)#ar" |
| 61 |
}, |
| 62 |
)) |
| 63 |
.await?; |
| 64 |
|
| 65 |
Ok(()) |
| 66 |
} |
| 67 |
|
| 68 |
#[tokio::test(flavor = "multi_thread")] |
| 69 |
async fn surround_by_character() -> anyhow::Result<()> { |
| 70 |
|
| 71 |
test(( |
| 72 |
"(so [many {go#[o|]#d} text] here)", |
| 73 |
"mi{", |
| 74 |
"(so [many {#[good|]#} text] here)", |
| 75 |
)) |
| 76 |
.await?; |
| 77 |
test(( |
| 78 |
"(so [many {go#[o|]#d} text] here)", |
| 79 |
"mi[", |
| 80 |
"(so [#[many {good} text|]#] here)", |
| 81 |
)) |
| 82 |
.await?; |
| 83 |
test(( |
| 84 |
"(so [many {go#[o|]#d} text] here)", |
| 85 |
"mi(", |
| 86 |
"(#[so [many {good} text] here|]#)", |
| 87 |
)) |
| 88 |
.await?; |
| 89 |
|
| 90 |
|
| 91 |
test(( |
| 92 |
"'so 'many 'go#[o|]#d' text' here'", |
| 93 |
"mi'", |
| 94 |
"'so 'many '#[good|]#' text' here'", |
| 95 |
)) |
| 96 |
.await?; |
| 97 |
test(( |
| 98 |
"'so 'many 'go#[o|]#d' text' here'", |
| 99 |
"2mi'", |
| 100 |
"'so '#[many 'good' text|]#' here'", |
| 101 |
)) |
| 102 |
.await?; |
| 103 |
test(( |
| 104 |
"'so \"many 'go#[o|]#d' text\" here'", |
| 105 |
"mi\"", |
| 106 |
"'so \"#[many 'good' text|]#\" here'", |
| 107 |
)) |
| 108 |
.await?; |
| 109 |
|
| 110 |
|
| 111 |
test(( |
| 112 |
"(so [many {go#[|od]#} text] here)", |
| 113 |
"mi{", |
| 114 |
"(so [many {#[|good]#} text] here)", |
| 115 |
)) |
| 116 |
.await?; |
| 117 |
|
| 118 |
Ok(()) |
| 119 |
} |
| 120 |
|
| 121 |
#[tokio::test(flavor = "multi_thread")] |
| 122 |
async fn surround_inside_pair() -> anyhow::Result<()> { |
| 123 |
|
| 124 |
|
| 125 |
test(("#[(|]#something)", "mim", "#[(|]#something)")).await?; |
| 126 |
|
| 127 |
|
| 128 |
test(("some (#[t|]#ext) here", "mim", "some (#[text|]#) here")).await?; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
test(("some (text#[)|]# here", "mim", "some (#[text|]#) here")).await?; |
| 134 |
|
| 135 |
|
| 136 |
test(("so#[m|]#e (text) here", "mim", "so#[m|]#e (text) here")).await?; |
| 137 |
|
| 138 |
|
| 139 |
test(( |
| 140 |
"(so (many (go#[o|]#d) text) here)", |
| 141 |
"1mim", |
| 142 |
"(so (many (#[good|]#) text) here)", |
| 143 |
)) |
| 144 |
.await?; |
| 145 |
test(( |
| 146 |
"(so (many (go#[o|]#d) text) here)", |
| 147 |
"2mim", |
| 148 |
"(so (#[many (good) text|]#) here)", |
| 149 |
)) |
| 150 |
.await?; |
| 151 |
test(( |
| 152 |
"(so (many (go#[o|]#d) text) here)", |
| 153 |
"3mim", |
| 154 |
"(#[so (many (good) text) here|]#)", |
| 155 |
)) |
| 156 |
.await?; |
| 157 |
|
| 158 |
|
| 159 |
test(( |
| 160 |
"((so)((many) go#[o|]#d (text))(here))", |
| 161 |
"mim", |
| 162 |
"((so)(#[(many) good (text)|]#)(here))", |
| 163 |
)) |
| 164 |
.await?; |
| 165 |
test(( |
| 166 |
"((so)((many) go#[o|]#d (text))(here))", |
| 167 |
"2mim", |
| 168 |
"(#[(so)((many) good (text))(here)|]#)", |
| 169 |
)) |
| 170 |
.await?; |
| 171 |
|
| 172 |
|
| 173 |
test(( |
| 174 |
"(so [many {go#[o|]#d} text] here)", |
| 175 |
"mim", |
| 176 |
"(so [many {#[good|]#} text] here)", |
| 177 |
)) |
| 178 |
.await?; |
| 179 |
test(( |
| 180 |
"(so [many {go#[o|]#d} text] here)", |
| 181 |
"2mim", |
| 182 |
"(so [#[many {good} text|]#] here)", |
| 183 |
)) |
| 184 |
.await?; |
| 185 |
test(( |
| 186 |
"(so [many {go#[o|]#d} text] here)", |
| 187 |
"3mim", |
| 188 |
"(#[so [many {good} text] here|]#)", |
| 189 |
)) |
| 190 |
.await?; |
| 191 |
|
| 192 |
|
| 193 |
test(( |
| 194 |
"(so [many {go#[|od]#} text] here)", |
| 195 |
"mim", |
| 196 |
"(so [many {#[|good]#} text] here)", |
| 197 |
)) |
| 198 |
.await?; |
| 199 |
test(( |
| 200 |
"(so [many {go#[|od]#} text] here)", |
| 201 |
"2mim", |
| 202 |
"(so [#[|many {good} text]#] here)", |
| 203 |
)) |
| 204 |
.await?; |
| 205 |
test(( |
| 206 |
"(so [many {go#[|od]#} text] here)", |
| 207 |
"3mim", |
| 208 |
"(#[|so [many {good} text] here]#)", |
| 209 |
)) |
| 210 |
.await?; |
| 211 |
|
| 212 |
|
| 213 |
test(( |
| 214 |
"(so (many (go#[od) |]#text) here)", |
| 215 |
"mim", |
| 216 |
"(so (#[many (good) text|]#) here)", |
| 217 |
)) |
| 218 |
.await?; |
| 219 |
test(( |
| 220 |
"(so (many#[ (go|]#od) text) here)", |
| 221 |
"mim", |
| 222 |
"(so (#[many (good) text|]#) here)", |
| 223 |
)) |
| 224 |
.await?; |
| 225 |
test(( |
| 226 |
"(so#[ (many (go|]#od) text) here)", |
| 227 |
"mim", |
| 228 |
"(#[so (many (good) text) here|]#)", |
| 229 |
)) |
| 230 |
.await?; |
| 231 |
test(( |
| 232 |
"(so (many (go#[od) text) |]#here)", |
| 233 |
"mim", |
| 234 |
"(#[so (many (good) text) here|]#)", |
| 235 |
)) |
| 236 |
.await?; |
| 237 |
|
| 238 |
|
| 239 |
test(( |
| 240 |
"(so (many (good) text) #[he|]#re\nso (many (good) text) #(|he)#re)", |
| 241 |
"mim", |
| 242 |
"(#[so (many (good) text) here\nso (many (good) text) here|]#)", |
| 243 |
)) |
| 244 |
.await?; |
| 245 |
|
| 246 |
Ok(()) |
| 247 |
} |
| 248 |
|
| 249 |
#[tokio::test(flavor = "multi_thread")] |
| 250 |
async fn surround_around_pair() -> anyhow::Result<()> { |
| 251 |
|
| 252 |
|
| 253 |
test(("#[(|]#something)", "mam", "#[(|]#something)")).await?; |
| 254 |
|
| 255 |
|
| 256 |
test(("some (#[t|]#ext) here", "mam", "some #[(text)|]# here")).await?; |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
test(("some (text#[)|]# here", "mam", "some #[(text)|]# here")).await?; |
| 262 |
|
| 263 |
|
| 264 |
test(("so#[m|]#e (text) here", "mam", "so#[m|]#e (text) here")).await?; |
| 265 |
|
| 266 |
|
| 267 |
test(( |
| 268 |
"(so (many (go#[o|]#d) text) here)", |
| 269 |
"1mam", |
| 270 |
"(so (many #[(good)|]# text) here)", |
| 271 |
)) |
| 272 |
.await?; |
| 273 |
test(( |
| 274 |
"(so (many (go#[o|]#d) text) here)", |
| 275 |
"2mam", |
| 276 |
"(so #[(many (good) text)|]# here)", |
| 277 |
)) |
| 278 |
.await?; |
| 279 |
test(( |
| 280 |
"(so (many (go#[o|]#d) text) here)", |
| 281 |
"3mam", |
| 282 |
"#[(so (many (good) text) here)|]#", |
| 283 |
)) |
| 284 |
.await?; |
| 285 |
|
| 286 |
|
| 287 |
test(( |
| 288 |
"((so)((many) go#[o|]#d (text))(here))", |
| 289 |
"mam", |
| 290 |
"((so)#[((many) good (text))|]#(here))", |
| 291 |
)) |
| 292 |
.await?; |
| 293 |
test(( |
| 294 |
"((so)((many) go#[o|]#d (text))(here))", |
| 295 |
"2mam", |
| 296 |
"#[((so)((many) good (text))(here))|]#", |
| 297 |
)) |
| 298 |
.await?; |
| 299 |
|
| 300 |
|
| 301 |
test(( |
| 302 |
"(so [many {go#[o|]#d} text] here)", |
| 303 |
"mam", |
| 304 |
"(so [many #[{good}|]# text] here)", |
| 305 |
)) |
| 306 |
.await?; |
| 307 |
test(( |
| 308 |
"(so [many {go#[o|]#d} text] here)", |
| 309 |
"2mam", |
| 310 |
"(so #[[many {good} text]|]# here)", |
| 311 |
)) |
| 312 |
.await?; |
| 313 |
test(( |
| 314 |
"(so [many {go#[o|]#d} text] here)", |
| 315 |
"3mam", |
| 316 |
"#[(so [many {good} text] here)|]#", |
| 317 |
)) |
| 318 |
.await?; |
| 319 |
|
| 320 |
|
| 321 |
test(( |
| 322 |
"(so [many {go#[|od]#} text] here)", |
| 323 |
"mam", |
| 324 |
"(so [many #[|{good}]# text] here)", |
| 325 |
)) |
| 326 |
.await?; |
| 327 |
test(( |
| 328 |
"(so [many {go#[|od]#} text] here)", |
| 329 |
"2mam", |
| 330 |
"(so #[|[many {good} text]]# here)", |
| 331 |
)) |
| 332 |
.await?; |
| 333 |
test(( |
| 334 |
"(so [many {go#[|od]#} text] here)", |
| 335 |
"3mam", |
| 336 |
"#[|(so [many {good} text] here)]#", |
| 337 |
)) |
| 338 |
.await?; |
| 339 |
|
| 340 |
|
| 341 |
test(( |
| 342 |
"(so (many (go#[od) |]#text) here)", |
| 343 |
"mam", |
| 344 |
"(so #[(many (good) text)|]# here)", |
| 345 |
)) |
| 346 |
.await?; |
| 347 |
test(( |
| 348 |
"(so (many#[ (go|]#od) text) here)", |
| 349 |
"mam", |
| 350 |
"(so #[(many (good) text)|]# here)", |
| 351 |
)) |
| 352 |
.await?; |
| 353 |
test(( |
| 354 |
"(so#[ (many (go|]#od) text) here)", |
| 355 |
"mam", |
| 356 |
"#[(so (many (good) text) here)|]#", |
| 357 |
)) |
| 358 |
.await?; |
| 359 |
test(( |
| 360 |
"(so (many (go#[od) text) |]#here)", |
| 361 |
"mam", |
| 362 |
"#[(so (many (good) text) here)|]#", |
| 363 |
)) |
| 364 |
.await?; |
| 365 |
|
| 366 |
|
| 367 |
test(( |
| 368 |
"(so (many (good) text) #[he|]#re\nso (many (good) text) #(|he)#re)", |
| 369 |
"mam", |
| 370 |
"#[(so (many (good) text) here\nso (many (good) text) here)|]#", |
| 371 |
)) |
| 372 |
.await?; |
| 373 |
|
| 374 |
Ok(()) |
| 375 |
} |
| 376 |
|
| 377 |
#[tokio::test(flavor = "multi_thread")] |
| 378 |
async fn match_around_closest_ts() -> anyhow::Result<()> { |
| 379 |
test_with_config( |
| 380 |
AppBuilder::new().with_file("foo.rs", None), |
| 381 |
( |
| 382 |
r#"fn main() {testing!{"f#[|oo]#)"};}"#, |
| 383 |
"mam", |
| 384 |
r#"fn main() {testing!{#[|"foo)"]#};}"#, |
| 385 |
), |
| 386 |
) |
| 387 |
.await?; |
| 388 |
|
| 389 |
test_with_config( |
| 390 |
AppBuilder::new().with_file("foo.rs", None), |
| 391 |
( |
| 392 |
r##"fn main() { let _ = ("#[|1]#23", "#(|1)#23"); } "##, |
| 393 |
"3mam", |
| 394 |
r##"fn main() #[|{ let _ = ("123", "123"); }]# "##, |
| 395 |
), |
| 396 |
) |
| 397 |
.await?; |
| 398 |
|
| 399 |
test_with_config( |
| 400 |
AppBuilder::new().with_file("foo.rs", None), |
| 401 |
( |
| 402 |
r##" fn main() { let _ = ("12#[|3", "12]#3"); } "##, |
| 403 |
"1mam", |
| 404 |
r##" fn main() { let _ = #[|("123", "123")]#; } "##, |
| 405 |
), |
| 406 |
) |
| 407 |
.await?; |
| 408 |
|
| 409 |
Ok(()) |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
#[tokio::test(flavor = "multi_thread")] |
| 415 |
async fn cursor_position_newly_opened_file() -> anyhow::Result<()> { |
| 416 |
let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> { |
| 417 |
let file = helpers::temp_file_with_contents(content)?; |
| 418 |
let mut app = helpers::AppBuilder::new() |
| 419 |
.with_file(file.path(), None) |
| 420 |
.build()?; |
| 421 |
|
| 422 |
let (view, doc) = helix_view::current!(app.editor); |
| 423 |
let sel = doc.selection(view.id).clone(); |
| 424 |
assert_eq!(expected_sel, sel); |
| 425 |
|
| 426 |
Ok(()) |
| 427 |
}; |
| 428 |
|
| 429 |
test("foo", Selection::single(0, 1))?; |
| 430 |
test("👨👩👧👦 foo", Selection::single(0, 7))?; |
| 431 |
test("", Selection::single(0, 0))?; |
| 432 |
|
| 433 |
Ok(()) |
| 434 |
} |
| 435 |
|
| 436 |
#[tokio::test(flavor = "multi_thread")] |
| 437 |
async fn cursor_position_append_eof() -> anyhow::Result<()> { |
| 438 |
|
| 439 |
test(("#[foo|]#", "abar<esc>", "#[foobar|]#\n")).await?; |
| 440 |
|
| 441 |
|
| 442 |
test(("#[|foo]#", "abar<esc>", "#[foobar|]#\n")).await?; |
| 443 |
|
| 444 |
Ok(()) |
| 445 |
} |
| 446 |
|
| 447 |
#[tokio::test(flavor = "multi_thread")] |
| 448 |
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> { |
| 449 |
test_with_config( |
| 450 |
AppBuilder::new().with_file("foo.rs", None), |
| 451 |
( |
| 452 |
indoc! {"\ |
| 453 |
#[/|]#// Increments |
| 454 |
fn inc(x: usize) -> usize { x + 1 } |
| 455 |
/// Decrements |
| 456 |
fn dec(x: usize) -> usize { x - 1 } |
| 457 |
"}, |
| 458 |
"]fv]f", |
| 459 |
indoc! {"\ |
| 460 |
/// Increments |
| 461 |
#[fn inc(x: usize) -> usize { x + 1 } |
| 462 |
/// Decrements |
| 463 |
fn dec(x: usize) -> usize { x - 1 }|]# |
| 464 |
"}, |
| 465 |
), |
| 466 |
) |
| 467 |
.await?; |
| 468 |
|
| 469 |
Ok(()) |
| 470 |
} |
| 471 |
|
| 472 |
#[tokio::test(flavor = "multi_thread")] |
| 473 |
async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> { |
| 474 |
test_with_config( |
| 475 |
AppBuilder::new().with_file("foo.rs", None), |
| 476 |
( |
| 477 |
indoc! {"\ |
| 478 |
/// Increments |
| 479 |
#[fn inc(x: usize) -> usize { x + 1 } |
| 480 |
/// Decrements |
| 481 |
fn dec(x: usize) -> usize { x - 1 }|]# |
| 482 |
"}, |
| 483 |
"v[f", |
| 484 |
indoc! {"\ |
| 485 |
/// Increments |
| 486 |
#[fn inc(x: usize) -> usize { x + 1 }|]# |
| 487 |
/// Decrements |
| 488 |
fn dec(x: usize) -> usize { x - 1 } |
| 489 |
"}, |
| 490 |
), |
| 491 |
) |
| 492 |
.await?; |
| 493 |
|
| 494 |
Ok(()) |
| 495 |
} |
| 496 |
|
| 497 |
#[tokio::test(flavor = "multi_thread")] |
| 498 |
async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> { |
| 499 |
|
| 500 |
test_with_config( |
| 501 |
AppBuilder::new().with_file("foo.rs", None), |
| 502 |
( |
| 503 |
indoc! {"\ |
| 504 |
/// Increments |
| 505 |
fn inc(x: usize) -> usize { x + 1 } |
| 506 |
/// Decrements |
| 507 |
fn dec(x: usize) -> usize { x - 1 } |
| 508 |
/// Identity |
| 509 |
#[fn ident(x: usize) -> usize { x }|]# |
| 510 |
"}, |
| 511 |
"v[f", |
| 512 |
indoc! {"\ |
| 513 |
/// Increments |
| 514 |
fn inc(x: usize) -> usize { x + 1 } |
| 515 |
/// Decrements |
| 516 |
#[|fn dec(x: usize) -> usize { x - 1 } |
| 517 |
/// Identity |
| 518 |
]#fn ident(x: usize) -> usize { x } |
| 519 |
"}, |
| 520 |
), |
| 521 |
) |
| 522 |
.await?; |
| 523 |
|
| 524 |
test_with_config( |
| 525 |
AppBuilder::new().with_file("foo.rs", None), |
| 526 |
( |
| 527 |
indoc! {"\ |
| 528 |
/// Increments |
| 529 |
fn inc(x: usize) -> usize { x + 1 } |
| 530 |
/// Decrements |
| 531 |
fn dec(x: usize) -> usize { x - 1 } |
| 532 |
/// Identity |
| 533 |
#[fn ident(x: usize) -> usize { x }|]# |
| 534 |
"}, |
| 535 |
"v[f[f", |
| 536 |
indoc! {"\ |
| 537 |
/// Increments |
| 538 |
#[|fn inc(x: usize) -> usize { x + 1 } |
| 539 |
/// Decrements |
| 540 |
fn dec(x: usize) -> usize { x - 1 } |
| 541 |
/// Identity |
| 542 |
]#fn ident(x: usize) -> usize { x } |
| 543 |
"}, |
| 544 |
), |
| 545 |
) |
| 546 |
.await?; |
| 547 |
|
| 548 |
Ok(()) |
| 549 |
} |
| 550 |
|
| 551 |
#[tokio::test(flavor = "multi_thread")] |
| 552 |
async fn find_char() -> anyhow::Result<()> { |
| 553 |
test(("he#[l|]#lo\nhello", "fl", "he#[ll|]#o\nhello")).await?; |
| 554 |
test(("hel#[l|]#o\nhello", "fl", "hel#[lo\nhel|]#lo")).await?; |
| 555 |
test(("hel#[l|]#o\nhello", "fx", "hel#[l|]#o\nhello")).await?; |
| 556 |
test(("he#[l|]#lo\nhello", "2fl", "he#[llo\nhel|]#lo")).await?; |
| 557 |
test(("#[h|]#ello\nhello", "9fl", "#[h|]#ello\nhello")).await?; |
| 558 |
|
| 559 |
test(("h#[e|]#llo\nhello", "tl", "h#[el|]#lo\nhello")).await?; |
| 560 |
test(("he#[l|]#lo\nhello", "tl", "he#[llo\nhe|]#llo")).await?; |
| 561 |
test(("hel#[l|]#o\nhello", "tl", "hel#[lo\nhe|]#llo")).await?; |
| 562 |
test(("hel#[l|]#o\nhello", "tx", "hel#[l|]#o\nhello")).await?; |
| 563 |
test(("he#[l|]#lo\nhello", "2tl", "he#[llo\nhel|]#lo")).await?; |
| 564 |
test(("#[h|]#ello\nhello", "9tl", "#[h|]#ello\nhello")).await?; |
| 565 |
|
| 566 |
test(("hello\nhel#[l|]#o", "Fl", "hello\nhe#[|ll]#o")).await?; |
| 567 |
test(("hello\nhe#[l|]#lo", "Fl", "hel#[|lo\nhel]#lo")).await?; |
| 568 |
test(("hello\n#[h|]#ello", "Fx", "hello\n#[h|]#ello")).await?; |
| 569 |
test(("hello\nhel#[l|]#o", "2Fl", "hel#[|lo\nhell]#o")).await?; |
| 570 |
test(("hello\nhell#[o|]#", "9Fl", "hello\nhell#[o|]#")).await?; |
| 571 |
|
| 572 |
test(("hello\nhell#[o|]#", "Tl", "hello\nhel#[|lo]#")).await?; |
| 573 |
test(("hello\nhel#[l|]#o", "Tl", "hell#[|o\nhell]#o")).await?; |
| 574 |
test(("hello\nhe#[l|]#lo", "Tl", "hell#[|o\nhel]#lo")).await?; |
| 575 |
test(("hello\n#[h|]#ello", "Tx", "hello\n#[h|]#ello")).await?; |
| 576 |
test(("hello\nhel#[l|]#o", "2Tl", "hel#[|lo\nhell]#o")).await?; |
| 577 |
test(("hello\nhell#[o|]#", "9Tl", "hello\nhell#[o|]#")).await?; |
| 578 |
|
| 579 |
Ok(()) |
| 580 |
} |
| 581 |
|
| 582 |
#[tokio::test(flavor = "multi_thread")] |
| 583 |
async fn find_char_line_ending() -> anyhow::Result<()> { |
| 584 |
test(("on#[e|]#\ntwo\n", "f<ret>", "on#[e\n|]#two\n")).await?; |
| 585 |
test(("one#[\n|]#two\n", "f<ret>", "one#[\ntwo\n|]#")).await?; |
| 586 |
test(("one\n#[t|]#wo\n", "f<ret>", "one\n#[two\n|]#")).await?; |
| 587 |
test(("one#[\n|]#", "f<ret>", "one#[\n|]#")).await?; |
| 588 |
test(("#[o|]#ne\ntwo\n", "2f<ret>", "#[one\ntwo\n|]#")).await?; |
| 589 |
test(("#[o|]#ne\ntwo\n", "9f<ret>", "#[o|]#ne\ntwo\n")).await?; |
| 590 |
|
| 591 |
test(("o#[n|]#e\ntwo\n", "t<ret>", "o#[ne|]#\ntwo\n")).await?; |
| 592 |
test(("on#[e|]#\ntwo\n", "t<ret>", "on#[e\ntwo|]#\n")).await?; |
| 593 |
test(("one#[\n|]#two\n", "t<ret>", "one#[\ntwo|]#\n")).await?; |
| 594 |
test(("one#[\n|]#", "t<ret>", "one#[\n|]#")).await?; |
| 595 |
test(("on#[e|]#\n", "t<ret>", "on#[e|]#\n")).await?; |
| 596 |
test(("#[o|]#ne\ntwo\n", "2t<ret>", "#[one\ntwo|]#\n")).await?; |
| 597 |
test(("#[o|]#ne\ntwo\n", "9t<ret>", "#[o|]#ne\ntwo\n")).await?; |
| 598 |
|
| 599 |
test(("one\ntwo\n#[t|]#hree\n", "F<ret>", "one\ntwo#[|\nt]#hree\n")).await?; |
| 600 |
test(("one\ntwo#[\n|]#three\n", "F<ret>", "one#[|\ntwo\n]#three\n")).await?; |
| 601 |
test(("one\ntw#[o|]#\nthree\n", "F<ret>", "one#[|\ntwo]#\nthree\n")).await?; |
| 602 |
test(("o#[n|]#e\n", "F<ret>", "o#[n|]#e\n")).await?; |
| 603 |
test(("#[o|]#ne\n", "F<ret>", "#[o|]#ne\n")).await?; |
| 604 |
test(("one\ntwo\nth#[r|]#ee\n", "2F\n", "one#[|\ntwo\nthr]#ee\n")).await?; |
| 605 |
test(("one\ntwo\nth#[r|]#ee\n", "9F\n", "one\ntwo\nth#[r|]#ee\n")).await?; |
| 606 |
|
| 607 |
test(("one\ntwo\nth#[r|]#ee\n", "T<ret>", "one\ntwo\n#[|thr]#ee\n")).await?; |
| 608 |
test(("one\ntwo\n#[t|]#hree\n", "T<ret>", "one\n#[|two\nt]#hree\n")).await?; |
| 609 |
test(("one\ntwo#[\n|]#three\n", "T<ret>", "one\n#[|two\n]#three\n")).await?; |
| 610 |
test(("o#[n|]#e\n", "T<ret>", "o#[n|]#e\n")).await?; |
| 611 |
test(("#[o|]#ne\n", "T<ret>", "#[o|]#ne\n")).await?; |
| 612 |
test(("one\ntwo\nth#[r|]#ee\n", "2T\n", "one\n#[|two\nthr]#ee\n")).await?; |
| 613 |
test(("one\ntwo\nth#[r|]#ee\n", "9T\n", "one\ntwo\nth#[r|]#ee\n")).await?; |
| 614 |
|
| 615 |
test(( |
| 616 |
indoc! { |
| 617 |
"\ |
| 618 |
one |
| 619 |
#[|t]#wo |
| 620 |
three" |
| 621 |
}, |
| 622 |
"T<ret>gll2f<ret>", |
| 623 |
indoc! { |
| 624 |
"\ |
| 625 |
one |
| 626 |
two#[ |
| 627 |
|]#three" |
| 628 |
}, |
| 629 |
)) |
| 630 |
.await?; |
| 631 |
|
| 632 |
test(( |
| 633 |
indoc! { |
| 634 |
"\ |
| 635 |
#[|o]#ne |
| 636 |
two |
| 637 |
three" |
| 638 |
}, |
| 639 |
"f<ret>2t<ret>ghT<ret>F<ret>", |
| 640 |
indoc! { |
| 641 |
"\ |
| 642 |
one#[| |
| 643 |
t]#wo |
| 644 |
three" |
| 645 |
}, |
| 646 |
)) |
| 647 |
.await?; |
| 648 |
|
| 649 |
Ok(()) |
| 650 |
} |
| 651 |
|
| 652 |
#[tokio::test(flavor = "multi_thread")] |
| 653 |
async fn repeat_find_char() -> anyhow::Result<()> { |
| 654 |
test(( |
| 655 |
indoc! { |
| 656 |
"\ |
| 657 |
#[o|]#ne two |
| 658 |
one two" |
| 659 |
}, |
| 660 |
"ft<A-.>", |
| 661 |
indoc! { |
| 662 |
"\ |
| 663 |
one #[two |
| 664 |
one t|]#wo" |
| 665 |
}, |
| 666 |
)) |
| 667 |
.await?; |
| 668 |
|
| 669 |
test(( |
| 670 |
indoc! { |
| 671 |
"\ |
| 672 |
#[o|]#ne two |
| 673 |
one two |
| 674 |
" |
| 675 |
}, |
| 676 |
"f<ret><A-.>", |
| 677 |
indoc! { |
| 678 |
"\ |
| 679 |
one two#[ |
| 680 |
one two |
| 681 |
|]#" |
| 682 |
}, |
| 683 |
)) |
| 684 |
.await?; |
| 685 |
|
| 686 |
test(( |
| 687 |
indoc! { |
| 688 |
"\ |
| 689 |
#[o|]#ne two |
| 690 |
one two |
| 691 |
" |
| 692 |
}, |
| 693 |
"ftf<ret><A-.>", |
| 694 |
indoc! { |
| 695 |
"\ |
| 696 |
one two#[ |
| 697 |
one two |
| 698 |
|]#" |
| 699 |
}, |
| 700 |
)) |
| 701 |
.await?; |
| 702 |
|
| 703 |
Ok(()) |
| 704 |
} |
| 705 |
|
| 706 |
#[tokio::test(flavor = "multi_thread")] |
| 707 |
async fn test_surround_replace() -> anyhow::Result<()> { |
| 708 |
test(( |
| 709 |
indoc! {"\ |
| 710 |
(#[|a]#) |
| 711 |
"}, |
| 712 |
"mrm{", |
| 713 |
indoc! {"\ |
| 714 |
{#[|a]#} |
| 715 |
"}, |
| 716 |
)) |
| 717 |
.await?; |
| 718 |
|
| 719 |
test(( |
| 720 |
indoc! {"\ |
| 721 |
(#[a|]#) |
| 722 |
"}, |
| 723 |
"mrm{", |
| 724 |
indoc! {"\ |
| 725 |
{#[a|]#} |
| 726 |
"}, |
| 727 |
)) |
| 728 |
.await?; |
| 729 |
|
| 730 |
test(( |
| 731 |
indoc! {"\ |
| 732 |
{{ |
| 733 |
|
| 734 |
#(}|)# |
| 735 |
#[}|]# |
| 736 |
"}, |
| 737 |
"mrm)", |
| 738 |
indoc! {"\ |
| 739 |
(( |
| 740 |
|
| 741 |
#()|)# |
| 742 |
#[)|]# |
| 743 |
"}, |
| 744 |
)) |
| 745 |
.await?; |
| 746 |
|
| 747 |
Ok(()) |
| 748 |
} |
| 749 |
|
| 750 |
#[tokio::test(flavor = "multi_thread")] |
| 751 |
async fn test_surround_delete() -> anyhow::Result<()> { |
| 752 |
test(( |
| 753 |
indoc! {"\ |
| 754 |
(#[|a]#) |
| 755 |
"}, |
| 756 |
"mdm", |
| 757 |
indoc! {"\ |
| 758 |
#[|a]# |
| 759 |
"}, |
| 760 |
)) |
| 761 |
.await?; |
| 762 |
|
| 763 |
test(( |
| 764 |
indoc! {"\ |
| 765 |
(#[a|]#) |
| 766 |
"}, |
| 767 |
"mdm", |
| 768 |
indoc! {"\ |
| 769 |
#[a|]# |
| 770 |
"}, |
| 771 |
)) |
| 772 |
.await?; |
| 773 |
|
| 774 |
test(( |
| 775 |
indoc! {"\ |
| 776 |
{{ |
| 777 |
|
| 778 |
#(}|)# |
| 779 |
#[}|]# |
| 780 |
"}, |
| 781 |
"mdm", |
| 782 |
"\n\n#(\n|)##[\n|]#", |
| 783 |
)) |
| 784 |
.await?; |
| 785 |
|
| 786 |
Ok(()) |
| 787 |
} |
| 788 |
|
| 789 |
#[tokio::test(flavor = "multi_thread")] |
| 790 |
async fn tree_sitter_motions_work_across_injections() -> anyhow::Result<()> { |
| 791 |
test_with_config( |
| 792 |
AppBuilder::new().with_file("foo.html", None), |
| 793 |
( |
| 794 |
"<script>let #[|x]# = 1;</script>", |
| 795 |
"<A-o>", |
| 796 |
"<script>let #[|x = 1]#;</script>", |
| 797 |
), |
| 798 |
) |
| 799 |
.await?; |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
test_with_config( |
| 804 |
AppBuilder::new().with_file("foo.html", None), |
| 805 |
( |
| 806 |
"<script>#[|let x = 1;]#</script>", |
| 807 |
"<A-o>", |
| 808 |
"#[|<script>let x = 1;</script>]#", |
| 809 |
), |
| 810 |
) |
| 811 |
.await?; |
| 812 |
|
| 813 |
test_with_config( |
| 814 |
AppBuilder::new().with_file("foo.html", None), |
| 815 |
( |
| 816 |
"<script>let #[|x = 1]#;</script>", |
| 817 |
"<A-i>", |
| 818 |
"<script>let #[|x]# = 1;</script>", |
| 819 |
), |
| 820 |
) |
| 821 |
.await?; |
| 822 |
|
| 823 |
test_with_config( |
| 824 |
AppBuilder::new().with_file("foo.html", None), |
| 825 |
( |
| 826 |
"<script>let #[|x]# = 1;</script>", |
| 827 |
"<A-n>", |
| 828 |
"<script>let x #[=|]# 1;</script>", |
| 829 |
), |
| 830 |
) |
| 831 |
.await?; |
| 832 |
|
| 833 |
test_with_config( |
| 834 |
AppBuilder::new().with_file("foo.html", None), |
| 835 |
( |
| 836 |
"<script>let #[|x]# = 1;</script>", |
| 837 |
"<A-p>", |
| 838 |
"<script>#[|let]# x = 1;</script>", |
| 839 |
), |
| 840 |
) |
| 841 |
.await?; |
| 842 |
|
| 843 |
Ok(()) |
| 844 |
} |