@@ -397,6 +397,117 @@ func Test_search_cmdline5()
397397 bw !
398398endfunc
399399
400+ func Test_search_cmdline6 ()
401+ " Test that consecutive matches
402+ " are caught by <c-g>/<c-t>
403+ if ! exists (' +incsearch' )
404+ return
405+ endif
406+ " need to disable char_avail,
407+ " so that expansion of commandline works
408+ call test_override (" char_avail" , 1 )
409+ new
410+ call setline (1 , [' bbvimb' , ' ' ])
411+ set incsearch
412+ " first match
413+ norm! gg0
414+ call feedkeys (" /b\<cr> " , ' tx' )
415+ call assert_equal ([0 ,1 ,2 ,0 ], getpos (' .' ))
416+ " second match
417+ norm! gg0
418+ call feedkeys (" /b\<c-g>\<cr> " , ' tx' )
419+ call assert_equal ([0 ,1 ,3 ,0 ], getpos (' .' ))
420+ " third match
421+ norm! gg0
422+ call feedkeys (" /b\<c-g>\<c-g>\<cr> " , ' tx' )
423+ call assert_equal ([0 ,1 ,7 ,0 ], getpos (' .' ))
424+ " first match again
425+ norm! gg0
426+ call feedkeys (" /b\<c-g>\<c-g>\<c-g>\<cr> " , ' tx' )
427+ call assert_equal ([0 ,1 ,2 ,0 ], getpos (' .' ))
428+ set nowrapscan
429+ " last match
430+ norm! gg0
431+ call feedkeys (" /b\<c-g>\<c-g>\<c-g>\<cr> " , ' tx' )
432+ call assert_equal ([0 ,1 ,7 ,0 ], getpos (' .' ))
433+ " clean up
434+ set wrapscan &vim
435+ set noincsearch
436+ call test_override (" char_avail" , 0 )
437+ bw !
438+ endfunc
439+
440+ func Test_search_cmdline7 ()
441+ " Test that an pressing <c-g> in an empty command line
442+ " does not move the cursor
443+ if ! exists (' +incsearch' )
444+ return
445+ endif
446+ " need to disable char_avail,
447+ " so that expansion of commandline works
448+ call test_override (" char_avail" , 1 )
449+ new
450+ let @/ = ' b'
451+ call setline (1 , [' bbvimb' , ' ' ])
452+ set incsearch
453+ " first match
454+ norm! gg0
455+ " moves to next match of previous search pattern, just like /<cr>
456+ call feedkeys (" /\<c-g>\<cr> " , ' tx' )
457+ call assert_equal ([0 ,1 ,2 ,0 ], getpos (' .' ))
458+ " moves to next match of previous search pattern, just like /<cr>
459+ call feedkeys (" /\<cr> " , ' tx' )
460+ call assert_equal ([0 ,1 ,3 ,0 ], getpos (' .' ))
461+ " moves to next match of previous search pattern, just like /<cr>
462+ call feedkeys (" /\<c-t>\<cr> " , ' tx' )
463+ call assert_equal ([0 ,1 ,7 ,0 ], getpos (' .' ))
464+ set noincsearch
465+ call test_override (" char_avail" , 0 )
466+ bw !
467+ endfunc
468+
469+ func Test_search_cmdline8 ()
470+ " Highlighting is cleared in all windows
471+ " since hls applies to all windows
472+ if ! exists (' +incsearch' ) || ! has (' terminal' ) || has (' gui_running' ) || winwidth (0 ) < 30
473+ return
474+ endif
475+ if has (" win32" )
476+ throw " Skipped: Bug with sending <ESC> to terminal window not fixed yet"
477+ endif
478+ let h = winheight (0 )
479+ if h < 3
480+ return
481+ endif
482+ " Prepare buffer text
483+ let lines = [' abb vim vim vi' , ' vimvivim' ]
484+ call writefile (lines , ' Xsearch.txt' )
485+ let g: buf = term_start ([GetVimProg (), ' --clean' , ' -c' , ' set noswapfile' , ' Xsearch.txt' ], {' term_rows' : 3 })
486+
487+ call term_wait (g: buf , 200 )
488+ call assert_equal (lines [0 ], term_getline (g: buf , 1 ))
489+ call assert_equal (lines [1 ], term_getline (g: buf , 2 ))
490+
491+ call term_sendkeys (g: buf , " :set incsearch hlsearch\<cr> " )
492+ call term_sendkeys (g: buf , " :14vsp\<cr> " )
493+ call term_sendkeys (g: buf , " /vim\<cr> " )
494+ call term_sendkeys (g: buf , " /b\<esc> " )
495+ call term_sendkeys (g: buf , " gg0" )
496+ call term_wait (g: buf , 500 )
497+ let screen_line = term_scrape (g: buf , 1 )
498+ let [a0,a1,a2,a3] = [screen_line[3 ].attr, screen_line[4 ].attr,
499+ \ screen_line[18 ].attr, screen_line[19 ].attr]
500+ call assert_notequal (a0, a1)
501+ call assert_notequal (a0, a3)
502+ call assert_notequal (a1, a2)
503+ call assert_equal (a0, a2)
504+ call assert_equal (a1, a3)
505+ " clean up
506+ call delete (' Xsearch.txt' )
507+
508+ bwipe!
509+ endfunc
510+
400511" Tests for regexp with various magic settings
401512func Test_search_regexp ()
402513 enew !
@@ -566,6 +677,7 @@ func Test_search_cmdline_incsearch_highlight_attr()
566677 let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0]
567678 call assert_equal (attr_line1, map (term_scrape (g: buf , 1 )[: len (attr_line1)-1 ], ' v:val.attr' ))
568679 call assert_equal (attr_line2, map (term_scrape (g: buf , 2 )[: len (attr_line2)-1 ], ' v:val.attr' ))
680+ call delete (' Xsearch.txt' )
569681
570682 call delete (' Xsearch.txt' )
571683 bwipe!
0 commit comments