robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
47.4 KiB1410 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, pending = t.describe, t.it, t.before_each, t.pending
6local NIL = vim.NIL
7local feed = n.feed
8local command = n.command
9local clear = n.clear
10local api = n.api
11local eq = t.eq
12local eval = n.eval
13local exec = n.exec
14local exec_lua = n.exec_lua
15local fn = n.fn
16local matches = t.matches
17local mkdir_p = n.mkdir_p
18local pcall_err = t.pcall_err
19local rmdir = n.rmdir
20local write_file = t.write_file
21
22local function eq_exec_lua(expected, f)
23  eq(expected, exec_lua(f))
24end
25
26describe('lua stdlib', function()
27  before_each(clear)
28
29  describe('variables', function()
30    it('vim.g', function()
31      exec_lua(function()
32        vim.api.nvim_set_var('testing', 'hi')
33        vim.api.nvim_set_var('other', 123)
34        vim.api.nvim_set_var('floaty', 5120.1)
35        vim.api.nvim_set_var('nullvar', vim.NIL)
36        vim.api.nvim_set_var('to_delete', { hello = 'world' })
37      end)
38
39      eq('hi', fn.luaeval 'vim.g.testing')
40      eq(123, fn.luaeval 'vim.g.other')
41      eq(5120.1, fn.luaeval 'vim.g.floaty')
42      eq(NIL, fn.luaeval 'vim.g.nonexistent')
43      eq(NIL, fn.luaeval 'vim.g.nullvar')
44      -- lost over RPC, so test locally:
45      eq_exec_lua({ false, true }, function()
46        return { vim.g.nonexistent == vim.NIL, vim.g.nullvar == vim.NIL }
47      end)
48
49      eq({ hello = 'world' }, fn.luaeval 'vim.g.to_delete')
50      exec_lua [[
51      vim.g.to_delete = nil
52      ]]
53      eq(NIL, fn.luaeval 'vim.g.to_delete')
54
55      matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.g[0].testing'))
56
57      exec_lua(function()
58        local counter = 0
59        local function add_counter()
60          counter = counter + 1
61        end
62        local function get_counter()
63          return counter
64        end
65        vim.g.AddCounter = add_counter
66        vim.g.GetCounter = get_counter
67        vim.g.fn = { add = add_counter, get = get_counter }
68        vim.g.AddParens = function(s)
69          return '(' .. s .. ')'
70        end
71      end)
72
73      eq(0, eval('g:GetCounter()'))
74      eval('g:AddCounter()')
75      eq(1, eval('g:GetCounter()'))
76      eval('g:AddCounter()')
77      eq(2, eval('g:GetCounter()'))
78      exec_lua([[vim.g.AddCounter()]])
79      eq(3, exec_lua([[return vim.g.GetCounter()]]))
80      exec_lua([[vim.api.nvim_get_var('AddCounter')()]])
81      eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]]))
82      exec_lua([[vim.g.fn.add()]])
83      eq(5, exec_lua([[return vim.g.fn.get()]]))
84      exec_lua([[vim.api.nvim_get_var('fn').add()]])
85      eq(6, exec_lua([[return vim.api.nvim_get_var('fn').get()]]))
86      eq('((foo))', eval([['foo'->AddParens()->AddParens()]]))
87
88      exec_lua(function()
89        local counter = 0
90        local function add_counter()
91          counter = counter + 1
92        end
93        local function get_counter()
94          return counter
95        end
96        vim.api.nvim_set_var('AddCounter', add_counter)
97        vim.api.nvim_set_var('GetCounter', get_counter)
98        vim.api.nvim_set_var('fn', { add = add_counter, get = get_counter })
99        vim.api.nvim_set_var('AddParens', function(s)
100          return '(' .. s .. ')'
101        end)
102      end)
103
104      eq(0, eval('g:GetCounter()'))
105      eval('g:AddCounter()')
106      eq(1, eval('g:GetCounter()'))
107      eval('g:AddCounter()')
108      eq(2, eval('g:GetCounter()'))
109      exec_lua([[vim.g.AddCounter()]])
110      eq(3, exec_lua([[return vim.g.GetCounter()]]))
111      exec_lua([[vim.api.nvim_get_var('AddCounter')()]])
112      eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]]))
113      exec_lua([[vim.g.fn.add()]])
114      eq(5, exec_lua([[return vim.g.fn.get()]]))
115      exec_lua([[vim.api.nvim_get_var('fn').add()]])
116      eq(6, exec_lua([[return vim.api.nvim_get_var('fn').get()]]))
117      eq('((foo))', eval([['foo'->AddParens()->AddParens()]]))
118
119      exec([[
120        function Test()
121        endfunction
122        function s:Test()
123        endfunction
124        let g:Unknown_func = function('Test')
125        let g:Unknown_script_func = function('s:Test')
126      ]])
127      eq(NIL, exec_lua([[return vim.g.Unknown_func]]))
128      eq(NIL, exec_lua([[return vim.g.Unknown_script_func]]))
129
130      -- Check if autoload works properly
131      local pathsep = n.get_pathsep()
132      local xhome = 'Xhome_lua'
133      local xconfig = xhome .. pathsep .. 'Xconfig'
134      local xdata = xhome .. pathsep .. 'Xdata'
135      local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep)
136      local autoload_file = table.concat({ autoload_folder, 'testload.vim' }, pathsep)
137      mkdir_p(autoload_folder)
138      write_file(autoload_file, [[let testload#value = 2]])
139
140      clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } }
141
142      eq(2, exec_lua("return vim.g['testload#value']"))
143      rmdir(xhome)
144    end)
145
146    it('vim.b', function()
147      exec_lua(function()
148        vim.api.nvim_buf_set_var(0, 'testing', 'hi')
149        vim.api.nvim_buf_set_var(0, 'other', 123)
150        vim.api.nvim_buf_set_var(0, 'floaty', 5120.1)
151        vim.api.nvim_buf_set_var(0, 'nullvar', vim.NIL)
152        vim.api.nvim_buf_set_var(0, 'to_delete', { hello = 'world' })
153        _G.BUF = vim.api.nvim_create_buf(false, true)
154        vim.api.nvim_buf_set_var(_G.BUF, 'testing', 'bye')
155      end)
156
157      eq('hi', fn.luaeval 'vim.b.testing')
158      eq('bye', fn.luaeval 'vim.b[BUF].testing')
159      eq(123, fn.luaeval 'vim.b.other')
160      eq(5120.1, fn.luaeval 'vim.b.floaty')
161      eq(NIL, fn.luaeval 'vim.b.nonexistent')
162      eq(NIL, fn.luaeval 'vim.b[BUF].nonexistent')
163      eq(NIL, fn.luaeval 'vim.b.nullvar')
164      -- lost over RPC, so test locally:
165      eq_exec_lua({ false, true }, function()
166        return { vim.b.nonexistent == vim.NIL, vim.b.nullvar == vim.NIL }
167      end)
168
169      matches(
170        [[attempt to index .* nil value]],
171        pcall_err(exec_lua, 'return vim.b[BUF][0].testing')
172      )
173
174      eq({ hello = 'world' }, fn.luaeval 'vim.b.to_delete')
175      exec_lua [[
176      vim.b.to_delete = nil
177      ]]
178      eq(NIL, fn.luaeval 'vim.b.to_delete')
179
180      exec_lua(function()
181        local counter = 0
182        local function add_counter()
183          counter = counter + 1
184        end
185        local function get_counter()
186          return counter
187        end
188        vim.b.AddCounter = add_counter
189        vim.b.GetCounter = get_counter
190        vim.b.fn = { add = add_counter, get = get_counter }
191        vim.b.AddParens = function(s)
192          return '(' .. s .. ')'
193        end
194      end)
195
196      eq(0, eval('b:GetCounter()'))
197      eval('b:AddCounter()')
198      eq(1, eval('b:GetCounter()'))
199      eval('b:AddCounter()')
200      eq(2, eval('b:GetCounter()'))
201      exec_lua([[vim.b.AddCounter()]])
202      eq(3, exec_lua([[return vim.b.GetCounter()]]))
203      exec_lua([[vim.api.nvim_buf_get_var(0, 'AddCounter')()]])
204      eq(4, exec_lua([[return vim.api.nvim_buf_get_var(0, 'GetCounter')()]]))
205      exec_lua([[vim.b.fn.add()]])
206      eq(5, exec_lua([[return vim.b.fn.get()]]))
207      exec_lua([[vim.api.nvim_buf_get_var(0, 'fn').add()]])
208      eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'fn').get()]]))
209      eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]]))
210
211      exec_lua(function()
212        local counter = 0
213        local function add_counter()
214          counter = counter + 1
215        end
216        local function get_counter()
217          return counter
218        end
219        vim.api.nvim_buf_set_var(0, 'AddCounter', add_counter)
220        vim.api.nvim_buf_set_var(0, 'GetCounter', get_counter)
221        vim.api.nvim_buf_set_var(0, 'fn', { add = add_counter, get = get_counter })
222        vim.api.nvim_buf_set_var(0, 'AddParens', function(s)
223          return '(' .. s .. ')'
224        end)
225      end)
226
227      eq(0, eval('b:GetCounter()'))
228      eval('b:AddCounter()')
229      eq(1, eval('b:GetCounter()'))
230      eval('b:AddCounter()')
231      eq(2, eval('b:GetCounter()'))
232      exec_lua([[vim.b.AddCounter()]])
233      eq(3, exec_lua([[return vim.b.GetCounter()]]))
234      exec_lua([[vim.api.nvim_buf_get_var(0, 'AddCounter')()]])
235      eq(4, exec_lua([[return vim.api.nvim_buf_get_var(0, 'GetCounter')()]]))
236      exec_lua([[vim.b.fn.add()]])
237      eq(5, exec_lua([[return vim.b.fn.get()]]))
238      exec_lua([[vim.api.nvim_buf_get_var(0, 'fn').add()]])
239      eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'fn').get()]]))
240      eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]]))
241
242      exec([[
243        function Test()
244        endfunction
245        function s:Test()
246        endfunction
247        let b:Unknown_func = function('Test')
248        let b:Unknown_script_func = function('s:Test')
249      ]])
250      eq(NIL, exec_lua([[return vim.b.Unknown_func]]))
251      eq(NIL, exec_lua([[return vim.b.Unknown_script_func]]))
252
253      exec_lua [[
254      vim.cmd "vnew"
255      ]]
256
257      eq(NIL, fn.luaeval 'vim.b.testing')
258      eq(NIL, fn.luaeval 'vim.b.other')
259      eq(NIL, fn.luaeval 'vim.b.nonexistent')
260    end)
261
262    it('vim.w', function()
263      exec_lua [[
264      vim.api.nvim_win_set_var(0, "testing", "hi")
265      vim.api.nvim_win_set_var(0, "other", 123)
266      vim.api.nvim_win_set_var(0, "to_delete", {hello="world"})
267      BUF = vim.api.nvim_create_buf(false, true)
268      WIN = vim.api.nvim_open_win(BUF, false, {
269        width=10, height=10,
270        relative='win', row=0, col=0
271      })
272      vim.api.nvim_win_set_var(WIN, "testing", "bye")
273      ]]
274
275      eq('hi', fn.luaeval 'vim.w.testing')
276      eq('bye', fn.luaeval 'vim.w[WIN].testing')
277      eq(123, fn.luaeval 'vim.w.other')
278      eq(NIL, fn.luaeval 'vim.w.nonexistent')
279      eq(NIL, fn.luaeval 'vim.w[WIN].nonexistent')
280
281      matches(
282        [[attempt to index .* nil value]],
283        pcall_err(exec_lua, 'return vim.w[WIN][0].testing')
284      )
285
286      eq({ hello = 'world' }, fn.luaeval 'vim.w.to_delete')
287      exec_lua [[
288      vim.w.to_delete = nil
289      ]]
290      eq(NIL, fn.luaeval 'vim.w.to_delete')
291
292      exec_lua [[
293        local counter = 0
294        local function add_counter() counter = counter + 1 end
295        local function get_counter() return counter end
296        vim.w.AddCounter = add_counter
297        vim.w.GetCounter = get_counter
298        vim.w.fn = {add = add_counter, get = get_counter}
299        vim.w.AddParens = function(s) return '(' .. s .. ')' end
300      ]]
301
302      eq(0, eval('w:GetCounter()'))
303      eval('w:AddCounter()')
304      eq(1, eval('w:GetCounter()'))
305      eval('w:AddCounter()')
306      eq(2, eval('w:GetCounter()'))
307      exec_lua([[vim.w.AddCounter()]])
308      eq(3, exec_lua([[return vim.w.GetCounter()]]))
309      exec_lua([[vim.api.nvim_win_get_var(0, 'AddCounter')()]])
310      eq(4, exec_lua([[return vim.api.nvim_win_get_var(0, 'GetCounter')()]]))
311      exec_lua([[vim.w.fn.add()]])
312      eq(5, exec_lua([[return vim.w.fn.get()]]))
313      exec_lua([[vim.api.nvim_win_get_var(0, 'fn').add()]])
314      eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'fn').get()]]))
315      eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]]))
316
317      exec_lua [[
318        local counter = 0
319        local function add_counter() counter = counter + 1 end
320        local function get_counter() return counter end
321        vim.api.nvim_win_set_var(0, 'AddCounter', add_counter)
322        vim.api.nvim_win_set_var(0, 'GetCounter', get_counter)
323        vim.api.nvim_win_set_var(0, 'fn', {add = add_counter, get = get_counter})
324        vim.api.nvim_win_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end)
325      ]]
326
327      eq(0, eval('w:GetCounter()'))
328      eval('w:AddCounter()')
329      eq(1, eval('w:GetCounter()'))
330      eval('w:AddCounter()')
331      eq(2, eval('w:GetCounter()'))
332      exec_lua([[vim.w.AddCounter()]])
333      eq(3, exec_lua([[return vim.w.GetCounter()]]))
334      exec_lua([[vim.api.nvim_win_get_var(0, 'AddCounter')()]])
335      eq(4, exec_lua([[return vim.api.nvim_win_get_var(0, 'GetCounter')()]]))
336      exec_lua([[vim.w.fn.add()]])
337      eq(5, exec_lua([[return vim.w.fn.get()]]))
338      exec_lua([[vim.api.nvim_win_get_var(0, 'fn').add()]])
339      eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'fn').get()]]))
340      eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]]))
341
342      exec([[
343        function Test()
344        endfunction
345        function s:Test()
346        endfunction
347        let w:Unknown_func = function('Test')
348        let w:Unknown_script_func = function('s:Test')
349      ]])
350      eq(NIL, exec_lua([[return vim.w.Unknown_func]]))
351      eq(NIL, exec_lua([[return vim.w.Unknown_script_func]]))
352
353      exec_lua [[
354      vim.cmd "vnew"
355      ]]
356
357      eq(NIL, fn.luaeval 'vim.w.testing')
358      eq(NIL, fn.luaeval 'vim.w.other')
359      eq(NIL, fn.luaeval 'vim.w.nonexistent')
360    end)
361
362    it('vim.t', function()
363      exec_lua [[
364      vim.api.nvim_tabpage_set_var(0, "testing", "hi")
365      vim.api.nvim_tabpage_set_var(0, "other", 123)
366      vim.api.nvim_tabpage_set_var(0, "to_delete", {hello="world"})
367      ]]
368
369      eq('hi', fn.luaeval 'vim.t.testing')
370      eq(123, fn.luaeval 'vim.t.other')
371      eq(NIL, fn.luaeval 'vim.t.nonexistent')
372      eq('hi', fn.luaeval 'vim.t[0].testing')
373      eq(123, fn.luaeval 'vim.t[0].other')
374      eq(NIL, fn.luaeval 'vim.t[0].nonexistent')
375
376      matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.t[0][0].testing'))
377
378      eq({ hello = 'world' }, fn.luaeval 'vim.t.to_delete')
379      exec_lua [[
380      vim.t.to_delete = nil
381      ]]
382      eq(NIL, fn.luaeval 'vim.t.to_delete')
383
384      exec_lua [[
385        local counter = 0
386        local function add_counter() counter = counter + 1 end
387        local function get_counter() return counter end
388        vim.t.AddCounter = add_counter
389        vim.t.GetCounter = get_counter
390        vim.t.fn = {add = add_counter, get = get_counter}
391        vim.t.AddParens = function(s) return '(' .. s .. ')' end
392      ]]
393
394      eq(0, eval('t:GetCounter()'))
395      eval('t:AddCounter()')
396      eq(1, eval('t:GetCounter()'))
397      eval('t:AddCounter()')
398      eq(2, eval('t:GetCounter()'))
399      exec_lua([[vim.t.AddCounter()]])
400      eq(3, exec_lua([[return vim.t.GetCounter()]]))
401      exec_lua([[vim.api.nvim_tabpage_get_var(0, 'AddCounter')()]])
402      eq(4, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'GetCounter')()]]))
403      exec_lua([[vim.t.fn.add()]])
404      eq(5, exec_lua([[return vim.t.fn.get()]]))
405      exec_lua([[vim.api.nvim_tabpage_get_var(0, 'fn').add()]])
406      eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'fn').get()]]))
407      eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]]))
408
409      exec_lua [[
410        local counter = 0
411        local function add_counter() counter = counter + 1 end
412        local function get_counter() return counter end
413        vim.api.nvim_tabpage_set_var(0, 'AddCounter', add_counter)
414        vim.api.nvim_tabpage_set_var(0, 'GetCounter', get_counter)
415        vim.api.nvim_tabpage_set_var(0, 'fn', {add = add_counter, get = get_counter})
416        vim.api.nvim_tabpage_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end)
417      ]]
418
419      eq(0, eval('t:GetCounter()'))
420      eval('t:AddCounter()')
421      eq(1, eval('t:GetCounter()'))
422      eval('t:AddCounter()')
423      eq(2, eval('t:GetCounter()'))
424      exec_lua([[vim.t.AddCounter()]])
425      eq(3, exec_lua([[return vim.t.GetCounter()]]))
426      exec_lua([[vim.api.nvim_tabpage_get_var(0, 'AddCounter')()]])
427      eq(4, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'GetCounter')()]]))
428      exec_lua([[vim.t.fn.add()]])
429      eq(5, exec_lua([[return vim.t.fn.get()]]))
430      exec_lua([[vim.api.nvim_tabpage_get_var(0, 'fn').add()]])
431      eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'fn').get()]]))
432      eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]]))
433
434      exec_lua [[
435      vim.cmd "tabnew"
436      ]]
437
438      eq(NIL, fn.luaeval 'vim.t.testing')
439      eq(NIL, fn.luaeval 'vim.t.other')
440      eq(NIL, fn.luaeval 'vim.t.nonexistent')
441    end)
442
443    it('vim.env', function()
444      exec_lua([[vim.fn.setenv('A', 123)]])
445      eq('123', fn.luaeval('vim.env.A'))
446      exec_lua([[vim.env.A = 456]])
447      eq('456', fn.luaeval('vim.env.A'))
448      exec_lua([[vim.env.A = nil]])
449      eq(NIL, fn.luaeval('vim.env.A'))
450
451      eq(true, fn.luaeval('vim.env.B == nil'))
452
453      command([[let $HOME = 'foo']])
454      eq('foo', fn.expand('~'))
455      eq('foo', fn.luaeval('vim.env.HOME'))
456      exec_lua([[vim.env.HOME = nil]])
457      eq('foo', fn.expand('~'))
458      exec_lua([[vim.env.HOME = 'bar']])
459      eq('bar', fn.expand('~'))
460      eq('bar', fn.luaeval('vim.env.HOME'))
461    end)
462
463    it('vim.v', function()
464      eq(fn.luaeval "vim.api.nvim_get_vvar('progpath')", fn.luaeval 'vim.v.progpath')
465      eq(false, fn.luaeval "vim.v['false']")
466      eq(NIL, fn.luaeval 'vim.v.null')
467      matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath'))
468      matches('Key is read%-only: count$', pcall_err(exec_lua, [[vim.v.count = 42]]))
469      matches('Dict is locked$', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]]))
470      matches('Key is fixed: errmsg$', pcall_err(exec_lua, [[vim.v.errmsg = nil]]))
471      exec_lua([[vim.v.errmsg = 'set by Lua']])
472      eq('set by Lua', eval('v:errmsg'))
473      exec_lua([[vim.v.errmsg = 42]])
474      eq('42', eval('v:errmsg'))
475      exec_lua([[vim.v.oldfiles = { 'one', 'two' }]])
476      eq({ 'one', 'two' }, eval('v:oldfiles'))
477      exec_lua([[vim.v.oldfiles = {}]])
478      eq({}, eval('v:oldfiles'))
479      matches(
480        'Setting v:oldfiles to value with wrong type$',
481        pcall_err(exec_lua, [[vim.v.oldfiles = 'a']])
482      )
483      eq({}, eval('v:oldfiles'))
484
485      feed('i foo foo foo<Esc>0/foo<CR>')
486      eq({ 1, 1 }, api.nvim_win_get_cursor(0))
487      eq(1, eval('v:searchforward'))
488      feed('n')
489      eq({ 1, 5 }, api.nvim_win_get_cursor(0))
490      exec_lua([[vim.v.searchforward = 0]])
491      eq(0, eval('v:searchforward'))
492      feed('n')
493      eq({ 1, 1 }, api.nvim_win_get_cursor(0))
494      exec_lua([[vim.v.searchforward = 1]])
495      eq(1, eval('v:searchforward'))
496      feed('n')
497      eq({ 1, 5 }, api.nvim_win_get_cursor(0))
498
499      local screen = Screen.new(60, 3)
500      eq(1, eval('v:hlsearch'))
501      screen:expect {
502        grid = [[
503         {10:foo} {10:^foo} {10:foo}                                                |
504        {1:~                                                           }|
505                                                                    |
506      ]],
507      }
508      exec_lua([[vim.v.hlsearch = 0]])
509      eq(0, eval('v:hlsearch'))
510      screen:expect {
511        grid = [[
512         foo ^foo foo                                                |
513        {1:~                                                           }|
514                                                                    |
515      ]],
516      }
517      exec_lua([[vim.v.hlsearch = 1]])
518      eq(1, eval('v:hlsearch'))
519      screen:expect {
520        grid = [[
521         {10:foo} {10:^foo} {10:foo}                                                |
522        {1:~                                                           }|
523                                                                    |
524      ]],
525      }
526    end)
527  end)
528
529  describe('options', function()
530    describe('vim.o', function()
531      it('works for boolean values', function()
532        eq_exec_lua(false, function()
533          vim.o.number = false
534          return vim.o.number
535        end)
536      end)
537
538      it('works for number values', function()
539        eq_exec_lua(10, function()
540          vim.o.tabstop = 10
541          return vim.o.tabstop
542        end)
543      end)
544
545      it('works for string values', function()
546        eq_exec_lua('hello world', function()
547          vim.o.makeprg = 'hello world'
548          return vim.o.makeprg
549        end)
550      end)
551
552      it('works for array type options', function()
553        eq_exec_lua('hello,world', function()
554          vim.o.wildignore = { 'hello', 'world' }
555          return vim.o.wildignore
556        end)
557      end)
558
559      it('works for key:value type options using string', function()
560        eq_exec_lua('eol:~,space:-', function()
561          vim.o.listchars = 'eol:~,space:-'
562          return vim.o.listchars
563        end)
564      end)
565
566      it('works for key:value type options using list of strings', function()
567        eq_exec_lua('eol:~,space:-', function()
568          vim.o.listchars = { 'eol:~', 'space:-' }
569          return vim.o.listchars
570        end)
571      end)
572
573      it('works for key:value type options using table', function()
574        eq_exec_lua('eol:~,space:.', function()
575          vim.o.listchars = { eol = '~', space = '.' }
576          return vim.o.listchars
577        end)
578      end)
579
580      it('works for set type flaglists', function()
581        eq_exec_lua('tcro', function()
582          vim.o.formatoptions = 'tcro'
583          return vim.o.formatoptions
584        end)
585      end)
586
587      it('works for set type flaglists using tables', function()
588        eq_exec_lua({ t = true, c = true, r = true, o = true }, function()
589          vim.o.formatoptions = { t = true, c = true, r = true, o = true }
590          -- use vim.opt to convert to lua value
591          return vim.opt.formatoptions:get()
592        end)
593      end)
594
595      it('works for weird number options', function()
596        eq_exec_lua(9, function()
597          vim.o.wildchar = '<Tab>'
598          return vim.o.wildchar
599        end)
600      end)
601
602      it('expands env vars', function()
603        eq_exec_lua('/dev/null', function()
604          vim.fn.setenv('INCLUDE', '/dev/null')
605          vim.o.path = '$INCLUDE'
606          return vim.o.path
607        end)
608      end)
609
610      it('expands ~', function()
611        eq_exec_lua('/dev/null', function()
612          vim.fn.setenv('HOME', '/dev/null')
613          vim.o.rtp = '~'
614          return vim.o.rtp
615        end)
616      end)
617    end)
618
619    describe('vim.bo', function()
620      it('can get and set options', function()
621        eq('', fn.luaeval 'vim.bo.filetype')
622        exec_lua(function()
623          _G.BUF = vim.api.nvim_create_buf(false, true)
624          vim.api.nvim_set_option_value('filetype', 'markdown', {})
625          vim.api.nvim_set_option_value('modifiable', false, { buf = _G.BUF })
626        end)
627        eq(false, fn.luaeval 'vim.bo.modified')
628        eq('markdown', fn.luaeval 'vim.bo.filetype')
629        eq(false, fn.luaeval 'vim.bo[BUF].modifiable')
630        exec_lua(function()
631          vim.bo.filetype = ''
632          vim.bo[_G.BUF].modifiable = true
633        end)
634        eq('', fn.luaeval 'vim.bo.filetype')
635        eq(true, fn.luaeval 'vim.bo[BUF].modifiable')
636      end)
637
638      it('errors', function()
639        matches("Unknown option 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt'))
640        matches('Expected Lua string$', pcall_err(exec_lua, 'return vim.bo[0][0].autoread'))
641        matches('Invalid buffer id: %-1$', pcall_err(exec_lua, 'return vim.bo[-1].filetype'))
642      end)
643    end)
644
645    describe('vim.wo', function()
646      it('can get and set options', function()
647        exec_lua(function()
648          vim.api.nvim_set_option_value('cole', 2, {})
649          vim.cmd 'split'
650          vim.api.nvim_set_option_value('cole', 2, {})
651        end)
652        eq(2, fn.luaeval 'vim.wo.cole')
653        exec_lua(function()
654          vim.wo.conceallevel = 0
655        end)
656        eq(0, fn.luaeval 'vim.wo.cole')
657        eq(0, fn.luaeval 'vim.wo[0].cole')
658        eq(0, fn.luaeval 'vim.wo[1001].cole')
659        matches("Unknown option 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt'))
660        matches('Invalid window id: %-1$', pcall_err(exec_lua, 'return vim.wo[-1].list'))
661        eq(2, fn.luaeval 'vim.wo[1000].cole')
662        exec_lua(function()
663          vim.wo[1000].cole = 0
664        end)
665        eq(0, fn.luaeval 'vim.wo[1000].cole')
666
667        -- Can handle global-local values
668        exec_lua [[vim.o.scrolloff = 100]]
669        exec_lua [[vim.wo.scrolloff = 200]]
670        eq(200, fn.luaeval 'vim.wo.scrolloff')
671        exec_lua [[vim.wo.scrolloff = -1]]
672        eq(100, fn.luaeval 'vim.wo.scrolloff')
673        exec_lua(function()
674          vim.wo[0][0].scrolloff = 200
675          vim.cmd 'enew'
676        end)
677        eq(100, fn.luaeval 'vim.wo.scrolloff')
678      end)
679
680      it('errors', function()
681        matches('only bufnr=0 is supported', pcall_err(exec_lua, 'vim.wo[0][10].signcolumn = "no"'))
682        matches(
683          'only bufnr=0 is supported',
684          pcall_err(exec_lua, 'local a = vim.wo[0][10].signcolumn')
685        )
686      end)
687    end)
688
689    describe('vim.opt', function()
690      -- TODO: We still need to write some tests for optlocal, opt and then getting the options
691      --  Probably could also do some stuff with getting things from viml side as well to confirm behavior is the same.
692
693      it('allows setting number values', function()
694        local scrolloff = exec_lua [[
695          vim.opt.scrolloff = 10
696          return vim.o.scrolloff
697        ]]
698        eq(10, scrolloff)
699      end)
700
701      pending('handles STUPID window things', function()
702        eq_exec_lua({}, function()
703          return {
704            vim.api.nvim_get_option_value('scrolloff', { scope = 'global' }),
705            vim.api.nvim_get_option_value('scrolloff', { win = 0 }),
706          }
707        end)
708      end)
709
710      it('allows setting tables', function()
711        eq_exec_lua('hello,world', function()
712          vim.opt.wildignore = { 'hello', 'world' }
713          return vim.o.wildignore
714        end)
715      end)
716
717      it('allows setting tables with shortnames', function()
718        eq_exec_lua('hello,world', function()
719          vim.opt.wig = { 'hello', 'world' }
720          return vim.o.wildignore
721        end)
722      end)
723
724      it('errors when you attempt to set string values to numeric options', function()
725        eq_exec_lua(false, function()
726          return ({
727            pcall(function()
728              vim.opt.textwidth = 'hello world'
729            end),
730          })[1]
731        end)
732      end)
733
734      it('errors when you attempt to setlocal a global value', function()
735        eq_exec_lua(false, function()
736          return pcall(function()
737            vim.opt_local.clipboard = 'hello'
738          end)
739        end)
740      end)
741
742      it('allows you to set boolean values', function()
743        eq_exec_lua({ true, false, true }, function()
744          local results = {}
745
746          vim.opt.autoindent = true
747          table.insert(results, vim.bo.autoindent)
748
749          vim.opt.autoindent = false
750          table.insert(results, vim.bo.autoindent)
751
752          vim.opt.autoindent = not vim.opt.autoindent:get()
753          table.insert(results, vim.bo.autoindent)
754
755          return results
756        end)
757      end)
758
759      it('changes current buffer values and defaults for global local values', function()
760        local result = exec_lua(function()
761          local result = {}
762
763          vim.opt.makeprg = 'global-local'
764          table.insert(result, vim.go.makeprg)
765          table.insert(result, vim.api.nvim_get_option_value('makeprg', { buf = 0 }))
766
767          vim.opt_local.mp = 'only-local'
768          table.insert(result, vim.go.makeprg)
769          table.insert(result, vim.api.nvim_get_option_value('makeprg', { buf = 0 }))
770
771          vim.opt_global.makeprg = 'only-global'
772          table.insert(result, vim.go.makeprg)
773          table.insert(result, vim.api.nvim_get_option_value('makeprg', { buf = 0 }))
774
775          vim.opt.makeprg = 'global-local'
776          table.insert(result, vim.go.makeprg)
777          table.insert(result, vim.api.nvim_get_option_value('makeprg', { buf = 0 }))
778          return result
779        end)
780
781        -- Set -> global & local
782        eq('global-local', result[1])
783        eq('', result[2])
784
785        -- Setlocal -> only local
786        eq('global-local', result[3])
787        eq('only-local', result[4])
788
789        -- Setglobal -> only global
790        eq('only-global', result[5])
791        eq('only-local', result[6])
792
793        -- Set -> sets global value and resets local value
794        eq('global-local', result[7])
795        eq('', result[8])
796      end)
797
798      it('allows you to retrieve window opts even if they have not been set', function()
799        eq_exec_lua({ false, false, true, true }, function()
800          local result = {}
801          table.insert(result, vim.opt.number:get())
802          table.insert(result, vim.opt_local.number:get())
803
804          vim.opt_local.number = true
805          table.insert(result, vim.opt.number:get())
806          table.insert(result, vim.opt_local.number:get())
807
808          return result
809        end)
810      end)
811
812      it('allows all sorts of string manipulation', function()
813        eq_exec_lua({ 'hello', 'hello world', 'start hello world' }, function()
814          local results = {}
815
816          vim.opt.makeprg = 'hello'
817          table.insert(results, vim.o.makeprg)
818
819          vim.opt.makeprg = vim.opt.makeprg + ' world'
820          table.insert(results, vim.o.makeprg)
821
822          vim.opt.makeprg = vim.opt.makeprg ^ 'start '
823          table.insert(results, vim.o.makeprg)
824
825          return results
826        end)
827      end)
828
829      describe('option:get()', function()
830        it('works for boolean values', function()
831          eq_exec_lua(false, function()
832            vim.opt.number = false
833            return vim.opt.number:get()
834          end)
835        end)
836
837        it('works for number values', function()
838          eq_exec_lua(10, function()
839            vim.opt.tabstop = 10
840            return vim.opt.tabstop:get()
841          end)
842        end)
843
844        it('works for string values', function()
845          eq_exec_lua('hello world', function()
846            vim.opt.makeprg = 'hello world'
847            return vim.opt.makeprg:get()
848          end)
849        end)
850
851        it('works for set type flaglists', function()
852          local formatoptions = exec_lua(function()
853            vim.opt.formatoptions = 'tcro'
854            return vim.opt.formatoptions:get()
855          end)
856
857          eq(true, formatoptions.t)
858          eq(true, not formatoptions.q)
859        end)
860
861        it('works for set type flaglists', function()
862          local formatoptions = exec_lua(function()
863            vim.opt.formatoptions = { t = true, c = true, r = true, o = true }
864            return vim.opt.formatoptions:get()
865          end)
866
867          eq(true, formatoptions.t)
868          eq(true, not formatoptions.q)
869        end)
870
871        it('works for comma list type options', function()
872          local wildignore = exec_lua(function()
873            vim.opt.wildignore = '*.c,*.o,__pycache__'
874            return vim.opt.wildignore:get()
875          end)
876
877          eq(3, #wildignore)
878          eq('*.c', wildignore[1])
879        end)
880
881        it('works for array list type options', function()
882          eq_exec_lua({ eol = '~', space = '-' }, function()
883            vim.opt.listchars = { 'eol:~', 'space:-' }
884            return vim.opt.listchars:get()
885          end)
886        end)
887
888        it('works for options that are both commalist and flaglist', function()
889          eq_exec_lua({ b = true, s = true }, function()
890            vim.opt.whichwrap = 'b,s'
891            return vim.opt.whichwrap:get()
892          end)
893
894          eq_exec_lua({ b = true, h = true }, function()
895            vim.opt.whichwrap = { b = true, s = false, h = true }
896            return vim.opt.whichwrap:get()
897          end)
898        end)
899
900        it("returns structured values for a dict option ('diffopt')", function()
901          -- Bare flags -> true; sub-values stay strings (option sub-value types are not exposed).
902          eq_exec_lua({ internal = true, filler = true, context = '4' }, function()
903            vim.opt.diffopt = 'internal,filler,context:4'
904            return vim.opt.diffopt:get()
905          end)
906        end)
907
908        it('roundtrips a dict option through :set', function()
909          eq_exec_lua('context:4,filler,internal', function()
910            vim.opt.diffopt = 'internal,filler,context:4'
911            vim.opt.diffopt = vim.opt.diffopt:get()
912            return vim.go.diffopt
913          end)
914        end)
915
916        -- Dict option accepts a table and :get() returns a map. #18875
917        it("roundtrips a window-local dict option ('breakindentopt')", function()
918          eq_exec_lua({ sbr = true, shift = '3' }, function()
919            vim.opt.breakindentopt = { sbr = true, shift = 3 }
920            return vim.opt.breakindentopt:get()
921          end)
922        end)
923
924        it("roundtrips a table for 'mousescroll'", function()
925          eq_exec_lua({ hor = '6', ver = '3' }, function()
926            vim.opt.mousescroll = { hor = 6, ver = 3 }
927            return vim.opt.mousescroll:get()
928          end)
929        end)
930
931        it('works for key-value pair options', function()
932          eq_exec_lua({ tab = '> ', space = '_' }, function()
933            vim.opt.listchars = 'tab:> ,space:_'
934            return vim.opt.listchars:get()
935          end)
936        end)
937
938        it('allows you to add numeric options', function()
939          eq_exec_lua(16, function()
940            vim.opt.tabstop = 12
941            vim.opt.tabstop = vim.opt.tabstop + 4
942            return vim.bo.tabstop
943          end)
944        end)
945
946        it('allows you to subtract numeric options', function()
947          eq_exec_lua(2, function()
948            vim.opt.tabstop = 4
949            vim.opt.tabstop = vim.opt.tabstop - 2
950            return vim.bo.tabstop
951          end)
952        end)
953      end)
954
955      describe('key:value style options', function()
956        it('handles dict style', function()
957          eq_exec_lua('eol:~,space:.', function()
958            vim.opt.listchars = { eol = '~', space = '.' }
959            return vim.o.listchars
960          end)
961        end)
962
963        it('allows adding dict style', function()
964          eq_exec_lua('eol:~,space:-', function()
965            vim.opt.listchars = { eol = '~', space = '.' }
966            vim.opt.listchars = vim.opt.listchars + { space = '-' }
967            return vim.o.listchars
968          end)
969        end)
970
971        it('does not allow adding dict style multiple times', function()
972          matches(
973            'Multiple vim.opt infix operations unsupported',
974            pcall_err(
975              exec_lua,
976              [[
977              vim.opt.listchars = { eol = '~', space = '.' }
978              vim.opt.listchars = vim.opt.listchars + { space = '-' } + { space = '_' }
979            ]]
980            )
981          )
982        end)
983
984        it('allows completely new keys', function()
985          eq_exec_lua('eol:~,space:.,tab:>>>', function()
986            vim.opt.listchars = { eol = '~', space = '.' }
987            vim.opt.listchars = vim.opt.listchars + { tab = '>>>' }
988            return vim.o.listchars
989          end)
990        end)
991
992        it('allows subtracting dict style', function()
993          eq_exec_lua('eol:~', function()
994            vim.opt.listchars = { eol = '~', space = '.' }
995            vim.opt.listchars = vim.opt.listchars - 'space'
996            return vim.o.listchars
997          end)
998        end)
999
1000        it('does not allow subtracting dict style multiple times', function()
1001          matches(
1002            'Multiple vim.opt infix operations unsupported',
1003            pcall_err(
1004              exec_lua,
1005              [[
1006              vim.opt.listchars = { eol = '~', space = '.' }
1007              vim.opt.listchars = vim.opt.listchars - 'space' - 'eol'
1008            ]]
1009            )
1010          )
1011        end)
1012
1013        it('does not allow subtracting dict style multiple times with the same key', function()
1014          matches(
1015            'Multiple vim.opt infix operations unsupported',
1016            pcall_err(
1017              exec_lua,
1018              [[
1019              vim.opt.listchars = { eol = '~', space = '.' }
1020              vim.opt.listchars = vim.opt.listchars - 'space' - 'space'
1021            ]]
1022            )
1023          )
1024        end)
1025
1026        it('allows adding a key:value string to a listchars', function()
1027          eq_exec_lua('eol:~,space:.,tab:>~', function()
1028            vim.opt.listchars = { eol = '~', space = '.' }
1029            vim.opt.listchars = vim.opt.listchars + 'tab:>~'
1030            return vim.o.listchars
1031          end)
1032        end)
1033
1034        it('allows prepending a key:value string to a listchars', function()
1035          eq_exec_lua('eol:~,space:.,tab:>~', function()
1036            vim.opt.listchars = { eol = '~', space = '.' }
1037            -- Operator overloading is cursed.
1038            vim.opt.listchars = vim.opt.listchars ^ 'tab:>~'
1039            return vim.o.listchars
1040          end)
1041        end)
1042      end)
1043
1044      it('automatically sets when calling remove', function()
1045        eq_exec_lua('foo,baz', function()
1046          vim.opt.wildignore = 'foo,bar,baz'
1047          vim.opt.wildignore:remove('bar')
1048          return vim.o.wildignore
1049        end)
1050      end)
1051
1052      it('automatically sets when calling remove with a table', function()
1053        eq_exec_lua('foo', function()
1054          vim.opt.wildignore = 'foo,bar,baz'
1055          vim.opt.wildignore:remove { 'bar', 'baz' }
1056          return vim.o.wildignore
1057        end)
1058      end)
1059
1060      it('removes flags from a set when calling remove with a table: #41953', function()
1061        eq_exec_lua({ j = true, q = true, l = true }, function()
1062          vim.opt.formatoptions = 'jcroql'
1063          vim.opt.formatoptions:remove { 'c', 'r', 'o' }
1064          return vim.opt.formatoptions:get()
1065        end)
1066      end)
1067
1068      it('automatically sets when calling append', function()
1069        eq_exec_lua('foo,bar,baz,bing', function()
1070          vim.opt.wildignore = 'foo,bar,baz'
1071          vim.opt.wildignore:append('bing')
1072          return vim.o.wildignore
1073        end)
1074      end)
1075
1076      it('automatically sets when calling append with a table', function()
1077        eq_exec_lua('foo,bar,baz,bing,zap', function()
1078          vim.opt.wildignore = 'foo,bar,baz'
1079          vim.opt.wildignore:append { 'bing', 'zap' }
1080          return vim.o.wildignore
1081        end)
1082      end)
1083
1084      it('allows adding tables', function()
1085        eq_exec_lua('foo', function()
1086          vim.opt.wildignore = 'foo'
1087          return vim.o.wildignore
1088        end)
1089
1090        eq_exec_lua('foo,bar,baz', function()
1091          vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
1092          return vim.o.wildignore
1093        end)
1094      end)
1095
1096      it('handles adding duplicates', function()
1097        eq_exec_lua('foo', function()
1098          vim.opt.wildignore = 'foo'
1099          return vim.o.wildignore
1100        end)
1101
1102        eq_exec_lua('foo,bar,baz', function()
1103          vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
1104          return vim.o.wildignore
1105        end)
1106
1107        eq_exec_lua('foo,bar,baz', function()
1108          vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
1109          return vim.o.wildignore
1110        end)
1111      end)
1112
1113      it('does not allow adding multiple times', function()
1114        matches(
1115          'Multiple vim.opt infix operations unsupported',
1116          pcall_err(
1117            exec_lua,
1118            [[
1119            vim.opt.wildignore = 'foo'
1120            vim.opt.wildignore = vim.opt.wildignore + 'bar' + 'baz'
1121          ]]
1122          )
1123        )
1124      end)
1125
1126      it('removes values when you use minus', function()
1127        eq_exec_lua('foo', function()
1128          vim.opt.wildignore = 'foo'
1129          return vim.o.wildignore
1130        end)
1131
1132        eq_exec_lua('foo,bar,baz', function()
1133          vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' }
1134          return vim.o.wildignore
1135        end)
1136
1137        eq_exec_lua('foo,baz', function()
1138          vim.opt.wildignore = vim.opt.wildignore - 'bar'
1139          return vim.o.wildignore
1140        end)
1141      end)
1142
1143      it('prepends values when using ^', function()
1144        eq_exec_lua('first,foo', function()
1145          vim.opt.wildignore = 'foo'
1146          vim.opt.wildignore = vim.opt.wildignore ^ 'first'
1147          return vim.o.wildignore
1148        end)
1149
1150        eq_exec_lua('super_first,first,foo', function()
1151          vim.opt.wildignore = vim.opt.wildignore ^ 'super_first'
1152          return vim.o.wildignore
1153        end)
1154      end)
1155
1156      it('does not remove duplicates from wildmode: #14708', function()
1157        eq_exec_lua('full,list,full', function()
1158          vim.opt.wildmode = { 'full', 'list', 'full' }
1159          return vim.o.wildmode
1160        end)
1161      end)
1162
1163      describe('option types', function()
1164        it('allows to set option with numeric value', function()
1165          eq_exec_lua(4, function()
1166            vim.opt.tabstop = 4
1167            return vim.bo.tabstop
1168          end)
1169
1170          matches(
1171            "Invalid 'tabstop': expected a valid type, got String",
1172            pcall_err(exec_lua, [[vim.opt.tabstop = '4']])
1173          )
1174          matches(
1175            "Invalid 'tabstop': expected a valid type, got Boolean",
1176            pcall_err(exec_lua, [[vim.opt.tabstop = true]])
1177          )
1178          matches(
1179            "Invalid 'tabstop': expected a valid type, got Array",
1180            pcall_err(exec_lua, [[vim.opt.tabstop = {4, 2}]])
1181          )
1182          matches(
1183            "Invalid 'tabstop': expected a valid type, got Function",
1184            pcall_err(exec_lua, [[vim.opt.tabstop = function() return 4 end]])
1185          )
1186        end)
1187
1188        it('allows to set option with boolean value', function()
1189          eq_exec_lua(true, function()
1190            vim.opt.undofile = true
1191            return vim.bo.undofile
1192          end)
1193
1194          matches(
1195            "Invalid 'undofile': expected a valid type, got Integer",
1196            pcall_err(exec_lua, [[vim.opt.undofile = 0]])
1197          )
1198          matches(
1199            "Invalid 'undofile': expected a valid type, got Array",
1200            pcall_err(exec_lua, [[vim.opt.undofile = {true}]])
1201          )
1202          matches(
1203            "Invalid 'undofile': expected a valid type, got String",
1204            pcall_err(exec_lua, [[vim.opt.undofile = 'true']])
1205          )
1206          matches(
1207            "Invalid 'undofile': expected a valid type, got Function",
1208            pcall_err(exec_lua, [[vim.opt.undofile = function() return true end]])
1209          )
1210        end)
1211
1212        it('allows to set option with array or string value', function()
1213          eq_exec_lua('indent,eol,start', function()
1214            vim.opt.backspace = { 'indent', 'eol', 'start' }
1215            return vim.go.backspace
1216          end)
1217
1218          eq_exec_lua('indent,eol,start', function()
1219            vim.opt.backspace = 'indent,eol,start'
1220            return vim.go.backspace
1221          end)
1222
1223          matches(
1224            "Invalid 'backspace': expected a valid type, got Boolean",
1225            pcall_err(exec_lua, [[vim.opt.backspace = true]])
1226          )
1227          matches(
1228            "Invalid 'backspace': expected a valid type, got Integer",
1229            pcall_err(exec_lua, [[vim.opt.backspace = 2]])
1230          )
1231          matches(
1232            "Invalid 'backspace': expected a valid type, got Function",
1233            pcall_err(exec_lua, [[vim.opt.backspace = function() return 'indent,eol,start' end]])
1234          )
1235        end)
1236
1237        it('allows set option with map or string value', function()
1238          eq_exec_lua('eol:~,space:.', function()
1239            vim.opt.listchars = { eol = '~', space = '.' }
1240            return vim.o.listchars
1241          end)
1242
1243          eq_exec_lua('eol:~,space:.,tab:>~', function()
1244            vim.opt.listchars = 'eol:~,space:.,tab:>~'
1245            return vim.o.listchars
1246          end)
1247
1248          matches(
1249            "Invalid 'listchars': expected a valid type, got Boolean",
1250            pcall_err(exec_lua, [[vim.opt.listchars = true]])
1251          )
1252          matches(
1253            "Invalid 'listchars': expected a valid type, got Integer",
1254            pcall_err(exec_lua, [[vim.opt.listchars = 2]])
1255          )
1256          matches(
1257            "Invalid 'listchars': expected a valid type, got Function",
1258            pcall_err(
1259              exec_lua,
1260              [[vim.opt.listchars = function() return "eol:~,space:.,tab:>~" end]]
1261            )
1262          )
1263        end)
1264
1265        it('allows set option with set or string value', function()
1266          eq_exec_lua('b,s', function()
1267            vim.opt.whichwrap = { b = true, s = 1 }
1268            return vim.go.whichwrap
1269          end)
1270
1271          eq_exec_lua('b,s,<,>,[,]', function()
1272            vim.opt.whichwrap = 'b,s,<,>,[,]'
1273            return vim.go.whichwrap
1274          end)
1275
1276          matches(
1277            "Invalid 'whichwrap': expected a valid type, got Boolean",
1278            pcall_err(exec_lua, [[vim.opt.whichwrap = true]])
1279          )
1280          matches(
1281            "Invalid 'whichwrap': expected a valid type, got Integer",
1282            pcall_err(exec_lua, [[vim.opt.whichwrap = 2]])
1283          )
1284          matches(
1285            "Invalid 'whichwrap': expected a valid type, got Function",
1286            pcall_err(exec_lua, [[vim.opt.whichwrap = function() return "b,s,<,>,[,]" end]])
1287          )
1288        end)
1289      end)
1290
1291      -- The raw string keeps the ",," literal-comma convention; the structured view splits on every
1292      -- comma and does not reconstruct literal commas.
1293      it('can handle isfname ,,,', function()
1294        eq_exec_lua({ { 'a', 'b', 'c' }, 'a,b,,,c' }, function()
1295          vim.opt.isfname = 'a,b,,,c'
1296          return { vim.opt.isfname:get(), vim.go.isfname }
1297        end)
1298      end)
1299
1300      it('can handle isfname ,^,,', function()
1301        eq_exec_lua({ { 'a', 'b', '^', 'c' }, 'a,b,^,,c' }, function()
1302          vim.opt.isfname = 'a,b,^,,c'
1303          return { vim.opt.isfname:get(), vim.go.isfname }
1304        end)
1305      end)
1306
1307      describe('https://github.com/neovim/neovim/issues/14828', function()
1308        it('gives empty list when item is empty:array', function()
1309          eq_exec_lua({}, function()
1310            vim.cmd('set wildignore=')
1311            return vim.opt.wildignore:get()
1312          end)
1313
1314          eq_exec_lua({}, function()
1315            vim.opt.wildignore = {}
1316            return vim.opt.wildignore:get()
1317          end)
1318        end)
1319
1320        it('gives empty list when item is empty:set', function()
1321          eq_exec_lua({}, function()
1322            vim.cmd('set formatoptions=')
1323            return vim.opt.formatoptions:get()
1324          end)
1325
1326          eq_exec_lua({}, function()
1327            vim.opt.formatoptions = {}
1328            return vim.opt.formatoptions:get()
1329          end)
1330        end)
1331
1332        it('does not append to empty item', function()
1333          eq_exec_lua({ '*.foo', '*.bar' }, function()
1334            vim.opt.wildignore = {}
1335            vim.opt.wildignore:append { '*.foo', '*.bar' }
1336            return vim.opt.wildignore:get()
1337          end)
1338        end)
1339
1340        it('does not prepend to empty item', function()
1341          eq_exec_lua({ '*.foo', '*.bar' }, function()
1342            vim.opt.wildignore = {}
1343            vim.opt.wildignore:prepend { '*.foo', '*.bar' }
1344            return vim.opt.wildignore:get()
1345          end)
1346        end)
1347
1348        it('append to empty set', function()
1349          eq_exec_lua({ t = true }, function()
1350            vim.opt.formatoptions = {}
1351            vim.opt.formatoptions:append('t')
1352            return vim.opt.formatoptions:get()
1353          end)
1354        end)
1355
1356        it('prepend to empty set', function()
1357          eq_exec_lua({ t = true }, function()
1358            vim.opt.formatoptions = {}
1359            vim.opt.formatoptions:prepend('t')
1360            return vim.opt.formatoptions:get()
1361          end)
1362        end)
1363      end)
1364
1365      it('expands env vars', function()
1366        eq_exec_lua({ '/dev/null' }, function()
1367          vim.env.INCLUDE = '/dev/null'
1368          vim.opt.path = '$INCLUDE'
1369          return vim.opt.path:get()
1370        end)
1371      end)
1372
1373      it('expands ~', function()
1374        eq_exec_lua({ '/dev/null' }, function()
1375          vim.env.HOME = '/dev/null'
1376          vim.opt.rtp = '~'
1377          return vim.opt.rtp:get()
1378        end)
1379      end)
1380    end) -- vim.opt
1381
1382    describe('vim.opt_local', function()
1383      it('appends into global value when changing local option value', function()
1384        eq_exec_lua('foo,bar,baz,qux', function()
1385          vim.opt.tags = 'foo,bar'
1386          vim.opt_local.tags:append('baz')
1387          vim.opt_local.tags:append('qux')
1388          return vim.bo.tags
1389        end)
1390      end)
1391
1392      it('removes a table of flags from a flag-list option: #41953', function()
1393        eq_exec_lua('jql', function()
1394          vim.opt_local.formatoptions = 'jcroql'
1395          vim.opt_local.formatoptions:remove { 'c', 'r', 'o' }
1396          return vim.bo.formatoptions
1397        end)
1398      end)
1399    end)
1400
1401    describe('vim.opt_global', function()
1402      it('gets current global option value', function()
1403        eq_exec_lua({ 'yes' }, function()
1404          vim.cmd 'setglobal signcolumn=yes'
1405          return { vim.opt_global.signcolumn:get() }
1406        end)
1407      end)
1408    end)
1409  end)
1410end)