cursormoved_spec.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local eq = t.eq
  5. local eval = n.eval
  6. local api = n.api
  7. local source = n.source
  8. local command = n.command
  9. describe('CursorMoved', function()
  10. before_each(clear)
  11. it('is triggered after BufEnter when changing or splitting windows #11878 #12031', function()
  12. source([[
  13. call setline(1, 'foo')
  14. let g:log = []
  15. autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
  16. autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
  17. ]])
  18. eq({}, eval('g:log'))
  19. command('new')
  20. eq({ 'BufEnter2', 'CursorMoved2' }, eval('g:log'))
  21. command('wincmd w')
  22. eq({ 'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1' }, eval('g:log'))
  23. end)
  24. it('is not triggered by temporarily switching window', function()
  25. source([[
  26. let g:cursormoved = 0
  27. vnew
  28. autocmd CursorMoved * let g:cursormoved += 1
  29. ]])
  30. command('wincmd w | wincmd p')
  31. eq(0, eval('g:cursormoved'))
  32. end)
  33. it("is not triggered by functions that don't change the window", function()
  34. source([[
  35. let g:cursormoved = 0
  36. let g:buf = bufnr('%')
  37. vsplit foo
  38. autocmd CursorMoved * let g:cursormoved += 1
  39. ]])
  40. api.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' })
  41. eq(0, eval('g:cursormoved'))
  42. eq({ 'aaa' }, api.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
  43. eq(0, eval('g:cursormoved'))
  44. end)
  45. it('is not triggered by cursor movement prior to first CursorMoved instantiation', function()
  46. source([[
  47. let g:cursormoved = 0
  48. autocmd! CursorMoved
  49. autocmd CursorMoved * let g:cursormoved += 1
  50. ]])
  51. eq(0, eval('g:cursormoved'))
  52. end)
  53. end)