safestate_spec.lua 1.2 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 exec = n.exec
  6. local feed = n.feed
  7. local api = n.api
  8. before_each(clear)
  9. describe('SafeState autocommand', function()
  10. local function create_autocmd()
  11. exec([[
  12. let g:safe = 0
  13. autocmd SafeState * ++once let g:safe += 1
  14. ]])
  15. end
  16. it('with pending operator', function()
  17. feed('d')
  18. create_autocmd()
  19. eq(0, api.nvim_get_var('safe'))
  20. feed('d')
  21. eq(1, api.nvim_get_var('safe'))
  22. end)
  23. it('with specified register', function()
  24. feed('"r')
  25. create_autocmd()
  26. eq(0, api.nvim_get_var('safe'))
  27. feed('x')
  28. eq(1, api.nvim_get_var('safe'))
  29. end)
  30. it('with i_CTRL-O', function()
  31. feed('i<C-O>')
  32. create_autocmd()
  33. eq(0, api.nvim_get_var('safe'))
  34. feed('x')
  35. eq(1, api.nvim_get_var('safe'))
  36. end)
  37. it('with Insert mode completion', function()
  38. feed('i<C-X><C-V>')
  39. create_autocmd()
  40. eq(0, api.nvim_get_var('safe'))
  41. feed('<C-X><C-Z>')
  42. eq(1, api.nvim_get_var('safe'))
  43. end)
  44. it('with Cmdline completion', function()
  45. feed(':<Tab>')
  46. create_autocmd()
  47. eq(0, api.nvim_get_var('safe'))
  48. feed('<C-E>')
  49. eq(1, api.nvim_get_var('safe'))
  50. end)
  51. end)