ui_spec.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = helpers.clear
  4. local eq = helpers.eq
  5. local eval = helpers.eval
  6. local meths = helpers.meths
  7. local request = helpers.request
  8. local pcall_err = helpers.pcall_err
  9. describe('nvim_ui_attach()', function()
  10. before_each(function()
  11. clear()
  12. end)
  13. it('handles very large width/height #2180', function()
  14. local screen = Screen.new(999, 999)
  15. screen:attach()
  16. eq(999, eval('&lines'))
  17. eq(999, eval('&columns'))
  18. end)
  19. it('invalid option returns error', function()
  20. eq('No such UI option: foo',
  21. pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} }))
  22. end)
  23. it('validates channel arg', function()
  24. eq('UI not attached to channel: 1',
  25. pcall_err(request, 'nvim_ui_try_resize', 40, 10))
  26. eq('UI not attached to channel: 1',
  27. pcall_err(request, 'nvim_ui_set_option', 'rgb', true))
  28. eq('UI not attached to channel: 1',
  29. pcall_err(request, 'nvim_ui_detach'))
  30. local screen = Screen.new()
  31. screen:attach({rgb=false})
  32. eq('UI already attached to channel: 1',
  33. pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb=false }))
  34. end)
  35. end)
  36. it('autocmds UIEnter/UILeave', function()
  37. clear{
  38. args_rm={'--headless'},
  39. args={
  40. '--cmd', 'let g:evs = []',
  41. '--cmd', 'autocmd UIEnter * :call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)',
  42. '--cmd', 'autocmd UILeave * :call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)',
  43. '--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")',
  44. }}
  45. local screen = Screen.new()
  46. screen:attach()
  47. eq({chan=1}, eval('g:uienter_ev'))
  48. screen:detach()
  49. eq({chan=1}, eval('g:uileave_ev'))
  50. eq({
  51. 'VimEnter',
  52. 'UIEnter',
  53. 'UILeave',
  54. }, eval('g:evs'))
  55. end)