options_spec.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = helpers.clear
  4. local command = helpers.command
  5. local eq = helpers.eq
  6. local shallowcopy = helpers.shallowcopy
  7. describe('UI receives option updates', function()
  8. local screen
  9. local function reset(opts, ...)
  10. local defaults = {
  11. ambiwidth='single',
  12. arabicshape=true,
  13. emoji=true,
  14. guifont='',
  15. guifontwide='',
  16. linespace=0,
  17. pumblend=0,
  18. mousefocus=false,
  19. showtabline=1,
  20. termguicolors=false,
  21. ttimeout=true,
  22. ttimeoutlen=50,
  23. ext_cmdline=false,
  24. ext_popupmenu=false,
  25. ext_tabline=false,
  26. ext_wildmenu=false,
  27. ext_linegrid=false,
  28. ext_hlstate=false,
  29. ext_multigrid=false,
  30. ext_messages=false,
  31. ext_termcolors=false,
  32. }
  33. clear(...)
  34. screen = Screen.new(20,5)
  35. screen:attach(opts)
  36. -- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
  37. -- In both cases check that the received value is the one requested.
  38. defaults.ext_linegrid = screen._options.ext_linegrid or false
  39. return defaults
  40. end
  41. it("for defaults", function()
  42. local expected = reset()
  43. screen:expect(function()
  44. eq(expected, screen.options)
  45. end)
  46. end)
  47. it('on attach #11372', function()
  48. clear()
  49. local evs = {}
  50. screen = Screen.new(20,5)
  51. -- Override mouse_on/mouse_off handlers.
  52. function screen:_handle_mouse_on()
  53. table.insert(evs, 'mouse_on')
  54. end
  55. function screen:_handle_mouse_off()
  56. table.insert(evs, 'mouse_off')
  57. end
  58. screen:attach()
  59. screen:expect(function()
  60. eq({'mouse_off'}, evs)
  61. end)
  62. command("set mouse=nvi")
  63. screen:expect(function()
  64. eq({'mouse_off','mouse_on'}, evs)
  65. end)
  66. screen:detach()
  67. eq({'mouse_off','mouse_on'}, evs)
  68. screen:attach()
  69. screen:expect(function()
  70. eq({'mouse_off','mouse_on','mouse_on'}, evs)
  71. end)
  72. end)
  73. it("when setting options", function()
  74. local expected = reset()
  75. local defaults = shallowcopy(expected)
  76. command("set termguicolors")
  77. expected.termguicolors = true
  78. screen:expect(function()
  79. eq(expected, screen.options)
  80. end)
  81. command("set guifont=Comic\\ Sans")
  82. expected.guifont = "Comic Sans"
  83. screen:expect(function()
  84. eq(expected, screen.options)
  85. end)
  86. command("set showtabline=0")
  87. expected.showtabline = 0
  88. screen:expect(function()
  89. eq(expected, screen.options)
  90. end)
  91. command("set linespace=13")
  92. expected.linespace = 13
  93. screen:expect(function()
  94. eq(expected, screen.options)
  95. end)
  96. command("set linespace=-11")
  97. expected.linespace = -11
  98. screen:expect(function()
  99. eq(expected, screen.options)
  100. end)
  101. command("set mousefocus")
  102. expected.mousefocus = true
  103. screen:expect(function()
  104. eq(expected, screen.options)
  105. end)
  106. command("set nottimeout")
  107. expected.ttimeout = false
  108. screen:expect(function()
  109. eq(expected, screen.options)
  110. end)
  111. command("set ttimeoutlen=100")
  112. expected.ttimeoutlen = 100
  113. screen:expect(function()
  114. eq(expected, screen.options)
  115. end)
  116. command("set all&")
  117. screen:expect(function()
  118. eq(defaults, screen.options)
  119. end)
  120. end)
  121. it('with UI extensions', function()
  122. local expected = reset({ext_cmdline=true, ext_wildmenu=true})
  123. expected.ext_cmdline = true
  124. expected.ext_wildmenu = true
  125. screen:expect(function()
  126. eq(expected, screen.options)
  127. end)
  128. screen:set_option('ext_popupmenu', true)
  129. expected.ext_popupmenu = true
  130. screen:expect(function()
  131. eq(expected, screen.options)
  132. end)
  133. screen:set_option('ext_wildmenu', false)
  134. expected.ext_wildmenu = false
  135. screen:expect(function()
  136. eq(expected, screen.options)
  137. end)
  138. end)
  139. local function startup_test(headless)
  140. local expected = reset(nil, {args_rm=(headless and {} or {'--headless'}),
  141. args={'--cmd', 'set guifont=Comic\\ Sans\\ 12'}})
  142. expected.guifont = "Comic Sans 12"
  143. screen:expect(function()
  144. eq(expected, screen.options)
  145. end)
  146. end
  147. it('from startup options with --headless', function() startup_test(true) end)
  148. it('from startup options with --embed', function() startup_test(false) end)
  149. end)