ui_spec.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear = n.clear
  5. local command = n.command
  6. local eq = t.eq
  7. local eval = n.eval
  8. local exec = n.exec
  9. local feed = n.feed
  10. local api = n.api
  11. local request = n.request
  12. local pcall_err = t.pcall_err
  13. describe('nvim_ui_attach()', function()
  14. before_each(function()
  15. clear()
  16. end)
  17. it('handles very large width/height #2180', function()
  18. local _ = Screen.new(999, 999)
  19. eq(999, eval('&lines'))
  20. eq(999, eval('&columns'))
  21. end)
  22. it('validation', function()
  23. eq('No such UI option: foo', pcall_err(api.nvim_ui_attach, 80, 24, { foo = { 'foo' } }))
  24. eq(
  25. "Invalid 'ext_linegrid': expected Boolean, got Array",
  26. pcall_err(api.nvim_ui_attach, 80, 24, { ext_linegrid = {} })
  27. )
  28. eq(
  29. "Invalid 'override': expected Boolean, got Array",
  30. pcall_err(api.nvim_ui_attach, 80, 24, { override = {} })
  31. )
  32. eq(
  33. "Invalid 'rgb': expected Boolean, got Array",
  34. pcall_err(api.nvim_ui_attach, 80, 24, { rgb = {} })
  35. )
  36. eq(
  37. "Invalid 'term_name': expected String, got Boolean",
  38. pcall_err(api.nvim_ui_attach, 80, 24, { term_name = true })
  39. )
  40. eq(
  41. "Invalid 'term_colors': expected Integer, got Boolean",
  42. pcall_err(api.nvim_ui_attach, 80, 24, { term_colors = true })
  43. )
  44. eq(
  45. "Invalid 'stdin_fd': expected Integer, got String",
  46. pcall_err(api.nvim_ui_attach, 80, 24, { stdin_fd = 'foo' })
  47. )
  48. eq(
  49. "Invalid 'stdin_tty': expected Boolean, got String",
  50. pcall_err(api.nvim_ui_attach, 80, 24, { stdin_tty = 'foo' })
  51. )
  52. eq(
  53. "Invalid 'stdout_tty': expected Boolean, got String",
  54. pcall_err(api.nvim_ui_attach, 80, 24, { stdout_tty = 'foo' })
  55. )
  56. eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_try_resize', 40, 10))
  57. eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_set_option', 'rgb', true))
  58. eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_detach'))
  59. local _ = Screen.new(nil, nil, { rgb = false })
  60. eq(
  61. 'UI already attached to channel: 1',
  62. pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb = false })
  63. )
  64. end)
  65. end)
  66. it('autocmds UIEnter/UILeave', function()
  67. clear { args_rm = { '--headless' } }
  68. exec([[
  69. let g:evs = []
  70. autocmd UIEnter * call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)
  71. autocmd UILeave * call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)
  72. autocmd VimEnter * call add(g:evs, "VimEnter")
  73. ]])
  74. local screen = Screen.new()
  75. eq({ chan = 1 }, eval('g:uienter_ev'))
  76. screen:detach()
  77. eq({ chan = 1 }, eval('g:uileave_ev'))
  78. eq({
  79. 'VimEnter',
  80. 'UIEnter',
  81. 'UILeave',
  82. }, eval('g:evs'))
  83. end)
  84. it('autocmds VimSuspend/VimResume #22041', function()
  85. clear()
  86. local screen = Screen.new()
  87. exec([[
  88. let g:ev = []
  89. autocmd VimResume * :call add(g:ev, 'r')
  90. autocmd VimSuspend * :call add(g:ev, 's')
  91. ]])
  92. eq(false, screen.suspended)
  93. feed('<C-Z>')
  94. screen:expect(function()
  95. eq(true, screen.suspended)
  96. end)
  97. eq({ 's' }, eval('g:ev'))
  98. screen.suspended = false
  99. feed('<Ignore>')
  100. eq({ 's', 'r' }, eval('g:ev'))
  101. command('suspend')
  102. screen:expect(function()
  103. eq(true, screen.suspended)
  104. end)
  105. eq({ 's', 'r', 's' }, eval('g:ev'))
  106. screen.suspended = false
  107. api.nvim_input_mouse('move', '', '', 0, 0, 0)
  108. eq({ 's', 'r', 's', 'r' }, eval('g:ev'))
  109. feed('<C-Z><C-Z><C-Z>')
  110. screen:expect(function()
  111. eq(true, screen.suspended)
  112. end)
  113. api.nvim_ui_set_focus(false)
  114. eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev'))
  115. screen.suspended = false
  116. api.nvim_ui_set_focus(true)
  117. eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
  118. command('suspend | suspend | suspend')
  119. screen:expect(function()
  120. eq(true, screen.suspended)
  121. end)
  122. screen:detach()
  123. eq({ 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev'))
  124. screen.suspended = false
  125. screen:attach()
  126. eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
  127. end)