101_hlsearch_spec.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. -- Test for v:hlsearch
  2. local n = require('test.functional.testnvim')()
  3. local clear, feed = n.clear, n.feed
  4. local feed_command, expect = n.feed_command, n.expect
  5. describe('v:hlsearch', function()
  6. setup(clear)
  7. it('is working', function()
  8. -- Last abc: Q
  9. feed_command('new')
  10. feed_command([[call setline(1, repeat(['aaa'], 10))]])
  11. feed_command('set hlsearch nolazyredraw')
  12. feed_command('let r=[]')
  13. feed_command('command -nargs=0 -bar AddR :call add(r, [screenattr(1, 1), v:hlsearch])')
  14. feed_command('/aaa')
  15. feed_command('AddR')
  16. feed_command('nohlsearch')
  17. feed_command('AddR')
  18. feed_command('let v:hlsearch=1')
  19. feed_command('AddR')
  20. feed_command('let v:hlsearch=0')
  21. feed_command('AddR')
  22. feed_command('set hlsearch')
  23. feed_command('AddR')
  24. feed_command('let v:hlsearch=0')
  25. feed_command('AddR')
  26. feed('n:AddR<cr>')
  27. feed_command('let v:hlsearch=0')
  28. feed_command('AddR')
  29. feed_command('/')
  30. feed_command('AddR')
  31. feed_command('set nohls')
  32. feed_command('/')
  33. feed_command('AddR')
  34. feed_command('let r1=r[0][0]')
  35. -- I guess it is not guaranteed that screenattr outputs always the same character
  36. feed_command([[call map(r, 'v:val[1].":".(v:val[0]==r1?"highlighted":"not highlighted")')]])
  37. feed_command('try')
  38. feed_command(' let v:hlsearch=[]')
  39. feed_command('catch')
  40. feed_command([[ call add(r, matchstr(v:exception,'^Vim(let):E\d\+:'))]])
  41. feed_command('endtry')
  42. feed_command('bwipeout!')
  43. feed_command('$put=r')
  44. feed_command('call garbagecollect(1)')
  45. feed_command('call getchar()')
  46. feed_command('1d', '1d')
  47. -- Assert buffer contents.
  48. expect([[
  49. 1:highlighted
  50. 0:not highlighted
  51. 1:highlighted
  52. 0:not highlighted
  53. 1:highlighted
  54. 0:not highlighted
  55. 1:highlighted
  56. 0:not highlighted
  57. 1:highlighted
  58. 0:not highlighted
  59. Vim(let):E745:]])
  60. end)
  61. end)