autocmd_spec.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local eq = helpers.eq
  3. local eval = helpers.eval
  4. local clear = helpers.clear
  5. local meths = helpers.meths
  6. local expect = helpers.expect
  7. local command = helpers.command
  8. local exc_exec = helpers.exc_exec
  9. local curbufmeths = helpers.curbufmeths
  10. describe('autocmds:', function()
  11. before_each(clear)
  12. it(':tabnew triggers events in the correct order', function()
  13. local expected = {
  14. 'WinLeave',
  15. 'TabLeave',
  16. 'WinEnter',
  17. 'TabNew',
  18. 'TabEnter',
  19. 'BufLeave',
  20. 'BufEnter'
  21. }
  22. command('let g:foo = []')
  23. command('autocmd BufEnter * :call add(g:foo, "BufEnter")')
  24. command('autocmd BufLeave * :call add(g:foo, "BufLeave")')
  25. command('autocmd TabEnter * :call add(g:foo, "TabEnter")')
  26. command('autocmd TabLeave * :call add(g:foo, "TabLeave")')
  27. command('autocmd TabNew * :call add(g:foo, "TabNew")')
  28. command('autocmd WinEnter * :call add(g:foo, "WinEnter")')
  29. command('autocmd WinLeave * :call add(g:foo, "WinLeave")')
  30. command('tabnew')
  31. assert.same(expected, eval('g:foo'))
  32. end)
  33. it('v:vim_did_enter is 1 after VimEnter', function()
  34. eq(1, eval('v:vim_did_enter'))
  35. end)
  36. describe('BufLeave autocommand', function()
  37. it('can wipe out the buffer created by :edit which triggered autocmd',
  38. function()
  39. meths.set_option('hidden', true)
  40. curbufmeths.set_lines(0, 1, false, {
  41. 'start of test file xx',
  42. 'end of test file xx'})
  43. command('autocmd BufLeave * bwipeout yy')
  44. eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy',
  45. exc_exec('edit yy'))
  46. expect([[
  47. start of test file xx
  48. end of test file xx]])
  49. end)
  50. end)
  51. end)