test_hlsearch.vim 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. " Test for v:hlsearch
  2. source check.vim
  3. source screendump.vim
  4. func Test_hlsearch()
  5. new
  6. call setline(1, repeat(['aaa'], 10))
  7. set hlsearch nolazyredraw
  8. " redraw is needed to make hlsearch highlight the matches
  9. exe "normal! /aaa\<CR>" | redraw
  10. let r1 = screenattr(1, 1)
  11. nohlsearch | redraw
  12. call assert_notequal(r1, screenattr(1,1))
  13. let v:hlsearch=1 | redraw
  14. call assert_equal(r1, screenattr(1,1))
  15. let v:hlsearch=0 | redraw
  16. call assert_notequal(r1, screenattr(1,1))
  17. set hlsearch | redraw
  18. call assert_equal(r1, screenattr(1,1))
  19. let v:hlsearch=0 | redraw
  20. call assert_notequal(r1, screenattr(1,1))
  21. exe "normal! n" | redraw
  22. call assert_equal(r1, screenattr(1,1))
  23. let v:hlsearch=0 | redraw
  24. call assert_notequal(r1, screenattr(1,1))
  25. exe "normal! /\<CR>" | redraw
  26. call assert_equal(r1, screenattr(1,1))
  27. set nohls
  28. exe "normal! /\<CR>" | redraw
  29. call assert_notequal(r1, screenattr(1,1))
  30. call assert_fails('let v:hlsearch=[]', 'E745')
  31. call garbagecollect(1)
  32. call getchar(1)
  33. enew!
  34. endfunc
  35. func Test_hlsearch_hangs()
  36. if !has('reltime') || !has('float')
  37. return
  38. endif
  39. " This pattern takes a long time to match, it should timeout.
  40. new
  41. call setline(1, ['aaa', repeat('abc ', 100000), 'ccc'])
  42. let start = reltime()
  43. set hlsearch nolazyredraw redrawtime=101
  44. let @/ = '\%#=1a*.*X\@<=b*'
  45. redraw
  46. let elapsed = reltimefloat(reltime(start))
  47. call assert_true(elapsed > 0.1)
  48. call assert_true(elapsed < 1.0)
  49. set nohlsearch redrawtime&
  50. bwipe!
  51. endfunc
  52. func Test_hlsearch_eol_highlight()
  53. new
  54. call append(1, repeat([''], 9))
  55. set hlsearch nolazyredraw
  56. exe "normal! /$\<CR>" | redraw
  57. let attr = screenattr(1, 1)
  58. for row in range(2, 10)
  59. call assert_equal(attr, screenattr(row, 1), 'in line ' . row)
  60. endfor
  61. set nohlsearch
  62. bwipe!
  63. endfunc
  64. func Test_hlsearch_Ctrl_R()
  65. CheckRunVimInTerminal
  66. let lines =<< trim END
  67. set incsearch hlsearch
  68. let @" = "text"
  69. put
  70. END
  71. call writefile(lines, 'XhlsearchCtrlR', 'D')
  72. let buf = RunVimInTerminal('-S XhlsearchCtrlR', #{rows: 6, cols: 60})
  73. call term_sendkeys(buf, "/\<C-R>\<C-R>\"")
  74. call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {})
  75. call term_sendkeys(buf, "\<Esc>")
  76. call StopVimInTerminal(buf)
  77. endfunc
  78. func Test_hlsearch_clipboard()
  79. CheckRunVimInTerminal
  80. CheckFeature clipboard_working
  81. let lines =<< trim END
  82. set incsearch hlsearch
  83. let @* = "text"
  84. put *
  85. END
  86. call writefile(lines, 'XhlsearchClipboard', 'D')
  87. let buf = RunVimInTerminal('-S XhlsearchClipboard', #{rows: 6, cols: 60})
  88. call term_sendkeys(buf, "/\<C-R>*")
  89. call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {})
  90. call term_sendkeys(buf, "\<Esc>")
  91. call StopVimInTerminal(buf)
  92. endfunc
  93. " vim: shiftwidth=2 sts=2 expandtab