options_spec.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. local global_helpers = require('test.helpers')
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local Screen = require('test.functional.ui.screen')
  4. local clear = helpers.clear
  5. local command = helpers.command
  6. local eq = helpers.eq
  7. local shallowcopy = global_helpers.shallowcopy
  8. describe('ui receives option updates', function()
  9. local screen
  10. local function reset(opts, ...)
  11. local defaults = {
  12. ambiwidth='single',
  13. arabicshape=true,
  14. emoji=true,
  15. guifont='',
  16. guifontset='',
  17. guifontwide='',
  18. linespace=0,
  19. showtabline=1,
  20. termguicolors=false,
  21. ext_cmdline=false,
  22. ext_popupmenu=false,
  23. ext_tabline=false,
  24. ext_wildmenu=false,
  25. ext_linegrid=false,
  26. ext_hlstate=false,
  27. }
  28. clear(...)
  29. screen = Screen.new(20,5)
  30. screen:attach(opts)
  31. -- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
  32. -- In both cases check that the received value is the one requested.
  33. defaults.ext_linegrid = screen._options.ext_linegrid or false
  34. return defaults
  35. end
  36. after_each(function()
  37. screen:detach()
  38. end)
  39. it("for defaults", function()
  40. local expected = reset()
  41. screen:expect(function()
  42. eq(expected, screen.options)
  43. end)
  44. end)
  45. it("when setting options", function()
  46. local expected = reset()
  47. local defaults = shallowcopy(expected)
  48. command("set termguicolors")
  49. expected.termguicolors = true
  50. screen:expect(function()
  51. eq(expected, screen.options)
  52. end)
  53. command("set guifont=Comic\\ Sans")
  54. expected.guifont = "Comic Sans"
  55. screen:expect(function()
  56. eq(expected, screen.options)
  57. end)
  58. command("set showtabline=0")
  59. expected.showtabline = 0
  60. screen:expect(function()
  61. eq(expected, screen.options)
  62. end)
  63. command("set linespace=13")
  64. expected.linespace = 13
  65. screen:expect(function()
  66. eq(expected, screen.options)
  67. end)
  68. command("set linespace=-11")
  69. expected.linespace = -11
  70. screen:expect(function()
  71. eq(expected, screen.options)
  72. end)
  73. command("set all&")
  74. screen:expect(function()
  75. eq(defaults, screen.options)
  76. end)
  77. end)
  78. it('with UI extensions', function()
  79. local expected = reset({ext_cmdline=true, ext_wildmenu=true})
  80. expected.ext_cmdline = true
  81. expected.ext_wildmenu = true
  82. screen:expect(function()
  83. eq(expected, screen.options)
  84. end)
  85. screen:set_option('ext_popupmenu', true)
  86. expected.ext_popupmenu = true
  87. screen:expect(function()
  88. eq(expected, screen.options)
  89. end)
  90. screen:set_option('ext_wildmenu', false)
  91. expected.ext_wildmenu = false
  92. screen:expect(function()
  93. eq(expected, screen.options)
  94. end)
  95. end)
  96. local function startup_test(headless)
  97. local expected = reset(nil,{headless=headless,args={'--cmd', 'set guifont=Comic\\ Sans\\ 12'}})
  98. expected.guifont = "Comic Sans 12"
  99. screen:expect(function()
  100. eq(expected, screen.options)
  101. end)
  102. end
  103. it('from startup options with --headless', function() startup_test(true) end)
  104. it('from startup options with --embed', function() startup_test(false) end)
  105. end)