robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
6.7 KiB268 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local command = n.command
8local eq = t.eq
9local shallowcopy = t.shallowcopy
10local eval = n.eval
11
12describe('UI receives option updates', function()
13  local screen
14
15  local function reset(screen_opts, clear_opts)
16    local defaults = {
17      ambiwidth = 'single',
18      arabicshape = true,
19      emoji = true,
20      guifont = '',
21      guifontwide = '',
22      linespace = 0,
23      pumblend = 0,
24      mousefocus = false,
25      mousehide = true,
26      mousemoveevent = false,
27      showtabline = 1,
28      termguicolors = false,
29      termsync = true,
30      ttimeout = true,
31      ttimeoutlen = 50,
32      verbose = 0,
33      ext_cmdline = false,
34      ext_popupmenu = false,
35      ext_tabline = false,
36      ext_wildmenu = false,
37      ext_linegrid = false,
38      ext_hlstate = false,
39      ext_multigrid = false,
40      ext_messages = false,
41      ext_termcolors = false,
42    }
43
44    clear_opts = shallowcopy(clear_opts or {})
45    clear_opts.args_rm = clear_opts.args_rm or {}
46    table.insert(clear_opts.args_rm or {}, '--cmd')
47    clear(clear_opts)
48    screen = Screen.new(20, 5, screen_opts)
49    defaults.guifont = eval('&guifont')
50    -- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
51    -- In both cases check that the received value is the one requested.
52    defaults.ext_linegrid = screen._options.ext_linegrid or false
53    return defaults
54  end
55
56  it('for defaults', function()
57    local expected = reset()
58    screen:expect(function()
59      eq(expected, screen.options)
60    end)
61  end)
62
63  it('on attach #11372', function()
64    clear { args_rm = { '--headless' } }
65    local evs = {}
66    screen = Screen.new(20, 5)
67    -- Override mouse_on/mouse_off handlers.
68    function screen:_handle_mouse_on()
69      table.insert(evs, 'mouse_on')
70    end
71    function screen:_handle_mouse_off()
72      table.insert(evs, 'mouse_off')
73    end
74    screen:expect(function()
75      eq({ 'mouse_on' }, evs)
76    end)
77    command('set mouse=')
78    screen:expect(function()
79      eq({ 'mouse_on', 'mouse_off' }, evs)
80    end)
81    command('set mouse&')
82    screen:expect(function()
83      eq({ 'mouse_on', 'mouse_off', 'mouse_on' }, evs)
84    end)
85    screen:detach()
86    eq({ 'mouse_on', 'mouse_off', 'mouse_on' }, evs)
87    screen:attach()
88    screen:expect(function()
89      eq({ 'mouse_on', 'mouse_off', 'mouse_on', 'mouse_on' }, evs)
90    end)
91  end)
92
93  it('when setting options', function()
94    local expected = reset()
95    local defaults = shallowcopy(expected)
96
97    command('set termguicolors')
98    expected.termguicolors = true
99    screen:expect(function()
100      eq(expected, screen.options)
101    end)
102
103    command('set pumblend=50')
104    expected.pumblend = 50
105    screen:expect(function()
106      eq(expected, screen.options)
107    end)
108
109    -- check handling of out-of-bounds value
110    command('set pumblend=-1')
111    expected.pumblend = 0
112    screen:expect(function()
113      eq(expected, screen.options)
114    end)
115
116    command('set guifont=Comic\\ Sans')
117    expected.guifont = 'Comic Sans'
118    screen:expect(function()
119      eq(expected, screen.options)
120    end)
121
122    command('set showtabline=0')
123    expected.showtabline = 0
124    screen:expect(function()
125      eq(expected, screen.options)
126    end)
127
128    command('set linespace=13')
129    expected.linespace = 13
130    screen:expect(function()
131      eq(expected, screen.options)
132    end)
133
134    command('set linespace=-11')
135    expected.linespace = -11
136    screen:expect(function()
137      eq(expected, screen.options)
138    end)
139
140    command('set mousefocus')
141    expected.mousefocus = true
142    screen:expect(function()
143      eq(expected, screen.options)
144    end)
145
146    command('set nomousehide')
147    expected.mousehide = false
148    screen:expect(function()
149      eq(expected, screen.options)
150    end)
151
152    command('set mousemoveevent')
153    expected.mousemoveevent = true
154    screen:expect(function()
155      eq(expected, screen.options)
156    end)
157
158    command('set nottimeout')
159    expected.ttimeout = false
160    screen:expect(function()
161      eq(expected, screen.options)
162    end)
163
164    command('set ttimeoutlen=100')
165    expected.ttimeoutlen = 100
166    screen:expect(function()
167      eq(expected, screen.options)
168    end)
169
170    command('set all&')
171    screen:expect(function()
172      eq(defaults, screen.options)
173    end)
174  end)
175
176  it("restores statusline and tabline after 'set all&'", function()
177    reset()
178    command('tabnew | tabnew')
179    command('set laststatus=0 showtabline=0')
180    screen:expect({
181      unchanged = true,
182      condition = function()
183        local function row_text(row)
184          local chunks = {}
185          for _, cell in ipairs(screen._grid.rows[row]) do
186            table.insert(chunks, cell.text)
187          end
188          return table.concat(chunks)
189        end
190
191        eq(nil, row_text(1):find('%[No Name%]'))
192        eq(nil, row_text(screen._grid.height - 1):find('All', 1, true))
193      end,
194    })
195
196    command('set all&')
197    screen:expect({
198      unchanged = true,
199      any = { '[No Name]', 'All' },
200    })
201  end)
202
203  it('with UI extensions', function()
204    local expected = reset({ ext_cmdline = true, ext_wildmenu = true })
205
206    expected.ext_cmdline = true
207    expected.ext_wildmenu = true
208    screen:expect(function()
209      eq(expected, screen.options)
210    end)
211
212    screen:set_option('ext_popupmenu', true)
213    expected.ext_popupmenu = true
214    screen:expect(function()
215      eq(expected, screen.options)
216    end)
217
218    screen:set_option('ext_wildmenu', false)
219    expected.ext_wildmenu = false
220    screen:expect(function()
221      eq(expected, screen.options)
222    end)
223  end)
224
225  local function startup_test(headless)
226    local expected = reset(nil, {
227      args_rm = (headless and {} or { '--headless' }),
228      args = { '--cmd', 'set guifont=Comic\\ Sans\\ 12' },
229    })
230    expected.guifont = 'Comic Sans 12'
231    screen:expect(function()
232      eq(expected, screen.options)
233    end)
234  end
235
236  it('from startup options with --headless', function()
237    startup_test(true)
238  end)
239  it('from startup options with --embed', function()
240    startup_test(false)
241  end)
242end)
243
244describe('UI can set terminal option', function()
245  before_each(function()
246    -- by default we implicitly "--cmd 'set bg=light'" which ruins everything
247    clear { args_rm = { '--cmd' } }
248  end)
249
250  it('term_name', function()
251    eq('nvim', eval '&term')
252
253    local _ = Screen.new(20, 5, { term_name = 'xterm' })
254    eq('xterm', eval '&term')
255  end)
256
257  it('term_colors', function()
258    eq('256', eval '&t_Co')
259
260    local screen = Screen.new(20, 5, { term_colors = 8 })
261    eq('8', eval '&t_Co')
262    screen:detach()
263
264    screen = Screen.new(20, 5, { term_colors = 16777216 })
265    eq('16777216', eval '&t_Co')
266    screen:detach()
267  end)
268end)