bufenter_spec.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local command = helpers.command
  4. local eq = helpers.eq
  5. local eval = helpers.eval
  6. local request = helpers.request
  7. local source = helpers.source
  8. describe('autocmd BufEnter', function()
  9. before_each(clear)
  10. it("triggered by nvim_command('edit <dir>')", function()
  11. command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif")
  12. request("nvim_command", "split .")
  13. eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
  14. eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
  15. end)
  16. it('triggered by "try|:split <dir>|endtry" in a function', function()
  17. command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif")
  18. source([[
  19. function! Test()
  20. try
  21. exe 'split .'
  22. catch
  23. endtry
  24. endfunction
  25. ]])
  26. command("call Test()")
  27. eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
  28. eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
  29. end)
  30. it('triggered by ":split normal|:help|:bw"', function()
  31. command("split normal")
  32. command("wincmd j")
  33. command("helptags runtime/doc")
  34. command("help")
  35. command("wincmd L")
  36. command("autocmd BufEnter normal let g:bufentered = 1")
  37. command("bw")
  38. eq(1, eval('bufnr("%")')) -- The cursor is back to the bottom window
  39. eq(0, eval("exists('g:bufentered')")) -- The autocmd hasn't been triggered
  40. end)
  41. end)