options_spec.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 shallowcopy = t.shallowcopy
  8. local eval = n.eval
  9. describe('UI receives option updates', function()
  10. local screen
  11. local function reset(screen_opts, clear_opts)
  12. local defaults = {
  13. ambiwidth = 'single',
  14. arabicshape = true,
  15. emoji = true,
  16. guifont = '',
  17. guifontwide = '',
  18. linespace = 0,
  19. pumblend = 0,
  20. mousefocus = false,
  21. mousehide = true,
  22. mousemoveevent = false,
  23. showtabline = 1,
  24. termguicolors = false,
  25. termsync = true,
  26. ttimeout = true,
  27. ttimeoutlen = 50,
  28. verbose = 0,
  29. ext_cmdline = false,
  30. ext_popupmenu = false,
  31. ext_tabline = false,
  32. ext_wildmenu = false,
  33. ext_linegrid = false,
  34. ext_hlstate = false,
  35. ext_multigrid = false,
  36. ext_messages = false,
  37. ext_termcolors = false,
  38. }
  39. clear_opts = shallowcopy(clear_opts or {})
  40. clear_opts.args_rm = clear_opts.args_rm or {}
  41. table.insert(clear_opts.args_rm or {}, '--cmd')
  42. clear(clear_opts)
  43. screen = Screen.new(20, 5, screen_opts)
  44. -- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
  45. -- In both cases check that the received value is the one requested.
  46. defaults.ext_linegrid = screen._options.ext_linegrid or false
  47. return defaults
  48. end
  49. it('for defaults', function()
  50. local expected = reset()
  51. screen:expect(function()
  52. eq(expected, screen.options)
  53. end)
  54. end)
  55. it('on attach #11372', function()
  56. clear { args_rm = { '--headless' } }
  57. local evs = {}
  58. screen = Screen.new(20, 5)
  59. -- Override mouse_on/mouse_off handlers.
  60. function screen:_handle_mouse_on()
  61. table.insert(evs, 'mouse_on')
  62. end
  63. function screen:_handle_mouse_off()
  64. table.insert(evs, 'mouse_off')
  65. end
  66. screen:expect(function()
  67. eq({ 'mouse_on' }, evs)
  68. end)
  69. command('set mouse=')
  70. screen:expect(function()
  71. eq({ 'mouse_on', 'mouse_off' }, evs)
  72. end)
  73. command('set mouse&')
  74. screen:expect(function()
  75. eq({ 'mouse_on', 'mouse_off', 'mouse_on' }, evs)
  76. end)
  77. screen:detach()
  78. eq({ 'mouse_on', 'mouse_off', 'mouse_on' }, evs)
  79. screen:attach()
  80. screen:expect(function()
  81. eq({ 'mouse_on', 'mouse_off', 'mouse_on', 'mouse_on' }, evs)
  82. end)
  83. end)
  84. it('when setting options', function()
  85. local expected = reset()
  86. local defaults = shallowcopy(expected)
  87. command('set termguicolors')
  88. expected.termguicolors = true
  89. screen:expect(function()
  90. eq(expected, screen.options)
  91. end)
  92. command('set pumblend=50')
  93. expected.pumblend = 50
  94. screen:expect(function()
  95. eq(expected, screen.options)
  96. end)
  97. -- check handling of out-of-bounds value
  98. command('set pumblend=-1')
  99. expected.pumblend = 0
  100. screen:expect(function()
  101. eq(expected, screen.options)
  102. end)
  103. command('set guifont=Comic\\ Sans')
  104. expected.guifont = 'Comic Sans'
  105. screen:expect(function()
  106. eq(expected, screen.options)
  107. end)
  108. command('set showtabline=0')
  109. expected.showtabline = 0
  110. screen:expect(function()
  111. eq(expected, screen.options)
  112. end)
  113. command('set linespace=13')
  114. expected.linespace = 13
  115. screen:expect(function()
  116. eq(expected, screen.options)
  117. end)
  118. command('set linespace=-11')
  119. expected.linespace = -11
  120. screen:expect(function()
  121. eq(expected, screen.options)
  122. end)
  123. command('set mousefocus')
  124. expected.mousefocus = true
  125. screen:expect(function()
  126. eq(expected, screen.options)
  127. end)
  128. command('set nomousehide')
  129. expected.mousehide = false
  130. screen:expect(function()
  131. eq(expected, screen.options)
  132. end)
  133. command('set mousemoveevent')
  134. expected.mousemoveevent = true
  135. screen:expect(function()
  136. eq(expected, screen.options)
  137. end)
  138. command('set nottimeout')
  139. expected.ttimeout = false
  140. screen:expect(function()
  141. eq(expected, screen.options)
  142. end)
  143. command('set ttimeoutlen=100')
  144. expected.ttimeoutlen = 100
  145. screen:expect(function()
  146. eq(expected, screen.options)
  147. end)
  148. command('set all&')
  149. screen:expect(function()
  150. eq(defaults, screen.options)
  151. end)
  152. end)
  153. it('with UI extensions', function()
  154. local expected = reset({ ext_cmdline = true, ext_wildmenu = true })
  155. expected.ext_cmdline = true
  156. expected.ext_wildmenu = true
  157. screen:expect(function()
  158. eq(expected, screen.options)
  159. end)
  160. screen:set_option('ext_popupmenu', true)
  161. expected.ext_popupmenu = true
  162. screen:expect(function()
  163. eq(expected, screen.options)
  164. end)
  165. screen:set_option('ext_wildmenu', false)
  166. expected.ext_wildmenu = false
  167. screen:expect(function()
  168. eq(expected, screen.options)
  169. end)
  170. end)
  171. local function startup_test(headless)
  172. local expected = reset(nil, {
  173. args_rm = (headless and {} or { '--headless' }),
  174. args = { '--cmd', 'set guifont=Comic\\ Sans\\ 12' },
  175. })
  176. expected.guifont = 'Comic Sans 12'
  177. screen:expect(function()
  178. eq(expected, screen.options)
  179. end)
  180. end
  181. it('from startup options with --headless', function()
  182. startup_test(true)
  183. end)
  184. it('from startup options with --embed', function()
  185. startup_test(false)
  186. end)
  187. end)
  188. describe('UI can set terminal option', function()
  189. before_each(function()
  190. -- by default we implicitly "--cmd 'set bg=light'" which ruins everything
  191. clear { args_rm = { '--cmd' } }
  192. end)
  193. it('term_name', function()
  194. eq('nvim', eval '&term')
  195. local _ = Screen.new(20, 5, { term_name = 'xterm' })
  196. eq('xterm', eval '&term')
  197. end)
  198. it('term_colors', function()
  199. eq('256', eval '&t_Co')
  200. local _ = Screen.new(20, 5, { term_colors = 8 })
  201. eq('8', eval '&t_Co')
  202. end)
  203. end)