robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1" Test for the search command 2 3source shared.vim 4source screendump.vim 5source check.vim 6 7func Test_search_cmdline () 8CheckOption incsearch 9 10" need to disable char_avail, 11" so that expansion of commandline works 12call Ntest_override ( "char_avail" , 1 ) 13new 14call 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 17set noincsearch 18: 1 19call feedkeys ( "/foobar\<cr>" , 'tx' ) 20call feedkeys ( "/the\<cr>" , 'tx' ) 21call assert_equal ( 'the' , @/) 22call feedkeys ( "/thes\<C-P>\<C-P>\<cr>" , 'tx' ) 23call assert_equal ( 'foobar' , @/) 24 25" Test 2 26" Ctrl-G goes from one match to the next 27" until the end of the buffer 28set incsearch nowrapscan 29: 1 30" first match 31call feedkeys ( "/the\<cr>" , 'tx' ) 32call assert_equal ( ' 2 these' , getline ( '.' )) 33: 1 34" second match 35call feedkeys ( "/the\<C-G>\<cr>" , 'tx' ) 36call assert_equal ( ' 3 the' , getline ( '.' )) 37call assert_equal ([ 0 , 0 , 0 , 0 ], getpos ( '"' )) 38: 1 39" third match 40call feedkeys ( "/the" . repeat ( "\<C-G>" , 2 ) . "\<cr>" , 'tx' ) 41call assert_equal ( ' 4 their' , getline ( '.' )) 42: 1 43" fourth match 44call feedkeys ( "/the" . repeat ( "\<C-G>" , 3 ) . "\<cr>" , 'tx' ) 45call assert_equal ( ' 5 there' , getline ( '.' )) 46: 1 47" fifth match 48call feedkeys ( "/the" . repeat ( "\<C-G>" , 4 ) . "\<cr>" , 'tx' ) 49call assert_equal ( ' 6 their' , getline ( '.' )) 50: 1 51" sixth match 52call feedkeys ( "/the" . repeat ( "\<C-G>" , 5 ) . "\<cr>" , 'tx' ) 53call assert_equal ( ' 7 the' , getline ( '.' )) 54: 1 55" seventh match 56call feedkeys ( "/the" . repeat ( "\<C-G>" , 6 ) . "\<cr>" , 'tx' ) 57call assert_equal ( ' 8 them' , getline ( '.' )) 58: 1 59" eighth match 60call feedkeys ( "/the" . repeat ( "\<C-G>" , 7 ) . "\<cr>" , 'tx' ) 61call assert_equal ( ' 9 these' , getline ( '.' )) 62: 1 63" no further match 64call feedkeys ( "/the" . repeat ( "\<C-G>" , 8 ) . "\<cr>" , 'tx' ) 65call assert_equal ( ' 9 these' , getline ( '.' )) 66call 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 71set incsearch wrapscan 72: 1 73" first match 74call feedkeys ( "/the\<cr>" , 'tx' ) 75call assert_equal ( ' 2 these' , getline ( '.' )) 76: 1 77" second match 78call feedkeys ( "/the\<C-G>\<cr>" , 'tx' ) 79call assert_equal ( ' 3 the' , getline ( '.' )) 80: 1 81" third match 82call feedkeys ( "/the" . repeat ( "\<C-G>" , 2 ) . "\<cr>" , 'tx' ) 83call assert_equal ( ' 4 their' , getline ( '.' )) 84: 1 85" fourth match 86call feedkeys ( "/the" . repeat ( "\<C-G>" , 3 ) . "\<cr>" , 'tx' ) 87call assert_equal ( ' 5 there' , getline ( '.' )) 88: 1 89" fifth match 90call feedkeys ( "/the" . repeat ( "\<C-G>" , 4 ) . "\<cr>" , 'tx' ) 91call assert_equal ( ' 6 their' , getline ( '.' )) 92: 1 93" sixth match 94call feedkeys ( "/the" . repeat ( "\<C-G>" , 5 ) . "\<cr>" , 'tx' ) 95call assert_equal ( ' 7 the' , getline ( '.' )) 96: 1 97" seventh match 98call feedkeys ( "/the" . repeat ( "\<C-G>" , 6 ) . "\<cr>" , 'tx' ) 99call assert_equal ( ' 8 them' , getline ( '.' )) 100: 1 101" eighth match 102call feedkeys ( "/the" . repeat ( "\<C-G>" , 7 ) . "\<cr>" , 'tx' ) 103call assert_equal ( ' 9 these' , getline ( '.' )) 104: 1 105" back at first match 106call feedkeys ( "/the" . repeat ( "\<C-G>" , 8 ) . "\<cr>" , 'tx' ) 107call assert_equal ( ' 2 these' , getline ( '.' )) 108 109" Test 4 110" CTRL-T goes to the previous match 111set incsearch nowrapscan 112$ 113" first match 114call feedkeys ( "?the\<cr>" , 'tx' ) 115call assert_equal ( ' 9 these' , getline ( '.' )) 116$ 117" first match 118call feedkeys ( "?the\<C-G>\<cr>" , 'tx' ) 119call assert_equal ( ' 9 these' , getline ( '.' )) 120$ 121" second match 122call feedkeys ( "?the" . repeat ( "\<C-T>" , 1 ) . "\<cr>" , 'tx' ) 123call assert_equal ( ' 8 them' , getline ( '.' )) 124$ 125" last match 126call feedkeys ( "?the" . repeat ( "\<C-T>" , 7 ) . "\<cr>" , 'tx' ) 127call assert_equal ( ' 2 these' , getline ( '.' )) 128$ 129" last match 130call feedkeys ( "?the" . repeat ( "\<C-T>" , 8 ) . "\<cr>" , 'tx' ) 131call assert_equal ( ' 2 these' , getline ( '.' )) 132 133" Test 5 134" CTRL-T goes to the previous match 135set incsearch wrapscan 136$ 137" first match 138call feedkeys ( "?the\<cr>" , 'tx' ) 139call assert_equal ( ' 9 these' , getline ( '.' )) 140$ 141" first match at the top 142call feedkeys ( "?the\<C-G>\<cr>" , 'tx' ) 143call assert_equal ( ' 2 these' , getline ( '.' )) 144$ 145" second match 146call feedkeys ( "?the" . repeat ( "\<C-T>" , 1 ) . "\<cr>" , 'tx' ) 147call assert_equal ( ' 8 them' , getline ( '.' )) 148$ 149" last match 150call feedkeys ( "?the" . repeat ( "\<C-T>" , 7 ) . "\<cr>" , 'tx' ) 151call assert_equal ( ' 2 these' , getline ( '.' )) 152$ 153" back at the bottom of the buffer 154call feedkeys ( "?the" . repeat ( "\<C-T>" , 8 ) . "\<cr>" , 'tx' ) 155call assert_equal ( ' 9 these' , getline ( '.' )) 156 157" Test 6 158" CTRL-L adds to the search pattern 159set incsearch wrapscan 1601 161" first match 162call feedkeys ( "/the\<c-l>\<cr>" , 'tx' ) 163call assert_equal ( ' 2 these' , getline ( '.' )) 1641 165" go to next match of 'thes' 166call feedkeys ( "/the\<c-l>\<C-G>\<cr>" , 'tx' ) 167call assert_equal ( ' 9 these' , getline ( '.' )) 1681 169" wrap around 170call feedkeys ( "/the\<c-l>\<C-G>\<C-G>\<cr>" , 'tx' ) 171call assert_equal ( ' 2 these' , getline ( '.' )) 1721 173" wrap around 174set nowrapscan 175call feedkeys ( "/the\<c-l>\<C-G>\<C-G>\<cr>" , 'tx' ) 176call assert_equal ( ' 9 these' , getline ( '.' )) 177 178" Test 7 179" <bs> remove from match, but stay at current match 180set incsearch wrapscan 1811 182" first match 183call feedkeys ( "/thei\<cr>" , 'tx' ) 184call assert_equal ( ' 4 their' , getline ( '.' )) 1851 186" delete one char, add another 187call feedkeys ( "/thei\<bs>s\<cr>" , 'tx' ) 188call assert_equal ( ' 2 these' , getline ( '.' )) 1891 190" delete one char, add another, go to previous match, add one char 191call feedkeys ( "/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>" , 'tx' ) 192call assert_equal ( ' 9 these' , getline ( '.' )) 1931 194" delete all chars, start from the beginning again 195call feedkeys ( "/them" . repeat ( "\<bs>" , 4 ) . 'the\>' . "\<cr>" , 'tx' ) 196call assert_equal ( ' 3 the' , getline ( '.' )) 197 198" clean up 199call Ntest_override ( "char_avail" , 0 ) 200bw ! 201endfunc 202 203func Test_search_cmdline2 () 204CheckOption incsearch 205 206" need to disable char_avail, 207" so that expansion of commandline works 208call Ntest_override ( "char_avail" , 1 ) 209new 210call setline ( 1 , [ ' 1' , ' 2 these' , ' 3 the theother' ]) 211" Test 1 212" Ctrl-T goes correctly back and forth 213set incsearch 2141 215" first match 216call feedkeys ( "/the\<cr>" , 'tx' ) 217call assert_equal ( ' 2 these' , getline ( '.' )) 2181 219" go to next match (on next line) 220call feedkeys ( "/the\<C-G>\<cr>" , 'tx' ) 221call assert_equal ( ' 3 the theother' , getline ( '.' )) 2221 223" go to next match (still on line 3) 224call feedkeys ( "/the\<C-G>\<C-G>\<cr>" , 'tx' ) 225call assert_equal ( ' 3 the theother' , getline ( '.' )) 2261 227" go to next match (still on line 3) 228call feedkeys ( "/the\<C-G>\<C-G>\<C-G>\<cr>" , 'tx' ) 229call assert_equal ( ' 3 the theother' , getline ( '.' )) 2301 231" go to previous match (on line 3) 232call feedkeys ( "/the\<C-G>\<C-G>\<C-G>\<C-T>\<cr>" , 'tx' ) 233call assert_equal ( ' 3 the theother' , getline ( '.' )) 2341 235" go to previous match (on line 3) 236call feedkeys ( "/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<cr>" , 'tx' ) 237call assert_equal ( ' 3 the theother' , getline ( '.' )) 2381 239" go to previous match (on line 2) 240call feedkeys ( "/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>" , 'tx' ) 241call assert_equal ( ' 2 these' , getline ( '.' )) 2421 243" go to previous match (on line 2) 244call feedkeys ( "/the\<C-G>\<C-R>\<C-W>\<cr>" , 'tx' ) 245call assert_equal ( 'theother' , @/) 246 247" Test 2: keep the view, 248" after deleting a character from the search cmd 249call setline ( 1 , [ ' 1' , ' 2 these' , ' 3 the' , ' 4 their' , ' 5 there' , ' 6 their' , ' 7 the' , ' 8 them' , ' 9 these' , ' 10 foobar' ]) 250resize 5 2511 252call feedkeys ( "/foo\<bs>\<cr>" , 'tx' ) 253redraw 254call 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 257for i in range ( 11 ) 258call histdel ( '/' ) 259endfor 260 261" Test 3: reset the view, 262" after deleting all characters from the search cmd 263norm ! 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 273set noincsearch 274call Ntest_override ( "char_avail" , 0 ) 275bw ! 276endfunc 277 278func Test_use_sub_pat () 279split 280let @/= '' 281func X () 282s /^/a/ 283/ 284endfunc 285call X () 286bwipe ! 287endfunc 288 289func Test_searchpair () 290new 291call setline ( 1 , [ 'other code' , 'here [' , ' [' , ' " cursor here' , ' ]]' ]) 292 293" should not give an error for using "42" 294call assert_equal ( 0 , searchpair ( 'a' , 'b' , 'c' , '' , 42 )) 295 2964 297call assert_equal ( 3 , searchpair ( '\[' , '' , ']' , 'bW' )) 298call assert_equal ([ 0 , 3 , 2 , 0 ], getpos ( '.' )) 2994 300call assert_equal ( 2 , searchpair ( '\[' , '' , ']' , 'bWr' )) 301call assert_equal ([ 0 , 2 , 6 , 0 ], getpos ( '.' )) 3024 303call assert_equal ( 1 , searchpair ( '\[' , '' , ']' , 'bWm' )) 304call assert_equal ([ 0 , 3 , 2 , 0 ], getpos ( '.' )) 3054 |norm ^ 306call assert_equal ( 5 , searchpair ( '\[' , '' , ']' , 'Wn' )) 307call assert_equal ([ 0 , 4 , 2 , 0 ], getpos ( '.' )) 3084 309call assert_equal ( 2 , searchpair ( '\[' , '' , ']' , 'bW' , 310 \'getline(".") =~ "^\\s*\["' )) 311call assert_equal ([ 0 , 2 , 6 , 0 ], getpos ( '.' )) 312set nomagic 3134 314call assert_equal ( 3 , searchpair ( '\[' , '' , ']' , 'bW' )) 315call assert_equal ([ 0 , 3 , 2 , 0 ], getpos ( '.' )) 316set magic 3174 |norm ^ 318call assert_equal ( 0 , searchpair ( '{' , '' , '}' , 'bW' )) 319call assert_equal ([ 0 , 4 , 2 , 0 ], getpos ( '.' )) 320 321 %d 322call setline ( 1 , [ 'if 1' , ' if 2' , ' else' , ' endif 2' , 'endif 1' ]) 323 324/ \<if 1 325call assert_equal ( 5 , searchpair ( '\<if\>' , '\<else\>' , '\<endif\>' , 'W' )) 326call assert_equal ([ 0 , 5 , 1 , 0 ], getpos ( '.' )) 327/ \<if 2 328call assert_equal ( 3 , searchpair ( '\<if\>' , '\<else\>' , '\<endif\>' , 'W' )) 329call assert_equal ([ 0 , 3 , 3 , 0 ], getpos ( '.' )) 330 331q ! 332endfunc 333 334func Test_searchpairpos () 335new 336call setline ( 1 , [ 'other code' , 'here [' , ' [' , ' " cursor here' , ' ]]' ]) 337 3384 339call assert_equal ([ 3 , 2 ], searchpairpos ( '\[' , '' , ']' , 'bW' )) 340call assert_equal ([ 0 , 3 , 2 , 0 ], getpos ( '.' )) 3414 342call assert_equal ([ 2 , 6 ], searchpairpos ( '\[' , '' , ']' , 'bWr' )) 343call assert_equal ([ 0 , 2 , 6 , 0 ], getpos ( '.' )) 3444 |norm ^ 345call assert_equal ([ 5 , 2 ], searchpairpos ( '\[' , '' , ']' , 'Wn' )) 346call assert_equal ([ 0 , 4 , 2 , 0 ], getpos ( '.' )) 3474 348call assert_equal ([ 2 , 6 ], searchpairpos ( '\[' , '' , ']' , 'bW' , 349 \'getline(".") =~ "^\\s*\["' )) 350call assert_equal ([ 0 , 2 , 6 , 0 ], getpos ( '.' )) 3514 352call assert_equal ([ 2 , 6 ], searchpairpos ( '\[' , '' , ']' , 'bWr' )) 353call assert_equal ([ 0 , 2 , 6 , 0 ], getpos ( '.' )) 354set nomagic 3554 356call assert_equal ([ 3 , 2 ], searchpairpos ( '\[' , '' , ']' , 'bW' )) 357call assert_equal ([ 0 , 3 , 2 , 0 ], getpos ( '.' )) 358set magic 3594 |norm ^ 360call assert_equal ([ 0 , 0 ], searchpairpos ( '{' , '' , '}' , 'bW' )) 361call assert_equal ([ 0 , 4 , 2 , 0 ], getpos ( '.' )) 362 363 %d 364call setline ( 1 , [ 'if 1' , ' if 2' , ' else' , ' endif 2' , 'endif 1' ]) 365/ \<if 1 366call assert_equal ([ 5 , 1 ], searchpairpos ( '\<if\>' , '\<else\>' , '\<endif\>' , 'W' )) 367call assert_equal ([ 0 , 5 , 1 , 0 ], getpos ( '.' )) 368/ \<if 2 369call assert_equal ([ 3 , 3 ], searchpairpos ( '\<if\>' , '\<else\>' , '\<endif\>' , 'W' )) 370call assert_equal ([ 0 , 3 , 3 , 0 ], getpos ( '.' )) 371 372q ! 373endfunc 374 375func Test_searchpair_errors () 376call assert_fails ( "call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)" , 'E730: Using a List as a String' ) 377call assert_fails ( "call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)" , 'E729: Using a Funcref as a String' ) 378call assert_fails ( "call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)" , 'E731: Using a Dictionary as a String' ) 379call assert_fails ( "call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)" , 'E475: Invalid argument: flags' ) 380call assert_fails ( "call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)" , 'E475: Invalid argument: -99' ) 381call assert_fails ( "call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)" , 'E475: Invalid argument: -100' ) 382call assert_fails ( "call searchpair('start', 'middle', 'end', 'e')" , 'E475: Invalid argument: e' ) 383call assert_fails ( "call searchpair('start', 'middle', 'end', 'sn')" , 'E475: Invalid argument: sn' ) 384endfunc 385 386func Test_searchpairpos_errors () 387call assert_fails ( "call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)" , 'E730: Using a List as a String' ) 388call assert_fails ( "call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)" , 'E729: Using a Funcref as a String' ) 389call assert_fails ( "call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)" , 'E731: Using a Dictionary as a String' ) 390call assert_fails ( "call searchpairpos('start', 'middle', 'end', 'flags', 'skip', 99, 100)" , 'E475: Invalid argument: flags' ) 391call assert_fails ( "call searchpairpos('start', 'middle', 'end', 'bW', 'func', -99, 100)" , 'E475: Invalid argument: -99' ) 392call assert_fails ( "call searchpairpos('start', 'middle', 'end', 'bW', 'func', 99, -100)" , 'E475: Invalid argument: -100' ) 393call assert_fails ( "call searchpairpos('start', 'middle', 'end', 'e')" , 'E475: Invalid argument: e' ) 394call assert_fails ( "call searchpairpos('start', 'middle', 'end', 'sn')" , 'E475: Invalid argument: sn' ) 395endfunc 396 397func Test_searchpair_skip () 398func Zero () 399return 0 400endfunc 401func Partial ( x ) 402return a: x 403endfunc 404new 405call setline ( 1 , [ '{' , 'foo' , 'foo' , 'foo' , '}' ]) 4063 |call assert_equal ( 1 , searchpair ( '{' , '' , '}' , 'bWn' , '' )) 4073 |call assert_equal ( 1 , searchpair ( '{' , '' , '}' , 'bWn' , '0' )) 4083 |call assert_equal ( 1 , searchpair ( '{' , '' , '}' , 'bWn' , { ->0 })) 4093 |call assert_equal ( 1 , searchpair ( '{' , '' , '}' , 'bWn' , function ( 'Zero' ))) 4103 |call assert_equal ( 1 , searchpair ( '{' , '' , '}' , 'bWn' , function ( 'Partial' , [ 0 ]))) 411bw ! 412endfunc 413 414func Test_searchpair_leak () 415new 416call setline ( 1 , 'if one else another endif' ) 417 418" The error in the skip expression caused memory to leak. 419call assert_fails ( "call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')" , 'E15:' ) 420 421bwipe ! 422endfunc 423 424func Test_searchc () 425" These commands used to cause memory overflow in searchc(). 426new 427norm ixx 428exe "norm 0t\u93cf" 429bw ! 430endfunc 431 432func Cmdline3_prep () 433" need to disable char_avail, 434" so that expansion of commandline works 435call Ntest_override ( "char_avail" , 1 ) 436new 437call setline ( 1 , [ ' 1' , ' 2 the~e' , ' 3 the theother' ]) 438set incsearch 439endfunc 440 441func Incsearch_cleanup () 442set noincsearch 443call Ntest_override ( "char_avail" , 0 ) 444bw ! 445endfunc 446 447func Test_search_cmdline3 () 448CheckOption incsearch 449 450call Cmdline3_prep () 4511 452" first match 453call feedkeys ( "/the\<c-l>\<cr>" , 'tx' ) 454call assert_equal ( ' 2 the~e' , getline ( '.' )) 455 456call Incsearch_cleanup () 457endfunc 458 459func Test_search_cmdline3s () 460CheckOption incsearch 461 462call Cmdline3_prep () 4631 464call feedkeys ( ":%s/the\<c-l>/xxx\<cr>" , 'tx' ) 465call assert_equal ( ' 2 xxxe' , getline ( '.' )) 466undo 467call feedkeys ( ":%subs/the\<c-l>/xxx\<cr>" , 'tx' ) 468call assert_equal ( ' 2 xxxe' , getline ( '.' )) 469undo 470call feedkeys ( ":%substitute/the\<c-l>/xxx\<cr>" , 'tx' ) 471call assert_equal ( ' 2 xxxe' , getline ( '.' )) 472undo 473call feedkeys ( ":%smagic/the.e/xxx\<cr>" , 'tx' ) 474call assert_equal ( ' 2 xxx' , getline ( '.' )) 475undo 476call assert_fails ( ":%snomagic/the.e/xxx\<cr>" , 'E486' ) 477" 478call feedkeys ( ":%snomagic/the\\.e/xxx\<cr>" , 'tx' ) 479call assert_equal ( ' 2 xxx' , getline ( '.' )) 480 481call Incsearch_cleanup () 482endfunc 483 484func Test_search_cmdline3g () 485CheckOption incsearch 486 487call Cmdline3_prep () 4881 489call feedkeys ( ":g/the\<c-l>/d\<cr>" , 'tx' ) 490call assert_equal ( ' 3 the theother' , getline ( 2 )) 491undo 492call feedkeys ( ":global/the\<c-l>/d\<cr>" , 'tx' ) 493call assert_equal ( ' 3 the theother' , getline ( 2 )) 494undo 495call feedkeys ( ":g!/the\<c-l>/d\<cr>" , 'tx' ) 496call assert_equal ( 1 , line ( '$' )) 497call assert_equal ( ' 2 the~e' , getline ( 1 )) 498undo 499call feedkeys ( ":global!/the\<c-l>/d\<cr>" , 'tx' ) 500call assert_equal ( 1 , line ( '$' )) 501call assert_equal ( ' 2 the~e' , getline ( 1 )) 502 503call Incsearch_cleanup () 504endfunc 505 506func Test_search_cmdline3v () 507CheckOption incsearch 508 509call Cmdline3_prep () 5101 511call feedkeys ( ":v/the\<c-l>/d\<cr>" , 'tx' ) 512call assert_equal ( 1 , line ( '$' )) 513call assert_equal ( ' 2 the~e' , getline ( 1 )) 514undo 515call feedkeys ( ":vglobal/the\<c-l>/d\<cr>" , 'tx' ) 516call assert_equal ( 1 , line ( '$' )) 517call assert_equal ( ' 2 the~e' , getline ( 1 )) 518 519call Incsearch_cleanup () 520endfunc 521 522func Test_search_cmdline4 () 523CheckOption incsearch 524 525" need to disable char_avail, 526" so that expansion of commandline works 527call Ntest_override ( "char_avail" , 1 ) 528new 529call setline ( 1 , [ ' 1 the first' , ' 2 the second' , ' 3 the third' ]) 530set incsearch 531$ 532call feedkeys ( "?the\<c-g>\<cr>" , 'tx' ) 533call assert_equal ( ' 3 the third' , getline ( '.' )) 534$ 535call feedkeys ( "?the\<c-g>\<c-g>\<cr>" , 'tx' ) 536call assert_equal ( ' 1 the first' , getline ( '.' )) 537$ 538call feedkeys ( "?the\<c-g>\<c-g>\<c-g>\<cr>" , 'tx' ) 539call assert_equal ( ' 2 the second' , getline ( '.' )) 540$ 541call feedkeys ( "?the\<c-t>\<cr>" , 'tx' ) 542call assert_equal ( ' 1 the first' , getline ( '.' )) 543$ 544call feedkeys ( "?the\<c-t>\<c-t>\<cr>" , 'tx' ) 545call assert_equal ( ' 3 the third' , getline ( '.' )) 546$ 547call feedkeys ( "?the\<c-t>\<c-t>\<c-t>\<cr>" , 'tx' ) 548call assert_equal ( ' 2 the second' , getline ( '.' )) 549" clean up 550set noincsearch 551call Ntest_override ( "char_avail" , 0 ) 552bw ! 553endfunc 554 555func Test_search_cmdline5 () 556CheckOption incsearch 557 558" Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work 559" regardless char_avail. 560new 561call setline ( 1 , [ ' 1 the first' , ' 2 the second' , ' 3 the third' , '' ]) 562set incsearch 5631 564call feedkeys ( "/the\<c-g>\<c-g>\<cr>" , 'tx' ) 565call assert_equal ( ' 3 the third' , getline ( '.' )) 566$ 567call feedkeys ( "?the\<c-t>\<c-t>\<c-t>\<cr>" , 'tx' ) 568call assert_equal ( ' 1 the first' , getline ( '.' )) 569" clean up 570set noincsearch 571bw ! 572endfunc 573 574func Test_search_cmdline6 () 575" Test that consecutive matches 576" are caught by <c-g>/<c-t> 577CheckOption incsearch 578 579" need to disable char_avail, 580" so that expansion of commandline works 581call Ntest_override ( "char_avail" , 1 ) 582new 583call setline ( 1 , [ ' bbvimb' , '' ]) 584set incsearch 585" first match 586norm ! gg0 587call feedkeys ( "/b\<cr>" , 'tx' ) 588call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 589" second match 590norm ! gg0 591call feedkeys ( "/b\<c-g>\<cr>" , 'tx' ) 592call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 593" third match 594norm ! gg0 595call feedkeys ( "/b\<c-g>\<c-g>\<cr>" , 'tx' ) 596call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 597" first match again 598norm ! gg0 599call feedkeys ( "/b\<c-g>\<c-g>\<c-g>\<cr>" , 'tx' ) 600call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 601set nowrapscan 602" last match 603norm ! gg0 604call feedkeys ( "/b\<c-g>\<c-g>\<c-g>\<cr>" , 'tx' ) 605call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 606" clean up 607set wrapscan & vim 608set noincsearch 609call Ntest_override ( "char_avail" , 0 ) 610bw ! 611endfunc 612 613func Test_search_cmdline7 () 614" Test that pressing <c-g> in an empty command line 615" does not move the cursor 616if ! exists ( '+incsearch' ) 617return 618endif 619" need to disable char_avail, 620" so that expansion of commandline works 621call Ntest_override ( "char_avail" , 1 ) 622new 623let @/= 'b' 624call setline ( 1 , [ ' bbvimb' , '' ]) 625set incsearch 626" first match 627norm ! gg0 628" moves to next match of previous search pattern, just like /<cr> 629call feedkeys ( "/\<c-g>\<cr>" , 'tx' ) 630call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 631" moves to next match of previous search pattern, just like /<cr> 632call feedkeys ( "/\<cr>" , 'tx' ) 633call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 634" moves to next match of previous search pattern, just like /<cr> 635call feedkeys ( "/\<c-t>\<cr>" , 'tx' ) 636call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 637 638" using an offset uses the last search pattern 639call cursor ( 1 , 1 ) 640call setline ( 1 , [ '1 bbvimb' , ' 2 bbvimb' ]) 641let @/= 'b' 642call feedkeys ( "//e\<c-g>\<cr>" , 'tx' ) 643call assert_equal ( '1 bbvimb' , getline ( '.' )) 644call assert_equal ( 4 , col ( '.' )) 645call cursor ( 1 , 1 ) 646call feedkeys ( "//+1\<c-g>\<cr>" , 'tx' ) 647call assert_equal ( ' 2 bbvimb' , getline ( '.' )) 648call assert_equal ([ 0 , 2 , 1 , 0 ], getpos ( '.' )) 649call setline ( 1 , [ 'blah blah blah' ]) 650call feedkeys ( "gg0/blah/e\<c-g>\<cr>" , 'tx' ) 651call assert_equal ([ 0 , 1 , 9 , 0 ], getpos ( '.' )) 652call feedkeys ( "gg0/blah/e\<c-g>\<c-g>\<cr>" , 'tx' ) 653call assert_equal ([ 0 , 1 , 14 , 0 ], getpos ( '.' )) 654call feedkeys ( "gg0/blah/e\<c-g>\<c-g>\<c-t>\<cr>" , 'tx' ) 655call assert_equal ([ 0 , 1 , 9 , 0 ], getpos ( '.' )) 656call cursor ( 1 , col ( '$' )) 657call feedkeys ( "?blah?e\<c-g>\<cr>" , 'tx' ) 658call assert_equal ([ 0 , 1 , 9 , 0 ], getpos ( '.' )) 659call feedkeys ( "gg0/blah/e+1\<c-g>\<cr>" , 'tx' ) 660call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( '.' )) 661call feedkeys ( "gg0/blah/e-2\<c-g>\<cr>" , 'tx' ) 662call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 663call setline ( 1 , [ 'a/b a/b a/b' ]) 664call feedkeys ( "gg0/a\\/b/e\<c-g>\<cr>" , 'tx' ) 665call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 666 667set noincsearch 668call Ntest_override ( "char_avail" , 0 ) 669bw ! 670endfunc 671 672func Test_search_cmdline8 () 673" Highlighting is cleared in all windows 674" since hls applies to all windows 675CheckOption incsearch 676CheckFeature terminal 677CheckNotGui 678if has ( "win32" ) 679throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" 680endif 681 682let h = winheight ( 0 ) 683if h < 3 684return 685endif 686" Prepare buffer text 687let lines = [ 'abb vim vim vi' , 'vimvivim' ] 688call writefile ( lines , 'Xsearch.txt' , 'D' ) 689let buf = term_start ([ GetVimProg (), '--clean' , '-c' , 'set noswapfile' , 'Xsearch.txt' ], { 'term_rows' : 3 }) 690 691call WaitForAssert ({ ->assert_equal ( lines , [ term_getline ( buf , 1 ), term_getline ( buf , 2 )])}) 692 693call term_sendkeys ( buf , ":set incsearch hlsearch\<cr>" ) 694call term_sendkeys ( buf , ":14vsp\<cr>" ) 695call term_sendkeys ( buf , "/vim\<cr>" ) 696call term_sendkeys ( buf , "/b\<esc>" ) 697call term_sendkeys ( buf , "gg0" ) 698call TermWait ( buf , 250 ) 699let screen_line = term_scrape ( buf , 1 ) 700let [ a0 , a1 , a2 , a3 ] = [ screen_line [ 3 ]. attr , screen_line [ 4 ]. attr , 701 \screen_line [ 18 ]. attr , screen_line [ 19 ]. attr ] 702call assert_notequal ( a0 , a1 ) 703call assert_notequal ( a0 , a3 ) 704call assert_notequal ( a1 , a2 ) 705call assert_equal ( a0 , a2 ) 706call assert_equal ( a1 , a3 ) 707 708" clean up 709bwipe ! 710endfunc 711 712" Tests for regexp with various magic settings 713func Run_search_regexp_magic_opt () 714put ='1 a aa abb abbccc' 715exe 'normal! /a*b\{2}c\+/e' . "\<CR>" 716call assert_equal ([ 0 , 2 , 17 , 0 ], getpos ( '.' )) 717 718put ='2 d dd dee deefff' 719exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" 720call assert_equal ([ 0 , 3 , 17 , 0 ], getpos ( '.' )) 721 722set nomagic 723put ='3 g gg ghh ghhiii' 724exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" 725call assert_equal ([ 0 , 4 , 17 , 0 ], getpos ( '.' )) 726 727put ='4 j jj jkk jkklll' 728exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" 729call assert_equal ([ 0 , 5 , 17 , 0 ], getpos ( '.' )) 730 731put ='5 m mm mnn mnnooo' 732exe 'normal! /\vm*n{2}o+/e' . "\<CR>" 733call assert_equal ([ 0 , 6 , 17 , 0 ], getpos ( '.' )) 734 735put ='6 x ^aa$ x' 736exe 'normal! /\V^aa$' . "\<CR>" 737call assert_equal ([ 0 , 7 , 5 , 0 ], getpos ( '.' )) 738 739set magic 740put ='7 (a)(b) abbaa' 741exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" 742call assert_equal ([ 0 , 8 , 14 , 0 ], getpos ( '.' )) 743 744put ='8 axx [ab]xx' 745exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" 746call assert_equal ([ 0 , 9 , 7 , 0 ], getpos ( '.' )) 747 748 %d 749endfunc 750 751func Test_search_regexp () 752enew ! 753 754set regexpengine = 1 755call Run_search_regexp_magic_opt () 756set regexpengine = 2 757call Run_search_regexp_magic_opt () 758set regexpengine & 759 760set undolevels = 100 761put ='9 foobar' 762put ='' 763exe "normal! a\<C-G>u\<Esc>" 764normal G 765exe 'normal! dv?bar?' . "\<CR>" 766call assert_equal ( '9 foo' , getline ( '.' )) 767call assert_equal ([ 0 , 2 , 5 , 0 ], getpos ( '.' )) 768call assert_equal ( 2 , line ( '$' )) 769normal u 770" Nvim: undo restores the cursor to where "dv?bar?" started. 771call assert_equal ( '9 foobar' , getline ( 2 )) 772call assert_equal ([ 0 , 3 , 1 , 0 ], getpos ( '.' )) 773call assert_equal ( 3 , line ( '$' )) 774 775set undolevels & 776enew ! 777endfunc 778 779func Test_search_cmdline_incsearch_highlight () 780CheckOption incsearch 781 782set incsearch hlsearch 783" need to disable char_avail, 784" so that expansion of commandline works 785call Ntest_override ( "char_avail" , 1 ) 786new 787call setline ( 1 , [ 'aaa 1 the first' , ' 2 the second' , ' 3 the third' ]) 788 7891 790call feedkeys ( "/second\<cr>" , 'tx' ) 791call assert_equal ( 'second' , @/) 792call assert_equal ( ' 2 the second' , getline ( '.' )) 793 794" Canceling search won't change @/ 7951 796let @/= 'last pattern' 797call feedkeys ( "/third\<C-c>" , 'tx' ) 798call assert_equal ( 'last pattern' , @/) 799call feedkeys ( "/third\<Esc>" , 'tx' ) 800call assert_equal ( 'last pattern' , @/) 801call feedkeys ( "/3\<bs>\<bs>" , 'tx' ) 802call assert_equal ( 'last pattern' , @/) 803call feedkeys ( "/third\<c-g>\<c-t>\<Esc>" , 'tx' ) 804call assert_equal ( 'last pattern' , @/) 805 806" clean up 807set noincsearch nohlsearch 808call Ntest_override ( "char_avail" , 0 ) 809bw ! 810endfunc 811 812func Test_search_cmdline_incsearch_highlight_attr () 813CheckOption incsearch 814CheckFeature terminal 815CheckNotGui 816 817let h = winheight ( 0 ) 818if h < 3 819return 820endif 821 822" Prepare buffer text 823let lines = [ 'abb vim vim vi' , 'vimvivim' ] 824call writefile ( lines , 'Xsearch.txt' , 'D' ) 825let buf = term_start ([ GetVimProg (), '--clean' , '-c' , 'set noswapfile' , 'Xsearch.txt' ], { 'term_rows' : 3 }) 826 827call WaitForAssert ({ ->assert_equal ( lines , [ term_getline ( buf , 1 ), term_getline ( buf , 2 )])}) 828" wait for vim to complete initialization 829call TermWait ( buf ) 830 831" Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight 832call term_sendkeys ( buf , ":set incsearch hlsearch\<cr>" ) 833call term_sendkeys ( buf , '/b' ) 834call TermWait ( buf , 100 ) 835let screen_line1 = term_scrape ( buf , 1 ) 836call assert_true ( len ( screen_line1 ) > 2 ) 837" a0: attr_normal 838let a0 = screen_line1 [ 0 ]. attr 839" a1: attr_incsearch 840let a1 = screen_line1 [ 1 ]. attr 841" a2: attr_hlsearch 842let a2 = screen_line1 [ 2 ]. attr 843call assert_notequal ( a0 , a1 ) 844call assert_notequal ( a0 , a2 ) 845call assert_notequal ( a1 , a2 ) 846call term_sendkeys ( buf , "\<cr>gg0" ) 847 848" Test incremental highlight search 849call term_sendkeys ( buf , "/vim" ) 850call TermWait ( buf , 100 ) 851" Buffer: 852" abb vim vim vi 853" vimvivim 854" Search: /vim 855let attr_line1 = [ a0 , a0 , a0 , a0 , a1 , a1 , a1 , a0 , a2 , a2 , a2 , a0 , a0 , a0 ] 856let attr_line2 = [ a2 , a2 , a2 , a0 , a0 , a2 , a2 , a2 ] 857call assert_equal ( attr_line1 , map ( term_scrape ( buf , 1 )[: len ( attr_line1 ) - 1 ], 'v:val.attr' )) 858call assert_equal ( attr_line2 , map ( term_scrape ( buf , 2 )[: len ( attr_line2 ) - 1 ], 'v:val.attr' )) 859 860" Test <C-g> 861call term_sendkeys ( buf , "\<C-g>\<C-g>" ) 862call TermWait ( buf , 100 ) 863let attr_line1 = [ a0 , a0 , a0 , a0 , a2 , a2 , a2 , a0 , a2 , a2 , a2 , a0 , a0 , a0 ] 864let attr_line2 = [ a1 , a1 , a1 , a0 , a0 , a2 , a2 , a2 ] 865call assert_equal ( attr_line1 , map ( term_scrape ( buf , 1 )[: len ( attr_line1 ) - 1 ], 'v:val.attr' )) 866call assert_equal ( attr_line2 , map ( term_scrape ( buf , 2 )[: len ( attr_line2 ) - 1 ], 'v:val.attr' )) 867 868" Test <C-t> 869call term_sendkeys ( buf , "\<C-t>" ) 870call TermWait ( buf , 100 ) 871let attr_line1 = [ a0 , a0 , a0 , a0 , a2 , a2 , a2 , a0 , a1 , a1 , a1 , a0 , a0 , a0 ] 872let attr_line2 = [ a2 , a2 , a2 , a0 , a0 , a2 , a2 , a2 ] 873call assert_equal ( attr_line1 , map ( term_scrape ( buf , 1 )[: len ( attr_line1 ) - 1 ], 'v:val.attr' )) 874call assert_equal ( attr_line2 , map ( term_scrape ( buf , 2 )[: len ( attr_line2 ) - 1 ], 'v:val.attr' )) 875 876" Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) 877call term_sendkeys ( buf , "\<cr>" ) 878call TermWait ( buf , 100 ) 879let attr_line1 = [ a0 , a0 , a0 , a0 , a2 , a2 , a2 , a0 , a2 , a2 , a2 , a0 , a0 , a0 ] 880let attr_line2 = [ a2 , a2 , a2 , a0 , a0 , a2 , a2 , a2 ] 881call assert_equal ( attr_line1 , map ( term_scrape ( buf , 1 )[: len ( attr_line1 ) - 1 ], 'v:val.attr' )) 882call assert_equal ( attr_line2 , map ( term_scrape ( buf , 2 )[: len ( attr_line2 ) - 1 ], 'v:val.attr' )) 883 884" Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) 885call term_sendkeys ( buf , ":1\<cr>" ) 886call term_sendkeys ( buf , ":set nohlsearch\<cr>" ) 887call term_sendkeys ( buf , "/vim" ) 888call TermWait ( buf , 100 ) 889let attr_line1 = [ a0 , a0 , a0 , a0 , a1 , a1 , a1 , a0 , a0 , a0 , a0 , a0 , a0 , a0 ] 890let attr_line2 = [ a0 , a0 , a0 , a0 , a0 , a0 , a0 , a0 ] 891call assert_equal ( attr_line1 , map ( term_scrape ( buf , 1 )[: len ( attr_line1 ) - 1 ], 'v:val.attr' )) 892call assert_equal ( attr_line2 , map ( term_scrape ( buf , 2 )[: len ( attr_line2 ) - 1 ], 'v:val.attr' )) 893 894bwipe ! 895endfunc 896 897func Test_incsearch_cmdline_modifier () 898CheckOption incsearch 899 900call Ntest_override ( "char_avail" , 1 ) 901new 902call setline ( 1 , [ 'foo' ]) 903set incsearch 904" Test that error E14 does not occur in parsing command modifier. 905call feedkeys ( "V:tab" , 'tx' ) 906 907call Incsearch_cleanup () 908endfunc 909 910func Test_incsearch_scrolling () 911CheckScreendump 912CheckRunVimInTerminal 913call assert_equal ( 0 , & scrolloff ) 914call writefile ([ 915 \'let dots = repeat(".", 120)' , 916 \'set incsearch cmdheight=2 scrolloff=0' , 917 \'call setline(1, [dots, dots, dots, "", "target", dots, dots])' , 918 \'normal gg' , 919 \'redraw' , 920 \], 'Xscript' , 'D' ) 921let buf = RunVimInTerminal ( '-S Xscript' , { 'rows' : 9 , 'cols' : 70 }) 922" Need to send one key at a time to force a redraw 923call term_sendkeys ( buf , '/' ) 924sleep 100m 925call term_sendkeys ( buf , 't' ) 926sleep 100m 927call term_sendkeys ( buf , 'a' ) 928sleep 100m 929call term_sendkeys ( buf , 'r' ) 930sleep 100m 931call term_sendkeys ( buf , 'g' ) 932call VerifyScreenDump ( buf , 'Test_incsearch_scrolling_01' , {}) 933 934call term_sendkeys ( buf , "\<Esc>" ) 935call StopVimInTerminal ( buf ) 936endfunc 937 938func Test_incsearch_search_dump () 939CheckOption incsearch 940CheckScreendump 941 942call writefile ([ 943 \'set incsearch hlsearch scrolloff=0' , 944 \'for n in range(1, 8)' , 945 \' call setline(n, "foo " . n)' , 946 \'endfor' , 947 \'3' , 948 \], 'Xis_search_script' , 'D' ) 949let buf = RunVimInTerminal ( '-S Xis_search_script' , { 'rows' : 9 , 'cols' : 70 }) 950" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 951" the 'ambiwidth' check. 952sleep 100m 953 954" Need to send one key at a time to force a redraw. 955call term_sendkeys ( buf , '/fo' ) 956call VerifyScreenDump ( buf , 'Test_incsearch_search_01' , {}) 957call term_sendkeys ( buf , "\<Esc>" ) 958sleep 100m 959 960call term_sendkeys ( buf , '/\v' ) 961call VerifyScreenDump ( buf , 'Test_incsearch_search_02' , {}) 962call term_sendkeys ( buf , "\<Esc>" ) 963 964call StopVimInTerminal ( buf ) 965endfunc 966 967func Test_hlsearch_dump () 968CheckOption hlsearch 969CheckScreendump 970 971call writefile ([ 972 \'set hlsearch cursorline' , 973 \'call setline(1, ["xxx", "xxx", "xxx"])' , 974 \'/.*' , 975 \'2' , 976 \], 'Xhlsearch_script' , 'D' ) 977let buf = RunVimInTerminal ( '-S Xhlsearch_script' , { 'rows' : 6 , 'cols' : 50 }) 978call VerifyScreenDump ( buf , 'Test_hlsearch_1' , {}) 979 980call term_sendkeys ( buf , "/\\_.*\<CR>" ) 981call VerifyScreenDump ( buf , 'Test_hlsearch_2' , {}) 982 983call StopVimInTerminal ( buf ) 984endfunc 985 986func Test_hlsearch_and_visual () 987CheckOption hlsearch 988CheckScreendump 989 990call writefile ([ 991 \'set hlsearch' , 992 \'call setline(1, repeat(["xxx yyy zzz"], 3))' , 993 \'hi Search cterm=bold' , 994 \'/yyy' , 995 \'call cursor(1, 6)' , 996 \], 'Xhlvisual_script' , 'D' ) 997let buf = RunVimInTerminal ( '-S Xhlvisual_script' , { 'rows' : 6 , 'cols' : 40 }) 998call term_sendkeys ( buf , "vjj" ) 999call WaitForAssert ({ ->assert_match ( 'VISUAL.*-\d' , term_getline ( buf , 6 ))}, 1000 ) 1000call VerifyScreenDump ( buf , 'Test_hlsearch_visual_1' , {}) 1001call term_sendkeys ( buf , "\<Esc>" ) 1002 1003call StopVimInTerminal ( buf ) 1004endfunc 1005 1006func Test_hlsearch_block_visual_match () 1007CheckScreendump 1008 1009let lines =<< trim END 1010set hlsearch 1011call setline(1, ['aa', 'bbbb', 'cccccc']) 1012END 1013call writefile ( lines , 'Xhlsearch_block' , 'D' ) 1014let buf = RunVimInTerminal ( '-S Xhlsearch_block' , { 'rows' : 9 , 'cols' : 60 }) 1015 1016call term_sendkeys ( buf , "G\<C-V>$kk\<Esc>" ) 1017sleep 100m 1018call term_sendkeys ( buf , "/\\%V\<CR>" ) 1019sleep 100m 1020call VerifyScreenDump ( buf , 'Test_hlsearch_block_visual_match' , {}) 1021 1022call StopVimInTerminal ( buf ) 1023endfunc 1024 1025func Test_incsearch_substitute () 1026CheckOption incsearch 1027 1028call Ntest_override ( "char_avail" , 1 ) 1029new 1030set incsearch 1031for n in range ( 1 , 10 ) 1032call setline ( n , 'foo ' . n ) 1033endfor 10344 1035call feedkeys ( ":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>" , 'tx' ) 1036call assert_equal ( 'foo 3' , getline ( 3 )) 1037call assert_equal ( 'xxx 4' , getline ( 4 )) 1038call assert_equal ( 'xxx 5' , getline ( 5 )) 1039call assert_equal ( 'xxx 6' , getline ( 6 )) 1040call assert_equal ( 'foo 7' , getline ( 7 )) 1041 1042call Incsearch_cleanup () 1043endfunc 1044 1045func Test_incsearch_substitute_long_line () 1046new 1047call Ntest_override ( "char_avail" , 1 ) 1048set incsearch 1049 1050call repeat ( 'x' , 100000 ) ->setline ( 1 ) 1051call feedkeys ( ':s/\%c' , 'xt' ) 1052redraw 1053call feedkeys ( "\<Esc>" , 'xt' ) 1054 1055call Incsearch_cleanup () 1056bwipe ! 1057endfunc 1058 1059func Test_hlsearch_cursearch () 1060CheckScreendump 1061 1062let lines =<< trim END 1063set hlsearch scrolloff=0 1064call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar']) 1065hi Search ctermbg=yellow 1066hi CurSearch ctermbg=blue 1067END 1068call writefile ( lines , 'Xhlsearch_cursearch' , 'D' ) 1069let buf = RunVimInTerminal ( '-S Xhlsearch_cursearch' , { 'rows' : 9 , 'cols' : 60 }) 1070 1071call term_sendkeys ( buf , "gg/foo\<CR>" ) 1072call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_single_line_1' , {}) 1073 1074call term_sendkeys ( buf , "n" ) 1075call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_single_line_2' , {}) 1076 1077call term_sendkeys ( buf , "n" ) 1078call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_single_line_2a' , {}) 1079 1080call term_sendkeys ( buf , "n" ) 1081call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_single_line_2b' , {}) 1082 1083call term_sendkeys ( buf , ":call setline(5, 'foo')\<CR>" ) 1084call term_sendkeys ( buf , "0?\<CR>" ) 1085call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_single_line_3' , {}) 1086 1087call term_sendkeys ( buf , "gg/foo\\nbar\<CR>" ) 1088call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_multiple_line_1' , {}) 1089 1090call term_sendkeys ( buf , ":call setline(1, ['---', 'abcdefg', 'hijkl', '---', 'abcdefg', 'hijkl'])\<CR>" ) 1091call term_sendkeys ( buf , "gg/efg\\nhij\<CR>" ) 1092call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_multiple_line_2' , {}) 1093call term_sendkeys ( buf , "h\<C-L>" ) 1094call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_multiple_line_3' , {}) 1095call term_sendkeys ( buf , "j\<C-L>" ) 1096call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_multiple_line_4' , {}) 1097call term_sendkeys ( buf , "h\<C-L>" ) 1098call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_multiple_line_5' , {}) 1099 1100" check clearing CurSearch when using it for another match 1101call term_sendkeys ( buf , "G?^abcd\<CR>Y" ) 1102call term_sendkeys ( buf , "kkP" ) 1103call VerifyScreenDump ( buf , 'Test_hlsearch_cursearch_changed_1' , {}) 1104 1105call StopVimInTerminal ( buf ) 1106endfunc 1107 1108" Similar to Test_incsearch_substitute() but with a screendump halfway. 1109func Test_incsearch_substitute_dump () 1110CheckOption incsearch 1111CheckScreendump 1112 1113call writefile ([ 1114 \'set incsearch hlsearch scrolloff=0' , 1115 \'for n in range(1, 10)' , 1116 \' call setline(n, "foo " . n)' , 1117 \'endfor' , 1118 \'call setline(11, "bar 11")' , 1119 \'3' , 1120 \], 'Xis_subst_script' , 'D' ) 1121let buf = RunVimInTerminal ( '-S Xis_subst_script' , { 'rows' : 9 , 'cols' : 70 }) 1122" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1123" the 'ambiwidth' check. 1124sleep 100m 1125 1126" Need to send one key at a time to force a redraw. 1127" Select three lines at the cursor with typed pattern. 1128call term_sendkeys ( buf , ':.,.+2s/' ) 1129sleep 100m 1130call term_sendkeys ( buf , 'f' ) 1131sleep 100m 1132call term_sendkeys ( buf , 'o' ) 1133sleep 100m 1134call term_sendkeys ( buf , 'o' ) 1135call VerifyScreenDump ( buf , 'Test_incsearch_substitute_01' , {}) 1136call term_sendkeys ( buf , "\<Esc>" ) 1137 1138" Select three lines at the cursor using previous pattern. 1139call term_sendkeys ( buf , "/foo\<CR>" ) 1140sleep 100m 1141call term_sendkeys ( buf , ':.,.+2s//' ) 1142call VerifyScreenDump ( buf , 'Test_incsearch_substitute_02' , {}) 1143 1144" Deleting last slash should remove the match. 1145call term_sendkeys ( buf , "\<BS>" ) 1146call VerifyScreenDump ( buf , 'Test_incsearch_substitute_03' , {}) 1147call term_sendkeys ( buf , "\<Esc>" ) 1148 1149" Reverse range is accepted 1150call term_sendkeys ( buf , ':5,2s/foo' ) 1151call VerifyScreenDump ( buf , 'Test_incsearch_substitute_04' , {}) 1152call term_sendkeys ( buf , "\<Esc>" ) 1153 1154" White space after the command is skipped 1155call term_sendkeys ( buf , ':2,3sub /fo' ) 1156call VerifyScreenDump ( buf , 'Test_incsearch_substitute_05' , {}) 1157call term_sendkeys ( buf , "\<Esc>" ) 1158 1159" Command modifiers are skipped 1160call 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.' ) 1161call VerifyScreenDump ( buf , 'Test_incsearch_substitute_06' , {}) 1162call term_sendkeys ( buf , "\<Esc>" ) 1163 1164" Cursorline highlighting at match 1165call term_sendkeys ( buf , ":set cursorline\<CR>" ) 1166call term_sendkeys ( buf , 'G9G' ) 1167call term_sendkeys ( buf , ':9,11s/bar' ) 1168call VerifyScreenDump ( buf , 'Test_incsearch_substitute_07' , {}) 1169call term_sendkeys ( buf , "\<Esc>" ) 1170 1171" Cursorline highlighting at cursor when no match 1172call term_sendkeys ( buf , ':9,10s/bar' ) 1173call VerifyScreenDump ( buf , 'Test_incsearch_substitute_08' , {}) 1174call term_sendkeys ( buf , "\<Esc>" ) 1175 1176" Only \v handled as empty pattern, does not move cursor 1177call term_sendkeys ( buf , '3G4G' ) 1178call term_sendkeys ( buf , ":nohlsearch\<CR>" ) 1179call term_sendkeys ( buf , ':6,7s/\v' ) 1180call VerifyScreenDump ( buf , 'Test_incsearch_substitute_09' , {}) 1181call term_sendkeys ( buf , "\<Esc>" ) 1182 1183call term_sendkeys ( buf , ":set nocursorline\<CR>" ) 1184 1185" All matches are highlighted for 'hlsearch' after the incsearch canceled 1186call term_sendkeys ( buf , "1G*" ) 1187call term_sendkeys ( buf , ":2,5s/foo" ) 1188sleep 100m 1189call term_sendkeys ( buf , "\<Esc>" ) 1190call VerifyScreenDump ( buf , 'Test_incsearch_substitute_10' , {}) 1191 1192call term_sendkeys ( buf , ":split\<CR>" ) 1193call term_sendkeys ( buf , ":let @/ = 'xyz'\<CR>" ) 1194call term_sendkeys ( buf , ":%s/." ) 1195call VerifyScreenDump ( buf , 'Test_incsearch_substitute_11' , {}) 1196call term_sendkeys ( buf , "\<BS>" ) 1197call VerifyScreenDump ( buf , 'Test_incsearch_substitute_12' , {}) 1198call term_sendkeys ( buf , "\<Esc>" ) 1199call VerifyScreenDump ( buf , 'Test_incsearch_substitute_13' , {}) 1200call term_sendkeys ( buf , ":%bwipe!\<CR>" ) 1201call term_sendkeys ( buf , ":only!\<CR>" ) 1202 1203" get :'<,'>s command in history 1204call term_sendkeys ( buf , ":set cmdheight=2\<CR>" ) 1205call term_sendkeys ( buf , "aasdfasdf\<Esc>" ) 1206call term_sendkeys ( buf , "V:s/a/b/g\<CR>" ) 1207" Using '<,'> does not give E20 1208call term_sendkeys ( buf , ":new\<CR>" ) 1209call term_sendkeys ( buf , "aasdfasdf\<Esc>" ) 1210call term_sendkeys ( buf , ":\<Up>\<Up>" ) 1211call VerifyScreenDump ( buf , 'Test_incsearch_substitute_14' , {}) 1212call term_sendkeys ( buf , "<Esc>" ) 1213 1214call StopVimInTerminal ( buf ) 1215endfunc 1216 1217func Test_incsearch_highlighting () 1218CheckOption incsearch 1219CheckScreendump 1220 1221call writefile ([ 1222 \'set incsearch hlsearch' , 1223 \'call setline(1, "hello/there")' , 1224 \], 'Xis_subst_hl_script' , 'D' ) 1225let buf = RunVimInTerminal ( '-S Xis_subst_hl_script' , { 'rows' : 4 , 'cols' : 20 }) 1226" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1227" the 'ambiwidth' check. 1228sleep 300m 1229 1230" Using a different search delimiter should still highlight matches 1231" that contain a '/'. 1232call term_sendkeys ( buf , ":%s;ello/the" ) 1233call VerifyScreenDump ( buf , 'Test_incsearch_substitute_15' , {}) 1234call term_sendkeys ( buf , "<Esc>" ) 1235 1236call StopVimInTerminal ( buf ) 1237endfunc 1238 1239func Test_incsearch_with_change () 1240CheckFeature timers 1241CheckOption incsearch 1242CheckScreendump 1243 1244call writefile ([ 1245 \'set incsearch hlsearch scrolloff=0' , 1246 \'call setline(1, ["one", "two ------ X", "three"])' , 1247 \'call timer_start(200, { _ -> setline(2, "x")})' , 1248 \], 'Xis_change_script' , 'D' ) 1249let buf = RunVimInTerminal ( '-S Xis_change_script' , { 'rows' : 9 , 'cols' : 70 }) 1250" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1251" the 'ambiwidth' check. 1252sleep 300m 1253 1254" Highlight X, it will be deleted by the timer callback. 1255call term_sendkeys ( buf , ':%s/X' ) 1256call VerifyScreenDump ( buf , 'Test_incsearch_change_01' , {}) 1257call term_sendkeys ( buf , "\<Esc>" ) 1258 1259call StopVimInTerminal ( buf ) 1260endfunc 1261 1262" Similar to Test_incsearch_substitute_dump() for :sort 1263func Test_incsearch_sort_dump () 1264CheckOption incsearch 1265CheckScreendump 1266 1267call writefile ([ 1268 \'set incsearch hlsearch scrolloff=0' , 1269 \'call setline(1, ["another one 2", "that one 3", "the one 1"])' , 1270 \], 'Xis_sort_script' , 'D' ) 1271let buf = RunVimInTerminal ( '-S Xis_sort_script' , { 'rows' : 9 , 'cols' : 70 }) 1272" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1273" the 'ambiwidth' check. 1274sleep 100m 1275 1276call term_sendkeys ( buf , ':sort ni u /on' ) 1277call VerifyScreenDump ( buf , 'Test_incsearch_sort_01' , {}) 1278call term_sendkeys ( buf , "\<Esc>" ) 1279 1280call term_sendkeys ( buf , ':sort! /on' ) 1281call VerifyScreenDump ( buf , 'Test_incsearch_sort_02' , {}) 1282call term_sendkeys ( buf , "\<Esc>" ) 1283 1284call StopVimInTerminal ( buf ) 1285endfunc 1286 1287" Similar to Test_incsearch_sort_dump() for :uniq 1288func Test_incsearch_uniq_dump () 1289CheckOption incsearch 1290CheckScreendump 1291 1292call writefile ([ 1293 \'set incsearch hlsearch scrolloff=0' , 1294 \'call setline(1, ["another one 2", "that one 3", "the one 1"])' , 1295 \], 'Xis_uniq_script' , 'D' ) 1296let buf = RunVimInTerminal ( '-S Xis_uniq_script' , { 'rows' : 9 , 'cols' : 70 }) 1297" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1298" the 'ambiwidth' check. 1299sleep 100m 1300 1301call term_sendkeys ( buf , ':uniq /on' ) 1302call VerifyScreenDump ( buf , 'Test_incsearch_uniq_01' , {}) 1303call term_sendkeys ( buf , "\<Esc>" ) 1304 1305call term_sendkeys ( buf , ':uniq! /on' ) 1306call VerifyScreenDump ( buf , 'Test_incsearch_uniq_02' , {}) 1307call term_sendkeys ( buf , "\<Esc>" ) 1308 1309call StopVimInTerminal ( buf ) 1310endfunc 1311 1312" Similar to Test_incsearch_substitute_dump() for :vimgrep famiry 1313func Test_incsearch_vimgrep_dump () 1314CheckOption incsearch 1315CheckScreendump 1316 1317call writefile ([ 1318 \'set incsearch hlsearch scrolloff=0' , 1319 \'call setline(1, ["another one 2", "that one 3", "the one 1"])' , 1320 \], 'Xis_vimgrep_script' , 'D' ) 1321let buf = RunVimInTerminal ( '-S Xis_vimgrep_script' , { 'rows' : 9 , 'cols' : 70 }) 1322" Give Vim a chance to redraw to get rid of the spaces in line 2 caused by 1323" the 'ambiwidth' check. 1324sleep 100m 1325 1326" Need to send one key at a time to force a redraw. 1327call term_sendkeys ( buf , ':vimgrep on' ) 1328call VerifyScreenDump ( buf , 'Test_incsearch_vimgrep_01' , {}) 1329call term_sendkeys ( buf , "\<Esc>" ) 1330 1331call term_sendkeys ( buf , ':vimg /on/ *.txt' ) 1332call VerifyScreenDump ( buf , 'Test_incsearch_vimgrep_02' , {}) 1333call term_sendkeys ( buf , "\<Esc>" ) 1334 1335call term_sendkeys ( buf , ':vimgrepadd "\<on' ) 1336call VerifyScreenDump ( buf , 'Test_incsearch_vimgrep_03' , {}) 1337call term_sendkeys ( buf , "\<Esc>" ) 1338 1339call term_sendkeys ( buf , ':lv "tha' ) 1340call VerifyScreenDump ( buf , 'Test_incsearch_vimgrep_04' , {}) 1341call term_sendkeys ( buf , "\<Esc>" ) 1342 1343call term_sendkeys ( buf , ':lvimgrepa "the" **/*.txt' ) 1344call VerifyScreenDump ( buf , 'Test_incsearch_vimgrep_05' , {}) 1345call term_sendkeys ( buf , "\<Esc>" ) 1346 1347call StopVimInTerminal ( buf ) 1348endfunc 1349 1350func Test_keep_last_search_pattern () 1351CheckOption incsearch 1352 1353new 1354call setline ( 1 , [ 'foo' , 'foo' , 'foo' ]) 1355set incsearch 1356call Ntest_override ( "char_avail" , 1 ) 1357let @/= 'bar' 1358call feedkeys ( ":/foo/s//\<Esc>" , 'ntx' ) 1359call assert_equal ( 'bar' , @/) 1360 1361" no error message if pattern not found 1362call feedkeys ( ":/xyz/s//\<Esc>" , 'ntx' ) 1363call assert_equal ( 'bar' , @/) 1364 1365bwipe ! 1366call Ntest_override ( "ALL" , 0 ) 1367set noincsearch 1368endfunc 1369 1370func Test_word_under_cursor_after_match () 1371CheckOption incsearch 1372 1373new 1374call setline ( 1 , 'foo bar' ) 1375set incsearch 1376call Ntest_override ( "char_avail" , 1 ) 1377try 1378call feedkeys ( "/foo\<C-R>\<C-W>\<CR>" , 'ntx' ) 1379catch /E486:/ 1380endtry 1381call assert_equal ( 'foobar' , @/) 1382 1383bwipe ! 1384call Ntest_override ( "ALL" , 0 ) 1385set noincsearch 1386endfunc 1387 1388func Test_subst_word_under_cursor () 1389CheckOption incsearch 1390 1391new 1392call setline ( 1 , [ 'int SomeLongName;' , 'for (xxx = 1; xxx < len; ++xxx)' ]) 1393set incsearch 1394call Ntest_override ( "char_avail" , 1 ) 1395call feedkeys ( "/LongName\<CR>" , 'ntx' ) 1396call feedkeys ( ":%s/xxx/\<C-R>\<C-W>/g\<CR>" , 'ntx' ) 1397call assert_equal ( 'for (SomeLongName = 1; SomeLongName < len; ++SomeLongName)' , getline ( 2 )) 1398 1399bwipe ! 1400call Ntest_override ( "ALL" , 0 ) 1401set noincsearch 1402endfunc 1403 1404func Test_search_skip_all_matches () 1405enew 1406call setline ( 1 , [ 'no match here' , 1407 \'match this line' , 1408 \'nope' , 1409 \'match in this line' , 1410 \'last line' , 1411 \]) 1412call cursor ( 1 , 1 ) 1413let lnum = search ( 'this' , '' , 0 , 0 , 'getline(".") =~ "this line"' ) 1414" Only check that no match is found. Previously it searched forever. 1415call assert_equal ( 0 , lnum ) 1416 1417bwipe ! 1418endfunc 1419 1420func Test_search_undefined_behaviour () 1421CheckFeature terminal 1422 1423let h = winheight ( 0 ) 1424if h < 3 1425return 1426endif 1427" did cause an undefined left shift 1428let g: buf = term_start ([ GetVimProg (), '--clean' , '-e' , '-s' , '-c' , 'call search(getline("."))' , 'samples/test000' ], { 'term_rows' : 3 }) 1429call assert_equal ([ '' ], getline ( 1 , '$' )) 1430call term_sendkeys ( g: buf , ":qa!\<cr>" ) 1431bwipe ! 1432endfunc 1433 1434func Test_search_undefined_behaviour2 () 1435call search ( "\%UC0000000" ) 1436endfunc 1437 1438" Test for search('multi-byte char', 'bce') 1439func Test_search_multibyte () 1440let save_enc = & encoding 1441set encoding = utf8 1442enew ! 1443call append ( '$' , 'A' ) 1444call cursor ( 2 , 1 ) 1445call assert_equal ( 2 , search ( 'A' , 'bce' , line ( '.' ))) 1446enew ! 1447let & encoding = save_enc 1448endfunc 1449 1450" This was causing E874. Also causes an invalid read? 1451func Test_look_behind () 1452new 1453call setline ( 1 , '0\|\&\n\@<=' ) 1454call search ( getline ( "." )) 1455bwipe ! 1456endfunc 1457 1458func Test_search_visual_area_linewise () 1459new 1460call setline ( 1 , [ 'aa' , 'bb' , 'cc' ]) 1461exe "normal 2GV\<Esc>" 1462for engine in [ 1 , 2 ] 1463exe 'set regexpengine=' .. engine 1464exe "normal gg/\\%'<\<CR>>" 1465call assert_equal ([ 0 , 2 , 1 , 0 , 1 ], getcurpos (), 'engine ' .. engine ) 1466exe "normal gg/\\%'>\<CR>" 1467call assert_equal ([ 0 , 2 , 2 , 0 , 2 ], getcurpos (), 'engine ' .. engine ) 1468endfor 1469 1470bwipe ! 1471set regexpengine & 1472endfunc 1473 1474func Test_search_sentence () 1475new 1476" this used to cause a crash 1477/ \%'( 1478/ 1479bwipe 1480endfunc 1481 1482" Test that there is no crash when there is a last search pattern but no last 1483" substitute pattern. 1484func Test_no_last_substitute_pat () 1485throw 'Skipped: TODO: ' 1486" Use viminfo to set the last search pattern to a string and make the last 1487" substitute pattern the most recent used and make it empty (NULL). 1488call writefile ([ '~MSle0/bar' , '~MSle0~&' ], 'Xviminfo' , 'D' ) 1489rviminfo ! Xviminfo 1490call assert_fails ( 'normal n' , 'E35:' ) 1491endfunc 1492 1493func Test_search_Ctrl_L_combining () 1494" Make sure, that Ctrl-L works correctly with combining characters. 1495" It uses an artificial example of an 'a' with 4 combining chars: 1496" 'a' U+0061 Dec:97 LATIN SMALL LETTER A a /\%u61\Z "\u0061" 1497" ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" 1498" ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" 1499" ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" 1500" ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" 1501" Those should also appear on the commandline 1502CheckOption incsearch 1503 1504call Cmdline3_prep () 15051 1506let bufcontent = [ '' , 'Miạ̀́̇m' ] 1507call append ( '$' , bufcontent ) 1508call feedkeys ( "/Mi\<c-l>\<c-l>\<cr>" , 'tx' ) 1509call assert_equal ( 5 , line ( '.' )) 1510call assert_equal ( bufcontent [ 1 ], @/) 1511call Incsearch_cleanup () 1512endfunc 1513 1514func Test_large_hex_chars1 () 1515" This used to cause a crash, the character becomes an NFA state. 1516try 1517/ \%Ufffffc23 1518catch 1519call assert_match ( 'E678:' , v: exception ) 1520endtry 1521try 1522set re = 1 1523/ \%Ufffffc23 1524catch 1525call assert_match ( 'E678:' , v: exception ) 1526endtry 1527set re & 1528endfunc 1529 1530func Test_large_hex_chars2 () 1531" This used to cause a crash, the character becomes an NFA state. 1532try 1533/ [ \Ufffffc1f ] 1534catch 1535call assert_match ( 'E1541:' , v: exception ) 1536endtry 1537try 1538set re = 1 1539/ [ \Ufffffc1f ] 1540catch 1541call assert_match ( 'E1541:' , v: exception ) 1542endtry 1543set re & 1544endfunc 1545 1546func Test_large_hex_chars3 () 1547" Validate max number of Unicode char 1548try 1549/ [ \UFFFFFFFF ] 1550catch 1551call assert_match ( 'E1541:' , v: exception ) 1552endtry 1553try 1554/ [ \UFFFFFFF ] 1555catch 1556call assert_match ( 'E486:' , v: exception ) 1557endtry 1558try 1559/ \%#=2 [ \d32-\UFFFFFFFF ] 1560catch 1561call assert_match ( 'E1541:' , v: exception ) 1562endtry 1563try 1564/ \%#=1 [ \UFFFFFFFF ] 1565catch 1566call assert_match ( 'E1541:' , v: exception ) 1567endtry 1568try 1569/ \%#=1 [ \d32-\UFFFFFFFF ] 1570catch 1571call assert_match ( 'E945:' , v: exception ) 1572endtry 1573endfunc 1574 1575func Test_one_error_msg () 1576" This was also giving an internal error 1577call assert_fails ( 'call search(" \\((\\v[[=P=]]){185}+ ")' , 'E871:' ) 1578endfunc 1579 1580func Test_incsearch_add_char_under_cursor () 1581CheckOption incsearch 1582 1583set incsearch 1584new 1585call setline ( 1 , [ 'find match' , 'anything' ]) 15861 1587call Ntest_override ( 'char_avail' , 1 ) 1588call feedkeys ( "fc/m\<C-L>\<C-L>\<C-L>\<C-L>\<C-L>\<CR>" , 'tx' ) 1589call assert_equal ( 'match' , @/) 1590call Ntest_override ( 'char_avail' , 0 ) 1591 1592set incsearch & 1593bwipe ! 1594endfunc 1595 1596" Test for the search() function with match at the cursor position 1597func Test_search_match_at_curpos () 1598new 1599call append ( 0 , [ 'foobar' , '' , 'one two' , '' ]) 1600 1601normal gg 1602 1603eval 'foobar' ->search ( 'c' ) 1604call assert_equal ([ 1 , 1 ], [ line ( '.' ), col ( '.' )]) 1605 1606normal j 1607call search ( '^$' , 'c' ) 1608call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 1609 1610call search ( '^$' , 'bc' ) 1611call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 1612 1613exe "normal /two\<CR>" 1614call search ( '.' , 'c' ) 1615call assert_equal ([ 3 , 5 ], [ line ( '.' ), col ( '.' )]) 1616 1617bw ! 1618endfunc 1619 1620" Test for error cases with the search() function 1621func Test_search_errors () 1622call assert_fails ( "call search('pat', [])" , 'E730:' ) 1623call assert_fails ( "call search('pat', 'b', {})" , 'E728:' ) 1624call assert_fails ( "call search('pat', 'b', 1, [])" , 'E745:' ) 1625call assert_fails ( "call search('pat', 'ns')" , 'E475:' ) 1626call assert_fails ( "call search('pat', 'mr')" , 'E475:' ) 1627 1628new 1629call setline ( 1 , [ 'foo' , 'bar' ]) 1630call assert_fails ( 'call feedkeys("/foo/;/bar/;\<CR>", "tx")' , 'E386:' ) 1631bwipe ! 1632endfunc 1633 1634func Test_search_display_pattern () 1635new 1636call setline ( 1 , [ 'foo' , 'bar' , 'foobar' ]) 1637 1638call cursor ( 1 , 1 ) 1639let @/= 'foo' 1640let pat = @/->escape ( '()*?' . '\s\+' ) 1641let g: a = execute ( ':unsilent :norm! n' ) 1642call assert_match ( pat , g: a ) 1643 1644" right-left 1645if exists ( "+rightleft" ) 1646set rl 1647call cursor ( 1 , 1 ) 1648let @/= 'foo' 1649let pat = 'oof/\s\+' 1650let g: a = execute ( ':unsilent :norm! n' ) 1651call assert_match ( pat , g: a ) 1652set norl 1653endif 1654endfunc 1655 1656func Test_searchdecl () 1657let lines =<< trim END 1658int global; 1659 1660func() 1661{ 1662int global; 1663if (cond) { 1664int local; 1665} 1666int local; 1667// comment 1668} 1669END 1670new 1671call setline ( 1 , lines ) 167210 1673call assert_equal ( 0 , searchdecl ( 'local' , 0 , 0 )) 1674call assert_equal ( 7 , getcurpos ()[ 1 ]) 1675 167610 1677call assert_equal ( 0 , 'local' ->searchdecl ( 0 , 1 )) 1678call assert_equal ( 9 , getcurpos ()[ 1 ]) 1679 168010 1681call assert_equal ( 0 , searchdecl ( 'global' )) 1682call assert_equal ( 5 , getcurpos ()[ 1 ]) 1683 168410 1685call assert_equal ( 0 , searchdecl ( 'global' , 1 )) 1686call assert_equal ( 1 , getcurpos ()[ 1 ]) 1687 1688bwipe ! 1689endfunc 1690 1691func Test_search_special () 1692" this was causing illegal memory access and an endless loop 1693set t_PE = 1694exe "norm /\x80PS" 1695endfunc 1696 1697" Test for command failures when the last search pattern is not set. 1698" Need to run this in a new vim instance where last search pattern is not set. 1699func Test_search_with_no_last_pat () 1700let lines =<< trim [SCRIPT] 1701call assert_fails("normal i\<C-R>/\e", 'E35:') 1702call assert_fails("exe '/'", 'E35:') 1703call assert_fails("exe '?'", 'E35:') 1704call assert_fails("/", 'E35:') 1705call assert_fails("?", 'E35:') 1706call assert_fails("normal n", 'E35:') 1707call assert_fails("normal N", 'E35:') 1708call assert_fails("normal gn", 'E35:') 1709call assert_fails("normal gN", 'E35:') 1710call assert_fails("normal cgn", 'E35:') 1711call assert_fails("normal cgN", 'E35:') 1712let p = [] 1713let p = @/ 1714call assert_equal('', p) 1715call assert_fails("normal :\<C-R>/", 'E35:') 1716call assert_fails("//p", 'E35:') 1717call assert_fails(";//p", 'E35:') 1718call assert_fails("??p", 'E35:') 1719call assert_fails(";??p", 'E35:') 1720call assert_fails('g//p', ['E35:', 'E476:']) 1721call assert_fails('v//p', ['E35:', 'E476:']) 1722call writefile(v:errors, 'Xresult') 1723qall! 1724[SCRIPT] 1725call writefile ( lines , 'Xscript' , 'D' ) 1726 1727if RunVim ([], [], '--clean -S Xscript' ) 1728call assert_equal ([], readfile ( 'Xresult' )) 1729endif 1730call delete ( 'Xresult' ) 1731endfunc 1732 1733" Test for using the last substitute pattern without last search pattern. 1734func Test_search_with_last_substitute_pat () 1735let lines =<< trim [SCRIPT] 1736new 1737set shortmess+=S 1738call setline(1, repeat(['foofoo'], 3)) 1739%s/foo/bar/ 1740call assert_equal(repeat(['barfoo'], 3), getline(1, '$')) 1741 1742call cursor(1, 1) 1743call assert_equal("/foo", execute('call feedkeys("/\r", "tx")', '')->trim()) 1744call assert_equal([0, 1, 4, 0], getpos('.')) 1745 1746if has('rightleft') 1747set rightleft rightleftcmd=search 1748call cursor(1, 1) 1749call assert_equal("oof/", execute('call feedkeys("/\r", "tx")', '')->trim()) 1750call assert_equal([0, 1, 4, 0], getpos('.')) 1751endif 1752 1753call writefile(v:errors, 'Xresult') 1754qall! 1755[SCRIPT] 1756call writefile ( lines , 'Xscript' , 'D' ) 1757 1758if RunVim ([], [], '--clean -S Xscript' ) 1759call assert_equal ([], readfile ( 'Xresult' )) 1760endif 1761call delete ( 'Xresult' ) 1762endfunc 1763 1764" Test for using tilde (~) atom in search. This should use the last used 1765" substitute pattern 1766func Test_search_tilde_pat () 1767let lines =<< trim [SCRIPT] 1768set regexpengine=1 1769call assert_fails('exe "normal /~\<CR>"', 'E33:') 1770call assert_fails('exe "normal ?~\<CR>"', 'E33:') 1771set regexpengine=2 1772call assert_fails('exe "normal /~\<CR>"', ['E33:', 'E383:']) 1773call assert_fails('exe "normal ?~\<CR>"', ['E33:', 'E383:']) 1774set regexpengine& 1775call writefile(v:errors, 'Xresult') 1776qall! 1777[SCRIPT] 1778call writefile ( lines , 'Xscript' , 'D' ) 1779if RunVim ([], [], '--clean -S Xscript' ) 1780call assert_equal ([], readfile ( 'Xresult' )) 1781endif 1782call delete ( 'Xresult' ) 1783endfunc 1784 1785" Test for searching a pattern that is not present with 'nowrapscan' 1786func Test_search_pat_not_found () 1787new 1788set nowrapscan 1789let @/= '1abcxyz2' 1790call assert_fails ( 'normal n' , 'E385:' ) 1791call assert_fails ( 'normal N' , 'E384:' ) 1792set wrapscan & 1793bw 1794endfunc 1795 1796" Test for v:searchforward variable 1797func Test_searchforward_var () 1798new 1799call setline ( 1 , [ 'foo' , '' , 'foo' ]) 1800call cursor ( 2 , 1 ) 1801let @/= 'foo' 1802let v: searchforward = 0 1803normal N 1804call assert_equal ( 3 , line ( '.' )) 1805call cursor ( 2 , 1 ) 1806let v: searchforward = 1 1807normal N 1808call assert_equal ( 1 , line ( '.' )) 1809bw ! 1810endfunc 1811 1812" Test for invalid regular expressions 1813func Test_invalid_regexp () 1814set regexpengine = 1 1815call assert_fails ( "call search(repeat('\\(.\\)', 10))" , 'E51:' ) 1816call assert_fails ( "call search('\\%(')" , 'E53:' ) 1817call assert_fails ( "call search('\\(')" , 'E54:' ) 1818call assert_fails ( "call search('\\)')" , 'E55:' ) 1819call assert_fails ( "call search('x\\@#')" , 'E59:' ) 1820call assert_fails ( 'call search(''\v%(%(%(%(%(%(%(%(%(%(%(a){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}'')' , 'E60:' ) 1821call assert_fails ( "call search('a\\+*')" , 'E61:' ) 1822call assert_fails ( "call search('\\_m')" , 'E63:' ) 1823call assert_fails ( "call search('\\+')" , 'E64:' ) 1824call assert_fails ( "call search('\\1')" , 'E65:' ) 1825call assert_fails ( "call search('\\z\\(\\)')" , 'E66:' ) 1826call assert_fails ( "call search('\\z2')" , 'E67:' ) 1827call assert_fails ( "call search('\\zx')" , 'E68:' ) 1828call assert_fails ( "call search('\\%[ab')" , 'E69:' ) 1829call assert_fails ( "call search('\\%[]')" , 'E70:' ) 1830call assert_fails ( "call search('\\%a')" , 'E71:' ) 1831call assert_fails ( "call search('ab\\%[\\(cd\\)]')" , 'E369:' ) 1832call assert_fails ( "call search('ab\\%[\\%(cd\\)]')" , 'E369:' ) 1833set regexpengine = 2 1834call assert_fails ( "call search('\\_')" , 'E865:' ) 1835call assert_fails ( "call search('\\+')" , 'E866:' ) 1836call assert_fails ( "call search('\\zx')" , 'E867:' ) 1837call assert_fails ( "call search('\\%a')" , 'E867:' ) 1838call assert_fails ( "call search('x\\@#')" , 'E869:' ) 1839call assert_fails ( "call search(repeat('\\(.\\)', 10))" , 'E872:' ) 1840call assert_fails ( "call search('\\_m')" , 'E877:' ) 1841call assert_fails ( "call search('\\%(')" , 'E53:' ) 1842call assert_fails ( "call search('\\(')" , 'E54:' ) 1843call assert_fails ( "call search('\\)')" , 'E55:' ) 1844call assert_fails ( "call search('\\z\\(\\)')" , 'E66:' ) 1845call assert_fails ( "call search('\\z2')" , 'E67:' ) 1846call assert_fails ( "call search('\\zx')" , 'E867:' ) 1847call assert_fails ( "call search('\\%[ab')" , 'E69:' ) 1848call assert_fails ( "call search('\\%[]')" , 'E70:' ) 1849call assert_fails ( "call search('\\%9999999999999999999999999999v')" , 'E951:' ) 1850set regexpengine & 1851call assert_fails ( "call search('\\%#=3ab')" , 'E864:' ) 1852endfunc 1853 1854" Test for searching a very complex pattern in a string. Should switch the 1855" regexp engine from NFA to the old engine. 1856func Test_regexp_switch_engine () 1857let l = readfile ( 'samples/re.freeze.txt' ) 1858let v = substitute ( l [ 4 ], '..\@<!' , '' , '' ) 1859call assert_equal ( l [ 4 ], v ) 1860endfunc 1861 1862" Test for the \%V atom to search within visually selected text 1863func Test_search_in_visual_area () 1864new 1865call setline ( 1 , [ 'foo bar1' , 'foo bar2' , 'foo bar3' , 'foo bar4' ]) 1866exe "normal 2GVjo/\\%Vbar\<CR>\<Esc>" 1867call assert_equal ([ 2 , 5 ], [ line ( '.' ), col ( '.' )]) 1868exe "normal 2GVj$?\\%Vbar\<CR>\<Esc>" 1869call assert_equal ([ 3 , 5 ], [ line ( '.' ), col ( '.' )]) 1870bw ! 1871endfunc 1872 1873" Test for searching with 'smartcase' and 'ignorecase' 1874func Test_search_smartcase () 1875new 1876call setline ( 1 , [ '' , 'Hello' ]) 1877set noignorecase nosmartcase 1878call assert_fails ( 'exe "normal /\\a\\_.\\(.*\\)O\<CR>"' , 'E486:' ) 1879 1880set ignorecase nosmartcase 1881exe "normal /\\a\\_.\\(.*\\)O\<CR>" 1882call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 1883 1884call cursor ( 1 , 1 ) 1885set ignorecase smartcase 1886call assert_fails ( 'exe "normal /\\a\\_.\\(.*\\)O\<CR>"' , 'E486:' ) 1887 1888exe "normal /\\a\\_.\\(.*\\)o\<CR>" 1889call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 1890 1891" Test for using special atoms with 'smartcase' 1892call setline ( 1 , [ '' , ' Hello\ ' ]) 1893call cursor ( 1 , 1 ) 1894call feedkeys ( '/\_.\%(\uello\)\' .. "\<CR>" , 'xt' ) 1895call assert_equal ([ 2 , 4 ], [ line ( '.' ), col ( '.' )]) 1896 1897set ignorecase & smartcase & 1898bw ! 1899endfun 1900 1901" Test 'smartcase' with utf-8. 1902func Test_search_smartcase_utf8 () 1903new 1904let save_enc = & encoding 1905set encoding = utf8ignorecase smartcase 1906 1907call setline ( 1 , 'Café cafÉ' ) 19081 s /café/x/g 1909call assert_equal ( 'x x' , getline ( 1 )) 1910 1911call setline ( 1 , 'Café cafÉ' ) 19121 s /cafÉ/x/g 1913call assert_equal ( 'Café x' , getline ( 1 )) 1914 1915set ignorecase & smartcase & 1916let & encoding = save_enc 1917bwipe ! 1918endfunc 1919 1920" Test searching past the end of a file 1921func Test_search_past_eof () 1922new 1923call setline ( 1 , [ 'Line' ]) 1924exe "normal /\\n\\zs\<CR>" 1925call assert_equal ([ 1 , 4 ], [ line ( '.' ), col ( '.' )]) 1926bwipe ! 1927endfunc 1928 1929" Test setting the start of the match and still finding a next match in the 1930" same line. 1931func Test_search_set_start_same_line () 1932new 1933set cpo -= c 1934 1935call setline ( 1 , [ '1' , '2' , '3 .' , '4' , '5' ]) 1936exe "normal /\\_s\\zs\\S\<CR>" 1937call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 1938exe 'normal n' 1939call assert_equal ([ 3 , 1 ], [ line ( '.' ), col ( '.' )]) 1940exe 'normal n' 1941call assert_equal ([ 3 , 3 ], [ line ( '.' ), col ( '.' )]) 1942exe 'normal n' 1943call assert_equal ([ 4 , 1 ], [ line ( '.' ), col ( '.' )]) 1944exe 'normal n' 1945call assert_equal ([ 5 , 1 ], [ line ( '.' ), col ( '.' )]) 1946 1947set cpo += c 1948bwipe ! 1949endfunc 1950 1951" Test for various search offsets 1952func Test_search_offset () 1953" With /e, for a match in the first column of a line, the cursor should be 1954" placed at the end of the previous line. 1955new 1956call setline ( 1 , [ 'one two' , 'three four' ]) 1957call search ( 'two\_.' , 'e' ) 1958call assert_equal ([ 1 , 7 ], [ line ( '.' ), col ( '.' )]) 1959 1960" with cursor at the beginning of the file, use /s+1 1961" '+' without a digit is the same as +1, and 'b' is an alias for 's' 1962for searchcmd in [ '/two/s+1' , '/two/s+' , '/two/b+1' , '/two/b+' , '/' ] 1963call cursor ( 1 , 1 ) 1964exe $ "normal {searchcmd}\<CR>" 1965call assert_equal ([ 1 , 6 ], [ line ( '.' ), col ( '.' )], searchcmd ) 1966call assert_equal ( '/two/s+1' , Screenline ( & lines ) ->trim (), searchcmd ) 1967endfor 1968 1969" repeat the same search pattern with different offsets 1970for [ offset , col ] in [[ 's' , 5 ], [ 'e-1' , 6 ], [ 's+2' , 7 ], [ 's-2' , 3 ], [ '' , 5 ]] 1971let searchcmd = $ '//{offset}' 1972call cursor ( 1 , 1 ) 1973exe $ "normal {searchcmd}\<CR>" 1974call assert_equal ([ 1 , col ], [ line ( '.' ), col ( '.' )], searchcmd ) 1975call assert_equal ( col == 5 ?'/two' : $ '/two/{offset}', 1976 \Screenline(&lines)->trim(), searchcmd) 1977endfor 1978 1979" with cursor at the end of the file, use /e-1 1980" '-' without a digit is the same as -1 1981for searchcmd in [ '?three?e-1' , '?three?e-' , '?' ] 1982call cursor ( 2 , 10 ) 1983exe $ "normal {searchcmd}\<CR>" 1984call assert_equal ([ 2 , 4 ], [ line ( '.' ), col ( '.' )], searchcmd ) 1985call assert_equal ( '?three?e-1' , Screenline ( & lines ) ->trim (), searchcmd ) 1986endfor 1987 1988" repeat the same search pattern with different offsets 1989for [ offset , col ] in [[ 'e' , 5 ], [ 's+1' , 2 ], [ 'e-2' , 3 ], [ 'e+2' , 7 ], [ '' , 1 ]] 1990let searchcmd = $ '??{offset}' 1991call cursor ( 2 , 10 ) 1992exe $ "normal {searchcmd}\<CR>" 1993call assert_equal ([ 2 , col ], [ line ( '.' ), col ( '.' )], searchcmd ) 1994call assert_equal ( col == 1 ?'?three' : $ '?three?{offset}', 1995 \Screenline(&lines)->trim(), searchcmd) 1996endfor 1997 1998" line offset - after the last line 1999" '+' without a digit and '1' without a sign are the same as +1 2000for searchcmd in [ '/three/+1' , '/three/+' , '/three/1' , '/' ] 2001call cursor ( 1 , 1 ) 2002exe $ "normal {searchcmd}\<CR>" 2003call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )], searchcmd ) 2004call assert_equal ( '/three/+1' , Screenline ( & lines ) ->trim (), searchcmd ) 2005endfor 2006 2007" repeat the same search pattern with different line offsets 2008for [ offset , lnum ] in [[ '+0' , 2 ], [ '-1' , 1 ], [ '+2' , 2 ], [ '-2' , 1 ]] 2009let searchcmd = $ '//{offset}' 2010call cursor ( 1 , 1 ) 2011exe $ "normal {searchcmd}\<CR>" 2012call assert_equal ([ lnum , 1 ], [ line ( '.' ), col ( '.' )], searchcmd ) 2013call assert_equal ( $ '/three/{offset}', 2014 \Screenline(&lines)->trim(), searchcmd) 2015endfor 2016 2017" line offset - before the first line 2018" '-' without a digit is the same as -1 2019for searchcmd in [ '?one?-1' , '?one?-' , '?' ] 2020call cursor ( 2 , 1 ) 2021exe $ "normal {searchcmd}\<CR>" 2022call assert_equal ([ 1 , 1 ], [ line ( '.' ), col ( '.' )], searchcmd ) 2023call assert_equal ( '?one?-1' , Screenline ( & lines ) ->trim (), searchcmd ) 2024endfor 2025 2026" repeat the same search pattern with different line offsets 2027for [ offset , lnum ] in [[ '+0' , 1 ], [ '+1' , 2 ], [ '-2' , 1 ], [ '+2' , 2 ]] 2028let searchcmd = $ '??{offset}' 2029call cursor ( 2 , 1 ) 2030exe $ "normal {searchcmd}\<CR>" 2031call assert_equal ([ lnum , 1 ], [ line ( '.' ), col ( '.' )], searchcmd ) 2032call assert_equal ( $ '?one?{offset}', 2033 \Screenline(&lines)->trim(), searchcmd) 2034endfor 2035 2036" character offset - before the first character in the file 2037call cursor ( 2 , 1 ) 2038exe "normal ?one?s-1\<CR>" 2039call assert_equal ([ 1 , 1 ], [ line ( '.' ), col ( '.' )]) 2040call assert_equal ( '?one?s-1' , Screenline ( & lines ) ->trim ()) 2041call cursor ( 2 , 1 ) 2042exe "normal ?one?e-3\<CR>" 2043call assert_equal ([ 1 , 1 ], [ line ( '.' ), col ( '.' )]) 2044call assert_equal ( '?one?e-3' , Screenline ( & lines ) ->trim ()) 2045 2046" character offset - after the last character in the file 2047call cursor ( 1 , 1 ) 2048exe "normal /four/s+4\<CR>" 2049call assert_equal ([ 2 , 10 ], [ line ( '.' ), col ( '.' )]) 2050call assert_equal ( '/four/s+4' , Screenline ( & lines ) ->trim ()) 2051call cursor ( 1 , 1 ) 2052exe "normal /four/e+1\<CR>" 2053call assert_equal ([ 2 , 10 ], [ line ( '.' ), col ( '.' )]) 2054call assert_equal ( '/four/e+1' , Screenline ( & lines ) ->trim ()) 2055 2056bw ! 2057endfunc 2058 2059" Test for searching for matching parenthesis using % 2060func Test_search_match_paren () 2061new 2062call setline ( 1 , "abc(def')'ghi'('jk'\\t'lm)no" ) 2063" searching for a matching parenthesis should skip single quoted characters 2064call cursor ( 1 , 4 ) 2065normal % 2066call assert_equal ([ 1 , 25 ], [ line ( '.' ), col ( '.' )]) 2067normal % 2068call assert_equal ([ 1 , 4 ], [ line ( '.' ), col ( '.' )]) 2069call cursor ( 1 , 5 ) 2070normal ]) 2071call assert_equal ([ 1 , 25 ], [ line ( '.' ), col ( '.' )]) 2072call cursor ( 1 , 24 ) 2073normal [( 2074call assert_equal ([ 1 , 4 ], [ line ( '.' ), col ( '.' )]) 2075 2076call setline ( 1 , [ 'x" (a "b" )\' , '")' ]) 2077call cursor ( 1 , 4 ) 2078normal % 2079call assert_equal ([ 1 , 11 ], [ line ( '.' ), col ( '.' )]) 2080normal % 2081call assert_equal ([ 1 , 4 ], [ line ( '.' ), col ( '.' )]) 2082call cursor ( 1 , 10 ) 2083normal [( 2084call assert_equal ([ 1 , 4 ], [ line ( '.' ), col ( '.' )]) 2085call cursor ( 1 , 4 ) 2086normal ]) 2087call assert_equal ([ 1 , 11 ], [ line ( '.' ), col ( '.' )]) 2088 2089" matching parenthesis in 'virtualedit' mode with cursor after the eol 2090call setline ( 1 , 'abc(defgh)' ) 2091set virtualedit = all 2092normal 20|% 2093call assert_equal ( 4 , col ( '.' )) 2094set virtualedit & 2095bw ! 2096endfunc 2097 2098" Test for searching a pattern and stopping before a specified line 2099func Test_search_stopline () 2100new 2101call setline ( 1 , [ '' , '' , '' , 'vim' ]) 2102call assert_equal ( 0 , search ( 'vim' , 'n' , 3 )) 2103call assert_equal ( 4 , search ( 'vim' , 'n' , 4 )) 2104call setline ( 1 , [ 'vim' , '' , '' , '' ]) 2105call cursor ( 4 , 1 ) 2106call assert_equal ( 0 , search ( 'vim' , 'bn' , 2 )) 2107call assert_equal ( 1 , search ( 'vim' , 'bn' , 1 )) 2108bw ! 2109endfunc 2110 2111func Test_incsearch_highlighting_newline () 2112CheckRunVimInTerminal 2113CheckOption incsearch 2114CheckScreendump 2115new 2116call test_override ( "char_avail" , 1 ) 2117 2118let commands =<< trim [CODE] 2119set incsearch nohls 2120call setline(1, ['test', 'xxx']) 2121[CODE] 2122call writefile ( commands , 'Xincsearch_nl' , 'D' ) 2123let buf = RunVimInTerminal ( '-S Xincsearch_nl' , { 'rows' : 5 , 'cols' : 10 }) 2124call TermWait ( buf , 100 ) 2125call term_sendkeys ( buf , '/test' ) 2126call VerifyScreenDump ( buf , 'Test_incsearch_newline1' , {}) 2127" Need to send one key at a time to force a redraw 2128call term_sendkeys ( buf , '\n' ) 2129call VerifyScreenDump ( buf , 'Test_incsearch_newline2' , {}) 2130call term_sendkeys ( buf , 'x' ) 2131call VerifyScreenDump ( buf , 'Test_incsearch_newline3' , {}) 2132call term_sendkeys ( buf , 'x' ) 2133call VerifyScreenDump ( buf , 'Test_incsearch_newline4' , {}) 2134call term_sendkeys ( buf , "\<CR>" ) 2135call VerifyScreenDump ( buf , 'Test_incsearch_newline5' , {}) 2136call StopVimInTerminal ( buf ) 2137 2138" clean up 2139call test_override ( "char_avail" , 0 ) 2140bw 2141endfunc 2142 2143func Test_incsearch_substitute_dump2 () 2144CheckOption incsearch 2145CheckScreendump 2146 2147call writefile ([ 2148 \'set incsearch hlsearch scrolloff=0' , 2149 \'for n in range(1, 4)' , 2150 \' call setline(n, "foo " . n)' , 2151 \'endfor' , 2152 \'call setline(5, "abc|def")' , 2153 \'3' , 2154 \], 'Xis_subst_script2' , 'D' ) 2155let buf = RunVimInTerminal ( '-S Xis_subst_script2' , { 'rows' : 9 , 'cols' : 70 }) 2156 2157call term_sendkeys ( buf , ':%s/\vabc|' ) 2158sleep 100m 2159call VerifyScreenDump ( buf , 'Test_incsearch_sub_01' , {}) 2160call term_sendkeys ( buf , "\<Esc>" ) 2161 2162" The following should not be highlighted 2163call term_sendkeys ( buf , ':1,5s/\v|' ) 2164sleep 100m 2165call VerifyScreenDump ( buf , 'Test_incsearch_sub_02' , {}) 2166 2167 2168call StopVimInTerminal ( buf ) 2169endfunc 2170 2171func Test_incsearch_restore_view () 2172CheckOption incsearch 2173CheckScreendump 2174 2175let lines =<< trim [CODE] 2176set incsearch nohlsearch 2177setlocal scrolloff=0 smoothscroll 2178call setline(1, [join(range(25), ' '), '', '', '', '', 'xxx']) 2179call feedkeys("2\<C-E>", 't') 2180[CODE] 2181call writefile ( lines , 'Xincsearch_restore_view' , 'D' ) 2182let buf = RunVimInTerminal ( '-S Xincsearch_restore_view' , { 'rows' : 6 , 'cols' : 20 }) 2183 2184call VerifyScreenDump ( buf , 'Test_incsearch_restore_view_01' , {}) 2185call term_sendkeys ( buf , '/xx' ) 2186call VerifyScreenDump ( buf , 'Test_incsearch_restore_view_02' , {}) 2187call term_sendkeys ( buf , 'x' ) 2188call VerifyScreenDump ( buf , 'Test_incsearch_restore_view_03' , {}) 2189call term_sendkeys ( buf , "\<Esc>" ) 2190call VerifyScreenDump ( buf , 'Test_incsearch_restore_view_01' , {}) 2191 2192call StopVimInTerminal ( buf ) 2193endfunc 2194 2195func Test_pattern_is_uppercase_smartcase () 2196new 2197let input = [ 'abc' , 'ABC' , 'Abc' , 'abC' ] 2198call setline ( 1 , input ) 2199call cursor ( 1 , 1 ) 2200" default, matches firstline 2201 %s /abc//g 2202call assert_equal ([ '' , 'ABC' , 'Abc' , 'abC' ], 2203 \getline ( 1 , '$' )) 2204 2205set smartcase ignorecase 2206sil %d 2207call setline ( 1 , input ) 2208call cursor ( 1 , 1 ) 2209" with smartcase and incsearch set, matches everything 2210 %s /abc//g 2211call assert_equal ([ '' , '' , '' , '' ], getline ( 1 , '$' )) 2212 2213sil %d 2214call setline ( 1 , input ) 2215call cursor ( 1 , 1 ) 2216" with smartcase and incsearch set and found an uppercase letter, 2217" match only that. 2218 %s /abC//g 2219call assert_equal ([ 'abc' , 'ABC' , 'Abc' , '' ], 2220 \getline ( 1 , '$' )) 2221 2222sil %d 2223call setline ( 1 , input ) 2224call cursor ( 1 , 1 ) 2225exe "norm! vG$\<esc>" 2226" \%V should not be detected as uppercase letter 2227 %s /\%Vabc//g 2228call assert_equal ([ '' , '' , '' , '' ], getline ( 1 , '$' )) 2229 2230call setline ( 1 , input ) 2231call cursor ( 1 , 1 ) 2232exe "norm! vG$\<esc>" 2233" \v%V should not be detected as uppercase letter 2234 %s /\v%Vabc//g 2235call assert_equal ([ '' , '' , '' , '' ], getline ( 1 , '$' )) 2236 2237call setline ( 1 , input ) 2238call cursor ( 1 , 1 ) 2239exe "norm! vG$\<esc>" 2240" \v%VabC should be detected as uppercase letter 2241 %s /\v%VabC//g 2242call assert_equal ([ 'abc' , 'ABC' , 'Abc' , '' ], 2243 \getline ( 1 , '$' )) 2244 2245call setline ( 1 , input ) 2246call cursor ( 1 , 1 ) 2247" \Vabc should match everything 2248 %s /\Vabc//g 2249call assert_equal ([ '' , '' , '' , '' ], getline ( 1 , '$' )) 2250 2251call setline ( 1 , input + [ '_abc' ]) 2252" _ matches normally 2253 %s /\v_. * //g 2254call assert_equal ([ 'abc' , 'ABC' , 'Abc' , 'abC' , '' ], getline ( 1 , '$' )) 2255 2256set smartcase & ignorecase & 2257bw ! 2258endfunc 2259 2260func Test_no_last_search_pattern () 2261CheckOption incsearch 2262 2263let @/= "" 2264set incsearch 2265" these were causing a crash 2266call feedkeys ( "//\<C-G>" , 'xt' ) 2267call feedkeys ( "//\<C-T>" , 'xt' ) 2268call feedkeys ( "??\<C-G>" , 'xt' ) 2269call feedkeys ( "??\<C-T>" , 'xt' ) 2270endfunc 2271 2272func Test_search_with_invalid_range () 2273new 2274let lines =<< trim END 2275/\%.v 22765/ 2277c 2278END 2279call writefile ( lines , 'Xrangesearch' , 'D' ) 2280source Xrangesearch 2281 2282bwipe ! 2283endfunc 2284 2285func Test_incsearch_delimiter_ctrlg () 2286CheckOption incsearch 2287CheckScreendump 2288CheckRunVimInTerminal 2289call assert_equal ( 0 , & scrolloff ) 2290call writefile ([ 2291 \'set incsearch hls' , 2292 \'call setline(1, ["1 vim inc", "2 vim /", "3 vim /", "4 vim ?", "5 vim ?"])' , 2293 \'normal gg' , 2294 \'redraw' , 2295 \], 'Xscript_incsearch_delim' , 'D' ) 2296let buf = RunVimInTerminal ( '-S Xscript_incsearch_delim' , { 'rows' : 6 }) 2297 2298call term_sendkeys ( buf , '/' ) 2299sleep 100m 2300call term_sendkeys ( buf , 'v' ) 2301sleep 100m 2302call term_sendkeys ( buf , 'i' ) 2303sleep 100m 2304call term_sendkeys ( buf , 'm' ) 2305sleep 100m 2306call term_sendkeys ( buf , ' ' ) 2307sleep 100m 2308call term_sendkeys ( buf , '/' ) 2309sleep 100m 2310call term_sendkeys ( buf , "\<C-G>" ) 2311call VerifyScreenDump ( buf , 'Test_incsearch_delim_01' , {}) 2312call term_sendkeys ( buf , "\<Esc>" ) 2313 2314call term_sendkeys ( buf , ":5\<cr>" ) 2315call term_sendkeys ( buf , '?' ) 2316sleep 100m 2317call term_sendkeys ( buf , 'v' ) 2318sleep 100m 2319call term_sendkeys ( buf , 'i' ) 2320sleep 100m 2321call term_sendkeys ( buf , 'm' ) 2322sleep 100m 2323call term_sendkeys ( buf , ' ' ) 2324sleep 100m 2325call term_sendkeys ( buf , '?' ) 2326sleep 100m 2327call term_sendkeys ( buf , "\<C-T>" ) 2328call VerifyScreenDump ( buf , 'Test_incsearch_delim_02' , {}) 2329call term_sendkeys ( buf , "\<Esc>" ) 2330 2331call term_sendkeys ( buf , '/' ) 2332sleep 100m 2333call term_sendkeys ( buf , 'v' ) 2334sleep 100m 2335call term_sendkeys ( buf , 'i' ) 2336sleep 100m 2337call term_sendkeys ( buf , 'm' ) 2338sleep 100m 2339call term_sendkeys ( buf , ' ' ) 2340sleep 100m 2341call term_sendkeys ( buf , '\/' ) 2342sleep 100m 2343call term_sendkeys ( buf , "\<C-G>" ) 2344call VerifyScreenDump ( buf , 'Test_incsearch_delim_03' , {}) 2345call term_sendkeys ( buf , "\<Esc>" ) 2346 2347call term_sendkeys ( buf , ":5\<cr>" ) 2348call term_sendkeys ( buf , '?' ) 2349sleep 100m 2350call term_sendkeys ( buf , 'v' ) 2351sleep 100m 2352call term_sendkeys ( buf , 'i' ) 2353sleep 100m 2354call term_sendkeys ( buf , 'm' ) 2355sleep 100m 2356call term_sendkeys ( buf , ' ' ) 2357sleep 100m 2358call term_sendkeys ( buf , '\?' ) 2359sleep 100m 2360call term_sendkeys ( buf , "\<C-T>" ) 2361call VerifyScreenDump ( buf , 'Test_incsearch_delim_04' , {}) 2362call term_sendkeys ( buf , "\<Esc>" ) 2363 2364call StopVimInTerminal ( buf ) 2365endfunc 2366 2367func Test_searchcount_maxcount_cached () 2368new 2369call setline ( 1 , repeat ([ 'foo' ], 5 )) 2370set maxsearchcount = 99 2371let @/= 'foo' 2372call cursor ( 1 , 1 ) 2373call searchcount (#{ recompute : v: true , maxcount : 3 }) 2374let r = searchcount (#{ recompute : v: false , maxcount : 3 }) 2375call assert_equal ( 3 , r . maxcount ) 2376set maxsearchcount & 2377bwipe ! 2378endfunc 2379 2380" vim: shiftwidth=2 sts=2 expandtab