view src/testdir/test_hlsearch.vim @ 11523:aad2c2ca0774 v8.0.0644

patch 8.0.0644: the timeout for 'hlsearch' is not tested commit https://github.com/vim/vim/commit/5b1affefd0e96154517ec6f71300086ae6d22d24 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 17 19:13:49 2017 +0200 patch 8.0.0644: the timeout for 'hlsearch' is not tested Problem: There is no test for 'hlsearch' timing out. Solution: Add a test.
author Christian Brabandt <cb@256bit.org>
date Sat, 17 Jun 2017 19:15:03 +0200
parents eb9a7296ae9f
children 14b6b79d685b
line wrap: on
line source

" Test for v:hlsearch

function! Test_hlsearch()
  new
  call setline(1, repeat(['aaa'], 10))
  set hlsearch nolazyredraw
  let r=[]
  " redraw is needed to make hlsearch highlight the matches
  exe "normal! /aaa\<CR>" | redraw
  let r1 = screenattr(1, 1)
  nohlsearch | redraw
  call assert_notequal(r1, screenattr(1,1))
  let v:hlsearch=1 | redraw
  call assert_equal(r1, screenattr(1,1))
  let v:hlsearch=0 | redraw
  call assert_notequal(r1, screenattr(1,1))
  set hlsearch | redraw
  call assert_equal(r1, screenattr(1,1))
  let v:hlsearch=0 | redraw
  call assert_notequal(r1, screenattr(1,1))
  exe "normal! n" | redraw
  call assert_equal(r1, screenattr(1,1))
  let v:hlsearch=0 | redraw
  call assert_notequal(r1, screenattr(1,1))
  exe "normal! /\<CR>" | redraw
  call assert_equal(r1, screenattr(1,1))
  set nohls
  exe "normal! /\<CR>" | redraw
  call assert_notequal(r1, screenattr(1,1))
  call assert_fails('let v:hlsearch=[]', 'E745')
  call garbagecollect(1)
  call getchar(1)
  enew!
endfunction

func Test_hlsearch_hangs()
  if !has('reltime') || !has('float')
    return
  endif

  " This pattern takes forever to match, it should timeout.
  help
  let start = reltime()
  set hlsearch nolazyredraw redrawtime=101
  let @/ = '\%#=2\v(a|\1)*'
  redraw
  let elapsed = reltimefloat(reltime(start))
  call assert_true(elapsed > 0.1)
  call assert_true(elapsed < 1.0)
  set nohlsearch redrawtime&
  quit
endfunc