1" Test for the search command 2 3source shared.vim 4source screendump.vim 5source check.vim 6 7func Test_search_cmdline() 8 CheckOption incsearch 9 10 " need to disable char_avail, 11 " so that expansion of commandline works 12 call test_override("char_avail", 1) 13 new 14 call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) 15 " Test 1 16 " CTRL-N / CTRL-P skips through the previous search history 17 set noincsearch 18 :1 19 call feedkeys("/foobar\<cr>", 'tx') 20 call feedkeys("/the\<cr>", 'tx') 21 call assert_equal('the', @/) 22 call feedkeys("/thes\<C-P>\<C-P>\<cr>", 'tx') 23 call assert_equal('foobar', @/) 24 25 " Test 2 26 " Ctrl-G goes from one match to the next 27 " until the end of the buffer 28 set incsearch nowrapscan 29 :1 30 " first match 31 call feedkeys("/the\<cr>", 'tx') 32 call assert_equal(' 2 these', getline('.')) 33 :1 34 " second match 35 call feedkeys("/the\<C-G>\<cr>", 'tx') 36 call assert_equal(' 3 the', getline('.')) 37 call assert_equal([0, 0, 0, 0], getpos('"')) 38 :1 39 " third match 40 call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') 41 call assert_equal(' 4 their', getline('.')) 42 :1 43 " fourth match 44 call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') 45 call assert_equal(' 5 there', getline('.')) 46 :1 47 " fifth match 48 call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') 49 call assert_equal(' 6 their', getline('.')) 50 :1 51 " sixth match 52 call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') 53 call assert_equal(' 7 the', getline('.')) 54 :1 55 " seventh match 56 call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') 57 call assert_equal(' 8 them', getline('.')) 58 :1 59 " eighth match 60 call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') 61 call assert_equal(' 9 these', getline('.')) 62 :1 63 " no further match 64 call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') 65 call assert_equal(' 9 these', getline('.')) 66 call assert_equal([0, 0, 0, 0], getpos('"')) 67 68 " Test 3 69 " Ctrl-G goes from one match to the next 70 " and continues back at the top 71 set incsearch wrapscan 72 :1 73 " first match 74 call feedkeys("/the\<cr>", 'tx') 75 call assert_equal(' 2 these', getline('.')) 76 :1 77 " second match 78 call feedkeys("/the\<C-G>\<cr>", 'tx') 79 call assert_equal(' 3 the', getline('.')) 80 :1 81 " third match 82 call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') 83 call assert_equal(' 4 their', getline('.')) 84 :1 85 " fourth match 86 call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') 87 call assert_equal(' 5 there', getline('.')) 88 :1 89 " fifth match 90 call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') 91 call assert_equal(' 6 their', getline('.')) 92 :1 93 " sixth match 94 call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') 95 call assert_equal(' 7 the', getline('.')) 96 :1 97 " seventh match 98 call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') 99 call assert_equal(' 8 them', getline('.')) 100 :1 101 " eighth match 102 call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') 103 call assert_equal(' 9 these', getline('.')) 104 :1 105 " back at first match 106 call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') 107 call assert_equal(' 2 these', getline('.')) 108 109 " Test 4 110 " CTRL-T goes to the previous match 111 set incsearch nowrapscan 112 $ 113 " first match 114 call feedkeys("?the\<cr>", 'tx') 115 call assert_equal(' 9 these', getline('.')) 116 $ 117 " first match 118 call feedkeys("?the\<C-G>\<cr>", 'tx') 119 call assert_equal(' 9 these', getline('.')) 120 $ 121 " second match 122 call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') 123 call assert_equal(' 8 them', getline('.')) 124 $ 125 " last match 126 call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') 127 call assert_equal(' 2 these', getline('.')) 128 $ 129 " last match 130 call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') 131 call assert_equal(' 2 these', getline('.')) 132 133 " Test 5 134 " CTRL-T goes to the previous match 135 set incsearch wrapscan 136 $ 137 " first match 138 call feedkeys("?the\<cr>", 'tx') 139 call assert_equal(' 9 these', getline('.')) 140 $ 141 " first match at the top 142 call feedkeys("?the\<C-G>\<cr>", 'tx') 143 call assert_equal(' 2 these', getline('.')) 144 $ 145 " second match 146 call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') 147 call assert_equal(' 8 them', getline('.')) 148 $ 149 " last match 150 call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') 151 call assert_equal(' 2 these', getline('.')) 152 $ 153 " back at the bottom of the buffer 154 call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') 155 call assert_equal(' 9 these', getline('.')) 156 157 " Test 6 158 " CTRL-L adds to the search pattern 159 set incsearch wrapscan 160 1 161 " first match 162 call feedkeys("/the\<c-l>\<cr>", 'tx') 163 call assert_equal(' 2 these', getline('.')) 164 1 165 " go to next match of 'thes' 166 call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx') 167 call assert_equal(' 9 these', getline('.')) 168 1 169 " wrap around 170 call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') 171 call assert_equal(' 2 these', getline('.')) 172 1 173 " wrap around 174 set nowrapscan 175 call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') 176 call assert_equal(' 9 these', getline('.')) 177 178 " Test 7 179 " <bs> remove from match, but stay at current match 180 set incsearch wrapscan 181 1 182 " first match 183 call feedkeys("/thei\<cr>", 'tx') 184 call assert_equal(' 4 their', getline('.')) 185 1 186 " delete one char, add another 187 call feedkeys("/thei\<bs>s\<cr>", 'tx') 188 call assert_equal(' 2 these', getline('.')) 189 1 190 " delete one char, add another, go to previous match, add one char 191 call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx') 192 call assert_equal(' 9 these', getline('.')) 193 1 194 " delete all chars, start from the beginning again 195 call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx') 196 call assert_equal(' 3 the', getline('.')) 197 198 " clean up 199 call test_override("char_avail", 0) 200 bw! 201endfunc 202 203func Test_search_cmdline2() 204 CheckOption incsearch 205 206 " need to disable char_avail, 207 " so that expansion of commandline works 208 call test_override("char_avail", 1) 209 new 210 call setline(1, [' 1', ' 2 these', ' 3 the theother']) 211 " Test 1 212 " Ctrl-T goes correctly back and forth 213 set incsearch 214 1 215 " first match 216 call feedkeys("/the\<cr>", 'tx') 217 call assert_equal(' 2 these', getline('.')) 218 1 219 " go to next match (on next line) 220 call feedkeys("/the\<C-G>\<cr>", 'tx') 221 call assert_equal(' 3 the theother', getline('.')) 222 1 223 " go to next match (still on line 3) 224 call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx') 225 call assert_equal(' 3 the theother', getline('.')) 226 1 227 " go to next match (still on line 3) 228 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx') 229 call assert_equal(' 3 the theother', getline('.')) 230 1 231 " go to previous match (on line 3) 232 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<cr>", 'tx') 233 call assert_equal(' 3 the theother', getline('.')) 234 1 235 " go to previous match (on line 3) 236 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<cr>", 'tx') 237 call assert_equal(' 3 the theother', getline('.')) 238 1 239 " go to previous match (on line 2) 240 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx') 241 call assert_equal(' 2 these', getline('.')) 242 1 243 " go to previous match (on line 2) 244 call feedkeys("/the\<C-G>\<C-R>\<C-W>\<cr>", 'tx') 245 call assert_equal('theother', @/) 246 247 " Test 2: keep the view, 248 " after deleting a character from the search cmd 249 call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) 250 resize 5 251 1 252 call feedkeys("/foo\<bs>\<cr>", 'tx') 253 redraw 254 call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) 255 256 " remove all history entries 257 for i in range(11) 258 call histdel('/') 259 endfor 260 261 " Test 3: reset the view, 262 " after deleting all characters from the search cmd 263 norm! 1gg0 264 " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>", 265 " nor "/foo\<c-u>\<cr>" works to delete the commandline. 266 " In that case Vim should return "E35 no previous regular expression", 267 " but it looks like Vim still sees /foo and therefore the test fails. 268 " Therefore, disabling this test 269 "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35:') 270 "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) 271 272 " clean up 273 set noincsearch 274 call test_override("char_avail", 0) 275 bw! 276endfunc 277 278func Test_use_sub_pat() 279 split 280 let @/ = '' 281 func X() 282 s/^/a/ 283 / 284 endfunc 285 call X() 286 bwipe! 287endfunc 288 289func Test_searchpair() 290 new 291 call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) 292 293 " should not give an error for using "42" 294 call assert_equal(0, searchpair('a', 'b', 'c', '', 42)) 295 296 4 297 call assert_equal(3, searchpair('\[', '', ']', 'bW')) 298 call assert_equal([0, 3, 2, 0], getpos('.')) 299 4 300 call assert_equal(2, searchpair('\[', '', ']', 'bWr')) 301 call assert_equal([0, 2, 6, 0], getpos('.')) 302 4 303 call assert_equal(1, searchpair('\[', '', ']', 'bWm')) 304 call assert_equal([0, 3, 2, 0], getpos('.')) 305 4|norm ^ 306 call assert_equal(5, searchpair('\[', '', ']', 'Wn')) 307 call assert_equal([0, 4, 2, 0], getpos('.')) 308 4 309 call assert_equal(2, searchpair('\[', '', ']', 'bW', 310 \ 'getline(".") =~ "^\\s*\["')) 311 call assert_equal([0, 2, 6, 0], getpos('.')) 312 set nomagic 313 4 314 call assert_equal(3, searchpair('\[', '', ']', 'bW')) 315 call assert_equal([0, 3, 2, 0], getpos('.')) 316 set magic 317 4|norm ^ 318 call assert_equal(0, searchpair('{', '', '}', 'bW')) 319 call assert_equal([0, 4, 2, 0], getpos('.')) 320 321 %d 322 call setline(1, ['if 1', ' if 2', ' else', ' endif 2', 'endif 1']) 323 324 /\<if 1 325 call assert_equal(5, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W')) 326 call assert_equal([0, 5, 1, 0], getpos('.')) 327 /\<if 2 328 call assert_equal(3, searchpair('\<if\>', '\<else\>', '\<endif\>', 'W')) 329 call assert_equal([0, 3, 3, 0], getpos('.')) 330 331 q! 332endfunc 333 334func Test_searchpairpos() 335 new 336 call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) 337 338 4 339 call assert_equal([3, 2], searchpairpos('\[', '', ']', 'bW')) 340 call assert_equal([0, 3, 2, 0], getpos('.')) 341 4 342 call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bWr')) 343 call assert_equal([0, 2, 6, 0], getpos('.')) 344 4|norm ^ 345 call assert_equal([5, 2], searchpairpos('\[', '', ']', 'Wn')) 346 call assert_equal([0, 4, 2, 0], getpos('.')) 347 4 348 call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bW', 349 \ 'getline(".") =~ "^\\s*\["')) 350 call assert_equal([0, 2, 6, 0], getpos('.')) 351 4 352 call assert_equal([2, 6], searchpairpos('\[', '', ']', 'bWr')) 353 call assert_equal([0, 2, 6, 0], getpos('.')) 354 set nomagic 355 4 356 call assert_equal([3, 2], searchpairpos('\[', '', ']', 'bW')) 357 call assert_equal([0, 3, 2, 0], getpos('.')) 358 set magic 359 4|norm ^ 360 call assert_equal([0, 0], searchpairpos('{', '', '}', 'bW')) 361 call assert_equal([0, 4, 2, 0], getpos('.')) 362 363 %d 364 call setline(1, ['if 1', ' if 2', ' else', ' endif 2', 'endif 1']) 365 /\<if 1 366 call assert_equal([5, 1], searchpairpos('\<if\>', '\<else\>', '\<endif\>', 'W')) 367 call assert_equal([0, 5, 1, 0], getpos('.')) 368 /\<if 2 369 call assert_equal([3, 3], searchpairpos('\<if\>', '\<else\>', '\<endif\>', 'W')) 370 call assert_equal([0, 3, 3, 0], getpos('.')) 371 372 q! 373endfunc 374 375func Test_searchpair_errors() 376 call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') 377 call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') 378 call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') 379 call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') 380 call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') 381 call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') 382 call assert_fails("call searchpair('start', 'middle', 'end', 'e')", 'E475: Invalid argument: e') 383 call assert_fails("call searchpair('start', 'middle', 'end', 'sn')", 'E475: Invalid argument: sn') 384endfunc 385 386func Test_searchpairpos_errors() 387 call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') 388 call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') 389 call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') 390 call assert_fails("call searchpairpos('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') 391 call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') 392 call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') 393 call assert_fails("call searchpairpos('start', 'middle', 'end', 'e')", 'E475: Invalid argument: e') 394 call assert_fails("call searchpairpos('start', 'middle', 'end', 'sn')", 'E475: Invalid argument: sn') 395endfunc 396 397func Test_searchpair_skip() 398 func Zero() 399 return 0 400 endfunc 401 func Partial(x) 402 return a:x 403 endfunc 404 new 405 call setline(1, ['{', 'foo', 'foo', 'foo', '}']) 406 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '')) 407 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0')) 408 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0})) 409 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero'))) 410 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0]))) 411 bw! 412endfunc 413 414func Test_searchpair_leak() 415 new 416 call setline(1, 'if one else another endif') 417 418 " The error in the skip expression caused memory to leak. 419 call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:') 420 421 bwipe! 422endfunc 423 424func Test_searchc() 425 " These commands used to cause memory overflow in searchc(). 426 new 427 norm ixx 428 exe "norm 0t\u93cf" 429 bw! 430endfunc 431 432func Cmdline3_prep() 433 " need to disable char_avail, 434 " so that expansion of commandline works 435 call test_override("char_avail", 1) 436 new 437 call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) 438 set incsearch 439endfunc 440 441func Incsearch_cleanup() 442 set noincsearch 443 call test_override("char_avail", 0) 444 bw! 445endfunc 446 447func Test_search_cmdline3() 448 CheckOption incsearch 449 450 call Cmdline3_prep() 451 1 452 " first match 453 call feedkeys("/the\<c-l>\<cr>", 'tx') 454 call assert_equal(' 2 the~e', getline('.')) 455 456 call Incsearch_cleanup() 457endfunc 458 459func Test_search_cmdline3s() 460 CheckOption incsearch 461 462 call Cmdline3_prep() 463 1 464 call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx') 465 call assert_equal(' 2 xxxe', getline('.')) 466 undo 467 call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx') 468 call assert_equal(' 2 xxxe', getline('.')) 469 undo 470 call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx') 471 call assert_equal(' 2 xxxe', getline('.')) 472 undo 473 call feedkeys(":%smagic/the.e/xxx\<cr>", 'tx') 474 call assert_equal(' 2 xxx', getline('.')) 475 undo 476 call assert_fails(":%snomagic/the.e/xxx\<cr>", 'E486:') 477 " 478 call feedkeys(":%snomagic/the\\.e/xxx\<cr>", 'tx') 479 call assert_equal(' 2 xxx', getline('.')) 480 481 call Incsearch_cleanup() 482endfunc 483 484func Test_search_cmdline3g() 485 CheckOption incsearch 486 487 call Cmdline3_prep() 488 1 489 call feedkeys(":g/the\<c-l>/d\<cr>", 'tx') 490 call assert_equal(' 3 the theother', getline(2)) 491 undo 492 call feedkeys(":global/the\<c-l>/d\<cr>", 'tx') 493 call assert_equal(' 3 the theother', getline(2)) 494 undo 495 call feedkeys(":g!/the\<c-l>/d\<cr>", 'tx') 496 call assert_equal(1, line('$')) 497 call assert_equal(' 2 the~e', getline(1)) 498 undo 499 call feedkeys(":global!/the\<c-l>/d\<cr>", 'tx') 500 call assert_equal(1, line('$')) 501 call assert_equal(' 2 the~e', getline(1)) 502 503 call Incsearch_cleanup() 504endfunc 505 506func Test_search_cmdline3v() 507 CheckOption incsearch 508 509 call Cmdline3_prep() 510 1 511 call feedkeys(":v/the\<c-l>/d\<cr>", 'tx') 512 call assert_equal(1, line('$')) 513 call assert_equal(' 2 the~e', getline(1)) 514 undo 515 call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx') 516 call assert_equal(1, line('$')) 517 call assert_equal(' 2 the~e', getline(1)) 518 519 call Incsearch_cleanup() 520endfunc 521 522func Test_search_cmdline4() 523 CheckOption incsearch 524 525 " need to disable char_avail, 526 " so that expansion of commandline works 527 call test_override("char_avail", 1) 528 new 529 call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) 530 set incsearch 531 $ 532 call feedkeys("?the\<c-g>\<cr>", 'tx') 533 call assert_equal(' 3 the third', getline('.')) 534 $ 535 call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') 536 call assert_equal(' 1 the first', getline('.')) 537 $ 538 call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') 539 call assert_equal(' 2 the second', getline('.')) 540 $ 541 call feedkeys("?the\<c-t>\<cr>", 'tx') 542 call assert_equal(' 1 the first', getline('.')) 543 $ 544 call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') 545 call assert_equal(' 3 the third', getline('.')) 546 $ 547 call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') 548 call assert_equal(' 2 the second', getline('.')) 549 " clean up 550 set noincsearch 551 call test_override("char_avail", 0) 552 bw! 553endfunc 554 555func Test_search_cmdline5() 556 CheckOption incsearch 557 558 " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work 559 " regardless char_avail. 560 new 561 call setline(1, [' 1 the first', ' 2 the second', ' 3 the third', '']) 562 set incsearch 563 1 564 call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') 565 call assert_equal(' 3 the third', getline('.')) 566 $ 567 call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') 568 call assert_equal(' 1 the first', getline('.')) 569 " clean up 570 set noincsearch 571 bw! 572endfunc 573 574func Test_search_cmdline6() 575 " Test that consecutive matches 576 " are caught by <c-g>/<c-t> 577 CheckOption incsearch 578 579 " need to disable char_avail, 580 " so that expansion of commandline works 581 call test_override("char_avail", 1) 582 new 583 call setline(1, [' bbvimb', '']) 584 set incsearch 585 " first match 586 norm! gg0 587 call feedkeys("/b\<cr>", 'tx') 588 call assert_equal([0,1,2,0], getpos('.')) 589 " second match 590 norm! gg0 591 call feedkeys("/b\<c-g>\<cr>", 'tx') 592 call assert_equal([0,1,3,0], getpos('.')) 593 " third match 594 norm! gg0 595 call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') 596 call assert_equal([0,1,7,0], getpos('.')) 597 " first match again 598 norm! gg0 599 call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') 600 call assert_equal([0,1,2,0], getpos('.')) 601 set nowrapscan 602 " last match 603 norm! gg0 604 call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') 605 call assert_equal([0,1,7,0], getpos('.')) 606 " clean up 607 set wrapscan&vim 608 set noincsearch 609 call test_override("char_avail", 0) 610 bw! 611endfunc 612 613func Test_search_cmdline7() 614 " Test that pressing <c-g> in an empty command line 615 " does not move the cursor 616 CheckOption incsearch 617 618 " need to disable char_avail, 619 " so that expansion of commandline works 620 call test_override("char_avail", 1) 621 new 622 let @/ = 'b' 623 call setline(1, [' bbvimb', '']) 624 set incsearch 625 " first match 626 norm! gg0 627 " moves to next match of previous search pattern, just like /<cr> 628 call feedkeys("/\<c-g>\<cr>", 'tx') 629 call assert_equal([0,1,2,0], getpos('.')) 630 " moves to next match of previous search pattern, just like /<cr> 631 call feedkeys("/\<cr>", 'tx') 632 call assert_equal([0,1,3,0], getpos('.')) 633 " moves to next match of previous search pattern, just like /<cr> 634 call feedkeys("/\<c-t>\<cr>", 'tx') 635 call assert_equal([0,1,7,0], getpos('.')) 636 637 " using an offset uses the last search pattern 638 call cursor(1, 1) 639 call setline(1, ['1 bbvimb', ' 2 bbvimb']) 640 let @/ = 'b' 641 call feedkeys("//e\<c-g>\<cr>", 'tx') 642 call assert_equal('1 bbvimb', getline('.')) 643 call assert_equal(4, col('.')) 644 645 set noincsearch 646 call test_override("char_avail", 0) 647 bw! 648endfunc 649 650func Test_search_cmdline8() 651 " Highlighting is cleared in all windows 652 " since hls applies to all windows 653 CheckOption incsearch 654 CheckFeature terminal 655 CheckNotGui 656 if has("win32") 657 throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" 658 endif 659 660 let h = winheight(0) 661 if h < 3 662 return 663 endif 664 " Prepare buffer text 665 let lines = ['abb vim vim vi', 'vimvivim'] 666 call writefile(lines, 'Xsearch.txt') 667 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) 668 669 call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) 670 671 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") 672 call term_sendkeys(buf, ":14vsp\<cr>") 673 call term_sendkeys(buf, "/vim\<cr>") 674 call term_sendkeys(buf, "/b\<esc>") 675 call term_sendkeys(buf, "gg0") 676 call TermWait(buf, 250) 677 let screen_line = term_scrape(buf, 1) 678 let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, 679 \ screen_line[18].attr, screen_line[19].attr] 680 call assert_notequal(a0, a1) 681 call assert_notequal(a0, a3) 682 call assert_notequal(a1, a2) 683 call assert_equal(a0, a2) 684 call assert_equal(a1, a3) 685 " clean up 686 call delete('Xsearch.txt') 687 688 bwipe! 689endfunc 690 691" Tests for regexp with various magic settings 692func Run_search_regexp_magic_opt() 693 put ='1 a aa abb abbccc' 694 exe 'normal! /a*b\{2}c\+/e' . "\<CR>" 695 call assert_equal([0, 2, 17, 0], getpos('.')) 696 697 put ='2 d dd dee deefff' 698 exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" 699 call assert_equal([0, 3, 17, 0], getpos('.')) 700 701 set nomagic 702 put ='3 g gg ghh ghhiii' 703 exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" 704 call assert_equal([0, 4, 17, 0], getpos('.')) 705 706 put ='4 j jj jkk jkklll' 707 exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" 708 call assert_equal([0, 5, 17, 0], getpos('.')) 709 710 put ='5 m mm mnn mnnooo' 711 exe 'normal! /\vm*n{2}o+/e' . "\<CR>" 712 call assert_equal([0, 6, 17, 0], getpos('.')) 713 714 put ='6 x ^aa$ x' 715 exe 'normal! /\V^aa$' . "\<CR>" 716 call assert_equal([0, 7, 5, 0], getpos('.')) 717 718 set magic 719 put ='7 (a)(b) abbaa' 720 exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" 721 call assert_equal([0, 8, 14, 0], getpos('.')) 722 723 put ='8 axx [ab]xx' 724 exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" 725 call assert_equal([0, 9, 7, 0], getpos('.')) 726 727 %d 728endfunc 729 730func Test_search_regexp() 731 enew! 732 733 set regexpengine=1 734 call Run_search_regexp_magic_opt() 735 set regexpengine=2 736 call Run_search_regexp_magic_opt() 737 set regexpengine& 738 739 set undolevels=100 740 put ='9 foobar' 741 put ='' 742 exe "normal! a\<C-G>u\<Esc>" 743 normal G 744 exe 'normal! dv?bar?' . "\<CR>" 745 call assert_equal('9 foo', getline('.')) 746 call assert_equal([0, 2, 5, 0], getpos('.')) 747 call assert_equal(2, line('$')) 748 normal u 749 call assert_equal('9 foobar', getline('.')) 750 call assert_equal([0, 2, 6, 0], getpos('.')) 751 call assert_equal(3, line('$')) 752 753 set undolevels& 754 enew! 755endfunc 756 757func Test_search_cmdline_incsearch_highlight() 758 CheckOption incsearch 759 760 set incsearch hlsearch 761 " need to disable char_avail, 762 " so that expansion of commandline works 763 call test_override("char_avail", 1) 764 new 765 call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) 766 767 1 768 call feedkeys("/second\<cr>", 'tx') 769 call assert_equal('second', @/) 770 call assert_equal(' 2 the second', getline('.')) 771 772 " Canceling search won't change @/ 773 1 774 let @/ = 'last pattern' 775 call feedkeys("/third\<C-c>", 'tx') 776 call assert_equal('last pattern', @/) 777 call feedkeys("/third\<Esc>", 'tx') 778 call assert_equal('last pattern', @/) 779 call feedkeys("/3\<bs>\<bs>", 'tx') 780 call assert_equal('last pattern', @/) 781 call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') 782 call assert_equal('last pattern', @/) 783 784 " clean up 785 set noincsearch nohlsearch 786 bw! 787endfunc 788 789func Test_search_cmdline_incsearch_highlight_attr() 790 CheckOption incsearch 791 CheckFeature terminal 792 CheckNotGui 793 794 let h = winheight(0) 795 if h < 3 796 return 797 endif 798 799 " Prepare buffer text 800 let lines = ['abb vim vim vi', 'vimvivim'] 801 call writefile(lines, 'Xsearch.txt') 802 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) 803 804 call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) 805 " wait for vim to complete initialization 806 call TermWait(buf) 807 808 " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight 809 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") 810 call term_sendkeys(buf, '/b') 811 call TermWait(buf, 100) 812 let screen_line1 = term_scrape(buf, 1) 813 call assert_true(len(screen_line1) > 2) 814 " a0: attr_normal 815 let a0 = screen_line1[0].attr 816 " a1: attr_incsearch 817 let a1 = screen_line1[1].attr 818 " a2: attr_hlsearch 819 let a2 = screen_line1[2].attr 820 call assert_notequal(a0, a1) 821 call assert_notequal(a0, a2) 822 call assert_notequal(a1, a2) 823 call term_sendkeys(buf, "\<cr>gg0") 824 825 " Test incremental highlight search 826 call term_sendkeys(buf, "/vim") 827 call TermWait(buf, 100) 828 " Buffer: 829 " abb vim vim vi 830 " vimvivim 831 " Search: /vim 832 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] 833 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] 834 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) 835 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) 836 837 " Test <C-g> 838 call term_sendkeys(buf, "\<C-g>\<C-g>") 839 call TermWait(buf, 100) 840 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] 841 let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] 842 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) 843 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) 844 845 " Test <C-t> 846 call term_sendkeys(buf, "\<C-t>") 847 call TermWait(buf, 100) 848 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] 849 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] 850 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) 851 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) 852 853 " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) 854 call term_sendkeys(buf, "\<cr>") 855 call TermWait(buf, 100) 856 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] 857 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] 858 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) 859 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) 860 861 " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) 862 call term_sendkeys(buf, ":1\<cr>") 863 call term_sendkeys(buf, ":set nohlsearch\<cr>") 864 call term_sendkeys(buf, "/vim") 865 call TermWait(buf, 100) 866 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] 867 let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] 868 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) 869 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) 870 call delete('Xsearch.txt') 871 872 call delete('Xsearch.txt') 873 bwipe! 874endfunc 875 876func Test_incsearch_cmdline_modifier() 877 CheckOption incsearch 878 879 call test_override("char_avail", 1) 880 new 881 call setline(1, ['foo']) 882 set incsearch 883 " Test that error E14 does not occur in parsing command modifier. 884 call feedkeys("V:tab", 'tx') 885 886 call Incsearch_cleanup() 887endfunc 888 889func Test_incsearch_scrolling() 890 CheckRunVimInTerminal 891 call assert_equal(0, &scrolloff) 892 call writefile([ 893 \ 'let dots = repeat(".", 120)', 894 \ 'set incsearch cmdheight=2 scrolloff=0', 895 \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])', 896 \ 'normal gg', 897 \ 'redraw', 898 \ ], 'Xscript') 899 let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70}) 900 " Need to send one key at a time to force a redraw 901 call term_sendkeys(buf, '/') 902 sleep 100m 903 call term_sendkeys(buf, 't') 904 sleep 100m 905 call term_sendkeys(buf, 'a') 906 sleep 100m 907 call term_sendkeys(buf, 'r') 908 sleep 100m 909 call term_sendkeys(buf, 'g') 910 call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {}) 911 912 call term_sendkeys(buf, "\<Esc>") 913 call StopVimInTerminal(buf) 914 call delete('Xscript') 915endfunc 916 917func Test_incsearch_search_dump() 918 CheckOption incsearch 919 CheckScreendump 920 921 call writefile([ 922 \ 'set incsearch hlsearch scrolloff=0', 923 \ 'for n in range(1, 8)', 924 \ ' call setline(n, "foo " . n)', 925 \ 'endfor', 926 \ '3', 927 \ ], 'Xis_search_script') 928 let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70}) 929 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 930 " the 'ambiwidth' check. 931 sleep 100m 932 933 " Need to send one key at a time to force a redraw. 934 call term_sendkeys(buf, '/fo') 935 call VerifyScreenDump(buf, 'Test_incsearch_search_01', {}) 936 call term_sendkeys(buf, "\<Esc>") 937 sleep 100m 938 939 call term_sendkeys(buf, '/\v') 940 call VerifyScreenDump(buf, 'Test_incsearch_search_02', {}) 941 call term_sendkeys(buf, "\<Esc>") 942 943 call StopVimInTerminal(buf) 944 call delete('Xis_search_script') 945endfunc 946 947func Test_hlsearch_dump() 948 CheckOption hlsearch 949 CheckScreendump 950 951 call writefile([ 952 \ 'set hlsearch cursorline', 953 \ 'call setline(1, ["xxx", "xxx", "xxx"])', 954 \ '/.*', 955 \ '2', 956 \ ], 'Xhlsearch_script') 957 let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50}) 958 call VerifyScreenDump(buf, 'Test_hlsearch_1', {}) 959 960 call term_sendkeys(buf, "/\\_.*\<CR>") 961 call VerifyScreenDump(buf, 'Test_hlsearch_2', {}) 962 963 call StopVimInTerminal(buf) 964 call delete('Xhlsearch_script') 965endfunc 966 967func Test_incsearch_substitute() 968 CheckOption incsearch 969 970 call test_override("char_avail", 1) 971 new 972 set incsearch 973 for n in range(1, 10) 974 call setline(n, 'foo ' . n) 975 endfor 976 4 977 call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx') 978 call assert_equal('foo 3', getline(3)) 979 call assert_equal('xxx 4', getline(4)) 980 call assert_equal('xxx 5', getline(5)) 981 call assert_equal('xxx 6', getline(6)) 982 call assert_equal('foo 7', getline(7)) 983 984 call Incsearch_cleanup() 985endfunc 986 987func Test_incsearch_substitute_long_line() 988 new 989 call test_override("char_avail", 1) 990 set incsearch 991 992 call repeat('x', 100000)->setline(1) 993 call feedkeys(':s/\%c', 'xt') 994 redraw 995 call feedkeys("\<Esc>", 'xt') 996 997 call Incsearch_cleanup() 998 bwipe! 999endfunc 1000 1001" Similar to Test_incsearch_substitute() but with a screendump halfway. 1002func Test_incsearch_substitute_dump() 1003 CheckOption incsearch 1004 CheckScreendump 1005 1006 call writefile([ 1007 \ 'set incsearch hlsearch scrolloff=0', 1008 \ 'for n in range(1, 10)', 1009 \ ' call setline(n, "foo " . n)', 1010 \ 'endfor', 1011 \ 'call setline(11, "bar 11")', 1012 \ '3', 1013 \ ], 'Xis_subst_script') 1014 let buf = RunVimInTerminal('-S Xis_subst_script', {'rows': 9, 'cols': 70}) 1015 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1016 " the 'ambiwidth' check. 1017 sleep 100m 1018 1019 " Need to send one key at a time to force a redraw. 1020 " Select three lines at the cursor with typed pattern. 1021 call term_sendkeys(buf, ':.,.+2s/') 1022 sleep 100m 1023 call term_sendkeys(buf, 'f') 1024 sleep 100m 1025 call term_sendkeys(buf, 'o') 1026 sleep 100m 1027 call term_sendkeys(buf, 'o') 1028 call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {}) 1029 call term_sendkeys(buf, "\<Esc>") 1030 1031 " Select three lines at the cursor using previous pattern. 1032 call term_sendkeys(buf, "/foo\<CR>") 1033 sleep 100m 1034 call term_sendkeys(buf, ':.,.+2s//') 1035 call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {}) 1036 1037 " Deleting last slash should remove the match. 1038 call term_sendkeys(buf, "\<BS>") 1039 call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {}) 1040 call term_sendkeys(buf, "\<Esc>") 1041 1042 " Reverse range is accepted 1043 call term_sendkeys(buf, ':5,2s/foo') 1044 call VerifyScreenDump(buf, 'Test_incsearch_substitute_04', {}) 1045 call term_sendkeys(buf, "\<Esc>") 1046 1047 " White space after the command is skipped 1048 call term_sendkeys(buf, ':2,3sub /fo') 1049 call VerifyScreenDump(buf, 'Test_incsearch_substitute_05', {}) 1050 call term_sendkeys(buf, "\<Esc>") 1051 1052 " Command modifiers are skipped 1053 call term_sendkeys(buf, ':above below browse botr confirm keepmar keepalt keeppat keepjum filter xxx hide lockm leftabove noau noswap rightbel sandbox silent silent! $tab top unsil vert verbose 4,5s/fo.') 1054 call VerifyScreenDump(buf, 'Test_incsearch_substitute_06', {}) 1055 call term_sendkeys(buf, "\<Esc>") 1056 1057 " Cursorline highlighting at match 1058 call term_sendkeys(buf, ":set cursorline\<CR>") 1059 call term_sendkeys(buf, 'G9G') 1060 call term_sendkeys(buf, ':9,11s/bar') 1061 call VerifyScreenDump(buf, 'Test_incsearch_substitute_07', {}) 1062 call term_sendkeys(buf, "\<Esc>") 1063 1064 " Cursorline highlighting at cursor when no match 1065 call term_sendkeys(buf, ':9,10s/bar') 1066 call VerifyScreenDump(buf, 'Test_incsearch_substitute_08', {}) 1067 call term_sendkeys(buf, "\<Esc>") 1068 1069 " Only \v handled as empty pattern, does not move cursor 1070 call term_sendkeys(buf, '3G4G') 1071 call term_sendkeys(buf, ":nohlsearch\<CR>") 1072 call term_sendkeys(buf, ':6,7s/\v') 1073 call VerifyScreenDump(buf, 'Test_incsearch_substitute_09', {}) 1074 call term_sendkeys(buf, "\<Esc>") 1075 1076 call term_sendkeys(buf, ":set nocursorline\<CR>") 1077 1078 " All matches are highlighted for 'hlsearch' after the incsearch canceled 1079 call term_sendkeys(buf, "1G*") 1080 call term_sendkeys(buf, ":2,5s/foo") 1081 sleep 100m 1082 call term_sendkeys(buf, "\<Esc>") 1083 call VerifyScreenDump(buf, 'Test_incsearch_substitute_10', {}) 1084 1085 call term_sendkeys(buf, ":split\<CR>") 1086 call term_sendkeys(buf, ":let @/ = 'xyz'\<CR>") 1087 call term_sendkeys(buf, ":%s/.") 1088 call VerifyScreenDump(buf, 'Test_incsearch_substitute_11', {}) 1089 call term_sendkeys(buf, "\<BS>") 1090 call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) 1091 call term_sendkeys(buf, "\<Esc>") 1092 call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) 1093 call term_sendkeys(buf, ":%bwipe!\<CR>") 1094 call term_sendkeys(buf, ":only!\<CR>") 1095 1096 " get :'<,'>s command in history 1097 call term_sendkeys(buf, ":set cmdheight=2\<CR>") 1098 call term_sendkeys(buf, "aasdfasdf\<Esc>") 1099 call term_sendkeys(buf, "V:s/a/b/g\<CR>") 1100 " Using '<,'> does not give E20 1101 call term_sendkeys(buf, ":new\<CR>") 1102 call term_sendkeys(buf, "aasdfasdf\<Esc>") 1103 call term_sendkeys(buf, ":\<Up>\<Up>") 1104 call VerifyScreenDump(buf, 'Test_incsearch_substitute_14', {}) 1105 call term_sendkeys(buf, "<Esc>") 1106 1107 call StopVimInTerminal(buf) 1108 call delete('Xis_subst_script') 1109endfunc 1110 1111func Test_incsearch_highlighting() 1112 CheckOption incsearch 1113 CheckScreendump 1114 1115 call writefile([ 1116 \ 'set incsearch hlsearch', 1117 \ 'call setline(1, "hello/there")', 1118 \ ], 'Xis_subst_hl_script') 1119 let buf = RunVimInTerminal('-S Xis_subst_hl_script', {'rows': 4, 'cols': 20}) 1120 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1121 " the 'ambiwidth' check. 1122 sleep 300m 1123 1124 " Using a different search delimiter should still highlight matches 1125 " that contain a '/'. 1126 call term_sendkeys(buf, ":%s;ello/the") 1127 call VerifyScreenDump(buf, 'Test_incsearch_substitute_15', {}) 1128 call term_sendkeys(buf, "<Esc>") 1129 1130 call StopVimInTerminal(buf) 1131 call delete('Xis_subst_hl_script') 1132endfunc 1133 1134func Test_incsearch_with_change() 1135 CheckFeature timers 1136 CheckOption incsearch 1137 CheckScreendump 1138 1139 call writefile([ 1140 \ 'set incsearch hlsearch scrolloff=0', 1141 \ 'call setline(1, ["one", "two ------ X", "three"])', 1142 \ 'call timer_start(200, { _ -> setline(2, "x")})', 1143 \ ], 'Xis_change_script') 1144 let buf = RunVimInTerminal('-S Xis_change_script', {'rows': 9, 'cols': 70}) 1145 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1146 " the 'ambiwidth' check. 1147 sleep 300m 1148 1149 " Highlight X, it will be deleted by the timer callback. 1150 call term_sendkeys(buf, ':%s/X') 1151 call VerifyScreenDump(buf, 'Test_incsearch_change_01', {}) 1152 call term_sendkeys(buf, "\<Esc>") 1153 1154 call StopVimInTerminal(buf) 1155 call delete('Xis_change_script') 1156endfunc 1157 1158" Similar to Test_incsearch_substitute_dump() for :sort 1159func Test_incsearch_sort_dump() 1160 CheckOption incsearch 1161 CheckScreendump 1162 1163 call writefile([ 1164 \ 'set incsearch hlsearch scrolloff=0', 1165 \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', 1166 \ ], 'Xis_sort_script') 1167 let buf = RunVimInTerminal('-S Xis_sort_script', {'rows': 9, 'cols': 70}) 1168 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1169 " the 'ambiwidth' check. 1170 sleep 100m 1171 1172 call term_sendkeys(buf, ':sort ni u /on') 1173 call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) 1174 call term_sendkeys(buf, "\<Esc>") 1175 1176 call term_sendkeys(buf, ':sort! /on') 1177 call VerifyScreenDump(buf, 'Test_incsearch_sort_02', {}) 1178 call term_sendkeys(buf, "\<Esc>") 1179 1180 call StopVimInTerminal(buf) 1181 call delete('Xis_sort_script') 1182endfunc 1183 1184" Similar to Test_incsearch_substitute_dump() for :vimgrep famiry 1185func Test_incsearch_vimgrep_dump() 1186 CheckOption incsearch 1187 CheckScreendump 1188 1189 call writefile([ 1190 \ 'set incsearch hlsearch scrolloff=0', 1191 \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', 1192 \ ], 'Xis_vimgrep_script') 1193 let buf = RunVimInTerminal('-S Xis_vimgrep_script', {'rows': 9, 'cols': 70}) 1194 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1195 " the 'ambiwidth' check. 1196 sleep 100m 1197 1198 " Need to send one key at a time to force a redraw. 1199 call term_sendkeys(buf, ':vimgrep on') 1200 call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_01', {}) 1201 call term_sendkeys(buf, "\<Esc>") 1202 1203 call term_sendkeys(buf, ':vimg /on/ *.txt') 1204 call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_02', {}) 1205 call term_sendkeys(buf, "\<Esc>") 1206 1207 call term_sendkeys(buf, ':vimgrepadd "\<on') 1208 call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_03', {}) 1209 call term_sendkeys(buf, "\<Esc>") 1210 1211 call term_sendkeys(buf, ':lv "tha') 1212 call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_04', {}) 1213 call term_sendkeys(buf, "\<Esc>") 1214 1215 call term_sendkeys(buf, ':lvimgrepa "the" **/*.txt') 1216 call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_05', {}) 1217 call term_sendkeys(buf, "\<Esc>") 1218 1219 call StopVimInTerminal(buf) 1220 call delete('Xis_vimgrep_script') 1221endfunc 1222 1223func Test_keep_last_search_pattern() 1224 CheckOption incsearch 1225 1226 new 1227 call setline(1, ['foo', 'foo', 'foo']) 1228 set incsearch 1229 call test_override("char_avail", 1) 1230 let @/ = 'bar' 1231 call feedkeys(":/foo/s//\<Esc>", 'ntx') 1232 call assert_equal('bar', @/) 1233 1234 " no error message if pattern not found 1235 call feedkeys(":/xyz/s//\<Esc>", 'ntx') 1236 call assert_equal('bar', @/) 1237 1238 bwipe! 1239 call test_override("ALL", 0) 1240 set noincsearch 1241endfunc 1242 1243func Test_word_under_cursor_after_match() 1244 CheckOption incsearch 1245 1246 new 1247 call setline(1, 'foo bar') 1248 set incsearch 1249 call test_override("char_avail", 1) 1250 try 1251 call feedkeys("/foo\<C-R>\<C-W>\<CR>", 'ntx') 1252 catch /E486:/ 1253 endtry 1254 call assert_equal('foobar', @/) 1255 1256 bwipe! 1257 call test_override("ALL", 0) 1258 set noincsearch 1259endfunc 1260 1261func Test_subst_word_under_cursor() 1262 CheckOption incsearch 1263 1264 new 1265 call setline(1, ['int SomeLongName;', 'for (xxx = 1; xxx < len; ++xxx)']) 1266 set incsearch 1267 call test_override("char_avail", 1) 1268 call feedkeys("/LongName\<CR>", 'ntx') 1269 call feedkeys(":%s/xxx/\<C-R>\<C-W>/g\<CR>", 'ntx') 1270 call assert_equal('for (SomeLongName = 1; SomeLongName < len; ++SomeLongName)', getline(2)) 1271 1272 bwipe! 1273 call test_override("ALL", 0) 1274 set noincsearch 1275endfunc 1276 1277func Test_search_undefined_behaviour() 1278 CheckFeature terminal 1279 1280 let h = winheight(0) 1281 if h < 3 1282 return 1283 endif 1284 " did cause an undefined left shift 1285 let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3}) 1286 call assert_equal([''], getline(1, '$')) 1287 call term_sendkeys(g:buf, ":qa!\<cr>") 1288 bwipe! 1289endfunc 1290 1291func Test_search_undefined_behaviour2() 1292 call search("\%UC0000000") 1293endfunc 1294 1295" Test for search('multi-byte char', 'bce') 1296func Test_search_multibyte() 1297 let save_enc = &encoding 1298 set encoding=utf8 1299 enew! 1300 call append('$', 'A') 1301 call cursor(2, 1) 1302 call assert_equal(2, search('A', 'bce', line('.'))) 1303 enew! 1304 let &encoding = save_enc 1305endfunc 1306 1307" This was causing E874. Also causes an invalid read? 1308func Test_look_behind() 1309 new 1310 call setline(1, '0\|\&\n\@<=') 1311 call search(getline(".")) 1312 bwipe! 1313endfunc 1314 1315func Test_search_sentence() 1316 new 1317 " this used to cause a crash 1318 call assert_fails("/\\%')", 'E486:') 1319 call assert_fails("/", 'E486:') 1320 /\%'( 1321 / 1322endfunc 1323 1324" Test that there is no crash when there is a last search pattern but no last 1325" substitute pattern. 1326func Test_no_last_substitute_pat() 1327 " Use viminfo to set the last search pattern to a string and make the last 1328 " substitute pattern the most recent used and make it empty (NULL). 1329 call writefile(['~MSle0/bar', '~MSle0~&'], 'Xviminfo') 1330 rviminfo! Xviminfo 1331 call assert_fails('normal n', 'E35:') 1332 1333 call delete('Xviminfo') 1334endfunc 1335 1336func Test_search_Ctrl_L_combining() 1337 " Make sure, that Ctrl-L works correctly with combining characters. 1338 " It uses an artificial example of an 'a' with 4 combining chars: 1339 " 'a' U+0061 Dec:97 LATIN SMALL LETTER A a /\%u61\Z "\u0061" 1340 " ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" 1341 " ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" 1342 " ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" 1343 " ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" 1344 " Those should also appear on the commandline 1345 CheckOption incsearch 1346 1347 call Cmdline3_prep() 1348 1 1349 let bufcontent = ['', 'Miạ̀́̇m'] 1350 call append('$', bufcontent) 1351 call feedkeys("/Mi\<c-l>\<c-l>\<cr>", 'tx') 1352 call assert_equal(5, line('.')) 1353 call assert_equal(bufcontent[1], @/) 1354 call Incsearch_cleanup() 1355endfunc 1356 1357func Test_large_hex_chars1() 1358 " This used to cause a crash, the character becomes an NFA state. 1359 try 1360 /\%Ufffffc23 1361 catch 1362 call assert_match('E678:', v:exception) 1363 endtry 1364 try 1365 set re=1 1366 /\%Ufffffc23 1367 catch 1368 call assert_match('E678:', v:exception) 1369 endtry 1370 set re& 1371endfunc 1372 1373func Test_large_hex_chars2() 1374 " This used to cause a crash, the character becomes an NFA state. 1375 try 1376 /[\Ufffffc1f] 1377 catch 1378 call assert_match('E486:', v:exception) 1379 endtry 1380 try 1381 set re=1 1382 /[\Ufffffc1f] 1383 catch 1384 call assert_match('E486:', v:exception) 1385 endtry 1386 set re& 1387endfunc 1388 1389func Test_one_error_msg() 1390 " This was also giving an internal error 1391 call assert_fails('call search(" \\((\\v[[=P=]]){185}+ ")', 'E871:') 1392endfunc 1393 1394func Test_incsearch_add_char_under_cursor() 1395 CheckOption incsearch 1396 1397 set incsearch 1398 new 1399 call setline(1, ['find match', 'anything']) 1400 1 1401 call test_override('char_avail', 1) 1402 call feedkeys("fc/m\<C-L>\<C-L>\<C-L>\<C-L>\<C-L>\<CR>", 'tx') 1403 call assert_equal('match', @/) 1404 call test_override('char_avail', 0) 1405 1406 set incsearch& 1407 bwipe! 1408endfunc 1409 1410" Test for the search() function with match at the cursor position 1411func Test_search_match_at_curpos() 1412 new 1413 call append(0, ['foobar', '', 'one two', '']) 1414 1415 normal gg 1416 1417 eval 'foobar'->search('c') 1418 call assert_equal([1, 1], [line('.'), col('.')]) 1419 1420 normal j 1421 call search('^$', 'c') 1422 call assert_equal([2, 1], [line('.'), col('.')]) 1423 1424 call search('^$', 'bc') 1425 call assert_equal([2, 1], [line('.'), col('.')]) 1426 1427 exe "normal /two\<CR>" 1428 call search('.', 'c') 1429 call assert_equal([3, 5], [line('.'), col('.')]) 1430 1431 close! 1432endfunc 1433 1434" Test for error cases with the search() function 1435func Test_search_errors() 1436 call assert_fails("call search('pat', [])", 'E730:') 1437 call assert_fails("call search('pat', 'b', {})", 'E728:') 1438 call assert_fails("call search('pat', 'b', 1, [])", 'E745:') 1439 call assert_fails("call search('pat', 'ns')", 'E475:') 1440 call assert_fails("call search('pat', 'mr')", 'E475:') 1441 1442 new 1443 call setline(1, ['foo', 'bar']) 1444 call assert_fails('call feedkeys("/foo/;/bar/;\<CR>", "tx")', 'E386:') 1445 bwipe! 1446endfunc 1447 1448func Test_search_display_pattern() 1449 new 1450 call setline(1, ['foo', 'bar', 'foobar']) 1451 1452 call cursor(1, 1) 1453 let @/ = 'foo' 1454 let pat = @/->escape('()*?'. '\s\+') 1455 let g:a = execute(':unsilent :norm! n') 1456 call assert_match(pat, g:a) 1457 1458 " right-left 1459 if exists("+rightleft") 1460 set rl 1461 call cursor(1, 1) 1462 let @/ = 'foo' 1463 let pat = 'oof/\s\+' 1464 let g:a = execute(':unsilent :norm! n') 1465 call assert_match(pat, g:a) 1466 set norl 1467 endif 1468endfunc 1469 1470func Test_searchdecl() 1471 let lines =<< trim END 1472 int global; 1473 1474 func() 1475 { 1476 int global; 1477 if (cond) { 1478 int local; 1479 } 1480 int local; 1481 // comment 1482 } 1483 END 1484 new 1485 call setline(1, lines) 1486 10 1487 call assert_equal(0, searchdecl('local', 0, 0)) 1488 call assert_equal(7, getcurpos()[1]) 1489 1490 10 1491 call assert_equal(0, 'local'->searchdecl(0, 1)) 1492 call assert_equal(9, getcurpos()[1]) 1493 1494 10 1495 call assert_equal(0, searchdecl('global')) 1496 call assert_equal(5, getcurpos()[1]) 1497 1498 10 1499 call assert_equal(0, searchdecl('global', 1)) 1500 call assert_equal(1, getcurpos()[1]) 1501 1502 bwipe! 1503endfunc 1504 1505func Test_search_special() 1506 " this was causing illegal memory access and an endless loop 1507 set t_PE= 1508 exe "norm /\x80PS" 1509endfunc 1510 1511" Test for command failures when the last search pattern is not set. 1512" Need to run this in a new vim instance where last search pattern is not set. 1513func Test_search_with_no_last_pat() 1514 let lines =<< trim [SCRIPT] 1515 call assert_fails("normal i\<C-R>/\e", 'E35:') 1516 call assert_fails("exe '/'", 'E35:') 1517 call assert_fails("exe '?'", 'E35:') 1518 call assert_fails("/", 'E35:') 1519 call assert_fails("?", 'E35:') 1520 call assert_fails("normal n", 'E35:') 1521 call assert_fails("normal N", 'E35:') 1522 call assert_fails("normal gn", 'E35:') 1523 call assert_fails("normal gN", 'E35:') 1524 call assert_fails("normal cgn", 'E35:') 1525 call assert_fails("normal cgN", 'E35:') 1526 let p = [] 1527 let p = @/ 1528 call assert_equal('', p) 1529 call assert_fails("normal :\<C-R>/", 'E35:') 1530 call assert_fails("//p", 'E35:') 1531 call assert_fails(";//p", 'E35:') 1532 call assert_fails("??p", 'E35:') 1533 call assert_fails(";??p", 'E35:') 1534 call assert_fails('g//p', ['E35:', 'E476:']) 1535 call assert_fails('v//p', ['E35:', 'E476:']) 1536 call writefile(v:errors, 'Xresult') 1537 qall! 1538 [SCRIPT] 1539 call writefile(lines, 'Xscript') 1540 1541 if RunVim([], [], '--clean -S Xscript') 1542 call assert_equal([], readfile('Xresult')) 1543 endif 1544 call delete('Xscript') 1545 call delete('Xresult') 1546endfunc 1547 1548" Test for using tilde (~) atom in search. This should use the last used 1549" substitute pattern 1550func Test_search_tilde_pat() 1551 let lines =<< trim [SCRIPT] 1552 set regexpengine=1 1553 call assert_fails('exe "normal /~\<CR>"', 'E33:') 1554 call assert_fails('exe "normal ?~\<CR>"', 'E33:') 1555 set regexpengine=2 1556 call assert_fails('exe "normal /~\<CR>"', ['E33:', 'E383:']) 1557 call assert_fails('exe "normal ?~\<CR>"', ['E33:', 'E383:']) 1558 set regexpengine& 1559 call writefile(v:errors, 'Xresult') 1560 qall! 1561 [SCRIPT] 1562 call writefile(lines, 'Xscript') 1563 if RunVim([], [], '--clean -S Xscript') 1564 call assert_equal([], readfile('Xresult')) 1565 endif 1566 call delete('Xscript') 1567 call delete('Xresult') 1568endfunc 1569 1570" Test for searching a pattern that is not present with 'nowrapscan' 1571func Test_search_pat_not_found() 1572 new 1573 set nowrapscan 1574 let @/ = '1abcxyz2' 1575 call assert_fails('normal n', 'E385:') 1576 call assert_fails('normal N', 'E384:') 1577 set wrapscan& 1578 close 1579endfunc 1580 1581" Test for v:searchforward variable 1582func Test_searchforward_var() 1583 new 1584 call setline(1, ['foo', '', 'foo']) 1585 call cursor(2, 1) 1586 let @/ = 'foo' 1587 let v:searchforward = 0 1588 normal N 1589 call assert_equal(3, line('.')) 1590 call cursor(2, 1) 1591 let v:searchforward = 1 1592 normal N 1593 call assert_equal(1, line('.')) 1594 close! 1595endfunc 1596 1597" Test for invalid regular expressions 1598func Test_invalid_regexp() 1599 set regexpengine=1 1600 call assert_fails("call search(repeat('\\(.\\)', 10))", 'E51:') 1601 call assert_fails("call search('\\%(')", 'E53:') 1602 call assert_fails("call search('\\(')", 'E54:') 1603 call assert_fails("call search('\\)')", 'E55:') 1604 call assert_fails("call search('x\\@#')", 'E59:') 1605 call assert_fails('call search(''\v%(%(%(%(%(%(%(%(%(%(%(a){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}'')', 'E60:') 1606 call assert_fails("call search('a\\+*')", 'E61:') 1607 call assert_fails("call search('\\_m')", 'E63:') 1608 call assert_fails("call search('\\+')", 'E64:') 1609 call assert_fails("call search('\\1')", 'E65:') 1610 call assert_fails("call search('\\z\\(\\)')", 'E66:') 1611 call assert_fails("call search('\\z2')", 'E67:') 1612 call assert_fails("call search('\\zx')", 'E68:') 1613 call assert_fails("call search('\\%[ab')", 'E69:') 1614 call assert_fails("call search('\\%[]')", 'E70:') 1615 call assert_fails("call search('\\%a')", 'E71:') 1616 call assert_fails("call search('ab\\%[\\(cd\\)]')", 'E369:') 1617 call assert_fails("call search('ab\\%[\\%(cd\\)]')", 'E369:') 1618 set regexpengine=2 1619 call assert_fails("call search('\\_')", 'E865:') 1620 call assert_fails("call search('\\+')", 'E866:') 1621 call assert_fails("call search('\\zx')", 'E867:') 1622 call assert_fails("call search('\\%a')", 'E867:') 1623 call assert_fails("call search('x\\@#')", 'E869:') 1624 call assert_fails("call search(repeat('\\(.\\)', 10))", 'E872:') 1625 call assert_fails("call search('\\_m')", 'E877:') 1626 call assert_fails("call search('\\%(')", 'E53:') 1627 call assert_fails("call search('\\(')", 'E54:') 1628 call assert_fails("call search('\\)')", 'E55:') 1629 call assert_fails("call search('\\z\\(\\)')", 'E66:') 1630 call assert_fails("call search('\\%[ab')", 'E69:') 1631 call assert_fails("call search('\\%[]')", 'E70:') 1632 call assert_fails("call search('\\%9999999999999999999999999999v')", 'E951:') 1633 set regexpengine& 1634 call assert_fails("call search('\\%#=3ab')", 'E864:') 1635endfunc 1636 1637" Test for searching a very complex pattern in a string. Should switch the 1638" regexp engine from NFA to the old engine. 1639func Test_regexp_switch_engine() 1640 let l = readfile('samples/re.freeze.txt') 1641 let v = substitute(l[4], '..\@<!', '', '') 1642 call assert_equal(l[4], v) 1643endfunc 1644 1645" Test for the \%V atom to search within visually selected text 1646func Test_search_in_visual_area() 1647 new 1648 call setline(1, ['foo bar1', 'foo bar2', 'foo bar3', 'foo bar4']) 1649 exe "normal 2GVjo/\\%Vbar\<CR>\<Esc>" 1650 call assert_equal([2, 5], [line('.'), col('.')]) 1651 exe "normal 2GVj$?\\%Vbar\<CR>\<Esc>" 1652 call assert_equal([3, 5], [line('.'), col('.')]) 1653 close! 1654endfunc 1655 1656" Test for searching with 'smartcase' and 'ignorecase' 1657func Test_search_smartcase() 1658 new 1659 call setline(1, ['', 'Hello']) 1660 set noignorecase nosmartcase 1661 call assert_fails('exe "normal /\\a\\_.\\(.*\\)O\<CR>"', 'E486:') 1662 1663 set ignorecase nosmartcase 1664 exe "normal /\\a\\_.\\(.*\\)O\<CR>" 1665 call assert_equal([2, 1], [line('.'), col('.')]) 1666 1667 call cursor(1, 1) 1668 set ignorecase smartcase 1669 call assert_fails('exe "normal /\\a\\_.\\(.*\\)O\<CR>"', 'E486:') 1670 1671 exe "normal /\\a\\_.\\(.*\\)o\<CR>" 1672 call assert_equal([2, 1], [line('.'), col('.')]) 1673 1674 " Test for using special atoms with 'smartcase' 1675 call setline(1, ['', ' Hello\ ']) 1676 call cursor(1, 1) 1677 call feedkeys('/\_.\%(\uello\)\' .. "\<CR>", 'xt') 1678 call assert_equal([2, 4], [line('.'), col('.')]) 1679 1680 set ignorecase& smartcase& 1681 close! 1682endfun 1683 1684" Test 'smartcase' with utf-8. 1685func Test_search_smartcase_utf8() 1686 new 1687 let save_enc = &encoding 1688 set encoding=utf8 ignorecase smartcase 1689 1690 call setline(1, 'Café cafÉ') 1691 1s/café/x/g 1692 call assert_equal('x x', getline(1)) 1693 1694 call setline(1, 'Café cafÉ') 1695 1s/cafÉ/x/g 1696 call assert_equal('Café x', getline(1)) 1697 1698 set ignorecase& smartcase& 1699 let &encoding = save_enc 1700 close! 1701endfunc 1702 1703" Test searching past the end of a file 1704func Test_search_past_eof() 1705 new 1706 call setline(1, ['Line']) 1707 exe "normal /\\n\\zs\<CR>" 1708 call assert_equal([1, 4], [line('.'), col('.')]) 1709 close! 1710endfunc 1711 1712" Test for various search offsets 1713func Test_search_offset() 1714 " With /e, for a match in the first column of a line, the cursor should be 1715 " placed at the end of the previous line. 1716 new 1717 call setline(1, ['one two', 'three four']) 1718 call search('two\_.', 'e') 1719 call assert_equal([1, 7], [line('.'), col('.')]) 1720 1721 " with cursor at the beginning of the file, use /s+1 1722 call cursor(1, 1) 1723 exe "normal /two/s+1\<CR>" 1724 call assert_equal([1, 6], [line('.'), col('.')]) 1725 1726 " with cursor at the end of the file, use /e-1 1727 call cursor(2, 10) 1728 exe "normal ?three?e-1\<CR>" 1729 call assert_equal([2, 4], [line('.'), col('.')]) 1730 1731 " line offset - after the last line 1732 call cursor(1, 1) 1733 exe "normal /three/+1\<CR>" 1734 call assert_equal([2, 1], [line('.'), col('.')]) 1735 1736 " line offset - before the first line 1737 call cursor(2, 1) 1738 exe "normal ?one?-1\<CR>" 1739 call assert_equal([1, 1], [line('.'), col('.')]) 1740 1741 " character offset - before the first character in the file 1742 call cursor(2, 1) 1743 exe "normal ?one?s-1\<CR>" 1744 call assert_equal([1, 1], [line('.'), col('.')]) 1745 call cursor(2, 1) 1746 exe "normal ?one?e-3\<CR>" 1747 call assert_equal([1, 1], [line('.'), col('.')]) 1748 1749 " character offset - after the last character in the file 1750 call cursor(1, 1) 1751 exe "normal /four/s+4\<CR>" 1752 call assert_equal([2, 10], [line('.'), col('.')]) 1753 call cursor(1, 1) 1754 exe "normal /four/e+1\<CR>" 1755 call assert_equal([2, 10], [line('.'), col('.')]) 1756 1757 close! 1758endfunc 1759 1760" Test for searching for matching parenthesis using % 1761func Test_search_match_paren() 1762 new 1763 call setline(1, "abc(def')'ghi'('jk'\\t'lm)no") 1764 " searching for a matching parenthesis should skip single quoted characters 1765 call cursor(1, 4) 1766 normal % 1767 call assert_equal([1, 25], [line('.'), col('.')]) 1768 normal % 1769 call assert_equal([1, 4], [line('.'), col('.')]) 1770 call cursor(1, 5) 1771 normal ]) 1772 call assert_equal([1, 25], [line('.'), col('.')]) 1773 call cursor(1, 24) 1774 normal [( 1775 call assert_equal([1, 4], [line('.'), col('.')]) 1776 1777 " matching parenthesis in 'virtualedit' mode with cursor after the eol 1778 call setline(1, 'abc(defgh)') 1779 set virtualedit=all 1780 normal 20|% 1781 call assert_equal(4, col('.')) 1782 set virtualedit& 1783 close! 1784endfunc 1785 1786" Test for searching a pattern and stopping before a specified line 1787func Test_search_stopline() 1788 new 1789 call setline(1, ['', '', '', 'vim']) 1790 call assert_equal(0, search('vim', 'n', 3)) 1791 call assert_equal(4, search('vim', 'n', 4)) 1792 call setline(1, ['vim', '', '', '']) 1793 call cursor(4, 1) 1794 call assert_equal(0, search('vim', 'bn', 2)) 1795 call assert_equal(1, search('vim', 'bn', 1)) 1796 close! 1797endfunc 1798 1799func Test_incsearch_highlighting_newline() 1800 CheckRunVimInTerminal 1801 CheckOption incsearch 1802 CheckScreendump 1803 new 1804 call test_override("char_avail", 1) 1805 1806 let commands =<< trim [CODE] 1807 set incsearch nohls 1808 call setline(1, ['test', 'xxx']) 1809 [CODE] 1810 call writefile(commands, 'Xincsearch_nl') 1811 let buf = RunVimInTerminal('-S Xincsearch_nl', {'rows': 5, 'cols': 10}) 1812 call term_sendkeys(buf, '/test') 1813 call VerifyScreenDump(buf, 'Test_incsearch_newline1', {}) 1814 " Need to send one key at a time to force a redraw 1815 call term_sendkeys(buf, '\n') 1816 call VerifyScreenDump(buf, 'Test_incsearch_newline2', {}) 1817 call term_sendkeys(buf, 'x') 1818 call VerifyScreenDump(buf, 'Test_incsearch_newline3', {}) 1819 call term_sendkeys(buf, 'x') 1820 call VerifyScreenDump(buf, 'Test_incsearch_newline4', {}) 1821 call term_sendkeys(buf, "\<CR>") 1822 call VerifyScreenDump(buf, 'Test_incsearch_newline5', {}) 1823 call StopVimInTerminal(buf) 1824 1825 " clean up 1826 call delete('Xincsearch_nl') 1827 call test_override("char_avail", 0) 1828 bw 1829endfunc 1830 1831func Test_incsearch_substitute_dump2() 1832 CheckOption incsearch 1833 CheckScreendump 1834 1835 call writefile([ 1836 \ 'set incsearch hlsearch scrolloff=0', 1837 \ 'for n in range(1, 4)', 1838 \ ' call setline(n, "foo " . n)', 1839 \ 'endfor', 1840 \ 'call setline(5, "abc|def")', 1841 \ '3', 1842 \ ], 'Xis_subst_script2') 1843 let buf = RunVimInTerminal('-S Xis_subst_script2', {'rows': 9, 'cols': 70}) 1844 1845 call term_sendkeys(buf, ':%s/\vabc|') 1846 sleep 100m 1847 call VerifyScreenDump(buf, 'Test_incsearch_sub_01', {}) 1848 call term_sendkeys(buf, "\<Esc>") 1849 1850 " The following should not be highlighted 1851 call term_sendkeys(buf, ':1,5s/\v|') 1852 sleep 100m 1853 call VerifyScreenDump(buf, 'Test_incsearch_sub_02', {}) 1854 1855 1856 call StopVimInTerminal(buf) 1857 call delete('Xis_subst_script2') 1858endfunc 1859 1860" vim: shiftwidth=2 sts=2 expandtab 1861