robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
20.3 KiB683 linesraw
1-- Test suite for testing luaeval() function
2local t = require('test.testutil')
3local n = require('test.functional.testnvim')()
4local Screen = require('test.functional.ui.screen')
5
6local describe, it, before_each = t.describe, t.it, t.before_each
7local pcall_err = t.pcall_err
8local remove_trace = t.remove_trace
9local exec_lua = n.exec_lua
10local command = n.command
11local api = n.api
12local fn = n.fn
13local clear = n.clear
14local eval = n.eval
15local feed = n.feed
16local assert_alive = n.assert_alive
17local NIL = vim.NIL
18local eq = t.eq
19local matches = t.matches
20
21before_each(clear)
22
23local function startswith(expected, actual)
24  eq(expected, actual:sub(1, #expected))
25end
26
27describe('luaeval()', function()
28  local nested_by_level = {}
29  local nested = {}
30  local nested_s = '{}'
31  for i = 1, 100 do
32    if i % 2 == 0 then
33      nested = { nested }
34      nested_s = '{' .. nested_s .. '}'
35    else
36      nested = { nested = nested }
37      nested_s = '{nested=' .. nested_s .. '}'
38    end
39    nested_by_level[i] = { o = nested, s = nested_s }
40  end
41
42  describe('second argument', function()
43    it('is successfully received', function()
44      local q = {
45        t = true,
46        f = false, --[[n=NIL,]]
47        d = { l = { 'string', 42, 0.42 } },
48      }
49      eq(q, fn.luaeval('_A', q))
50      -- Not tested: nil, funcrefs, returned object identity: behaviour will
51      -- most likely change.
52    end)
53  end)
54  describe('lua values', function()
55    it('are successfully transformed', function()
56      eq(
57        { n = 1, f = 1.5, s = 'string', l = { 4, 2 } },
58        fn.luaeval('{n=1, f=1.5, s="string", l={4, 2}}')
59      )
60      -- Not tested: nil inside containers: behaviour will most likely change.
61      eq(NIL, fn.luaeval('nil'))
62      eq({ [''] = 1 }, fn.luaeval('{[""]=1}'))
63    end)
64  end)
65  describe('recursive lua values', function()
66    it('are successfully transformed', function()
67      command('lua rawset(_G, "d", {})')
68      command('lua rawset(d, "d", d)')
69      eq("\n{'d': {...@0}}", fn.execute('echo luaeval("d")'))
70
71      command('lua rawset(_G, "l", {})')
72      command('lua table.insert(l, l)')
73      eq('\n[[...@0]]', fn.execute('echo luaeval("l")'))
74    end)
75  end)
76  describe('strings with NULs', function()
77    it('are successfully converted to blobs', function()
78      command([[let s = luaeval('"\0"')]])
79      eq('\000', api.nvim_get_var('s'))
80    end)
81    it('are successfully converted to special dictionaries in table keys', function()
82      command([[let d = luaeval('{["\0"]=1}')]])
83      eq({ _TYPE = {}, _VAL = { { '\000', 1 } } }, api.nvim_get_var('d'))
84      eq(1, fn.eval('d._TYPE is v:msgpack_types.map'))
85      eq(eval('v:t_blob'), fn.eval('type(d._VAL[0][0])'))
86    end)
87    it('are successfully converted to blobs from a list', function()
88      command([[let l = luaeval('{"abc", "a\0b", "c\0d", "def"}')]])
89      eq({ 'abc', 'a\000b', 'c\000d', 'def' }, api.nvim_get_var('l'))
90    end)
91  end)
92
93  -- Not checked: funcrefs converted to NIL. To be altered to something more
94  -- meaningful later.
95
96  it('scalars', function()
97    -- Also test method call (->) syntax
98    eq(1, fn.luaeval('1'))
99    eq(0, eval('"1"->luaeval()->type()'))
100
101    eq(1.5, fn.luaeval('1.5'))
102    eq(5, eval('"1.5"->luaeval()->type()'))
103
104    eq('test', fn.luaeval('"test"'))
105    eq(1, eval('"\'test\'"->luaeval()->type()'))
106
107    eq('', fn.luaeval('""'))
108    eq('\000', fn.luaeval([['\0']]))
109    eq('\000\n\000', fn.luaeval([['\0\n\0']]))
110    eq(10, eval([[type(luaeval("'\\0\\n\\0'"))]]))
111
112    eq(true, fn.luaeval('true'))
113    eq(false, fn.luaeval('false'))
114    eq(NIL, fn.luaeval('nil'))
115  end)
116
117  it('containers', function()
118    eq({}, fn.luaeval('{}'))
119    eq(3, eval('type(luaeval("{}"))'))
120
121    eq({ test = 1, foo = 2 }, fn.luaeval('{test=1, foo=2}'))
122    eq(4, eval('type(luaeval("{test=1, foo=2}"))'))
123
124    eq({ 4, 2 }, fn.luaeval('{4, 2}'))
125    eq(3, eval('type(luaeval("{4, 2}"))'))
126
127    eq({ NIL, 20 }, fn.luaeval('{[2] = 20}'))
128    eq(3, eval('type(luaeval("{[2] = 20}"))'))
129
130    eq({ 10, NIL, 30 }, fn.luaeval('{[1] = 10, [3] = 30}'))
131    eq(3, eval('type(luaeval("{[1] = 10, [3] = 30}"))'))
132
133    local level = 30
134    eq(nested_by_level[level].o, fn.luaeval(nested_by_level[level].s))
135
136    eq(
137      { _TYPE = {}, _VAL = { { '\000\n\000', '\000\n\000\000' } } },
138      fn.luaeval([[{['\0\n\0']='\0\n\0\0'}]])
139    )
140    eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]]))
141    eq(eval('v:t_blob'), eval([[type(luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0])]]))
142    eq(
143      { nested = { { _TYPE = {}, _VAL = { { '\000\n\000', '\000\n\000\000' } } } } },
144      fn.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]])
145    )
146  end)
147
148  it('passes scalars as argument', function()
149    eq(1, fn.luaeval('_A', 1))
150    eq(1.5, fn.luaeval('_A', 1.5))
151    eq('', fn.luaeval('_A', ''))
152    eq('test', fn.luaeval('_A', 'test'))
153    eq(NIL, fn.luaeval('_A', NIL))
154    eq(true, fn.luaeval('_A', true))
155    eq(false, fn.luaeval('_A', false))
156  end)
157
158  it('passes containers as argument', function()
159    eq({}, fn.luaeval('_A', {}))
160    eq({ test = 1 }, fn.luaeval('_A', { test = 1 }))
161    eq({ 4, 2 }, fn.luaeval('_A', { 4, 2 }))
162    local level = 28
163    eq(nested_by_level[level].o, fn.luaeval('_A', nested_by_level[level].o))
164  end)
165
166  local function sp(typ, val)
167    return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val)
168  end
169  local function mapsp(...)
170    local val = ''
171    for i = 1, (select('#', ...) / 2) do
172      val = ('%s[%s,%s],'):format(val, select(i * 2 - 1, ...), select(i * 2, ...))
173    end
174    return sp('map', '[' .. val .. ']')
175  end
176  local function luaevalarg(argexpr, expr)
177    return eval((([=[
178      [
179        extend(g:, {'_ret': luaeval(%s, %s)})._ret,
180        type(g:_ret)==type({})&&has_key(g:_ret, '_TYPE')
181        ? [
182          get(keys(filter(copy(v:msgpack_types), 'v:val is g:_ret._TYPE')), 0,
183              g:_ret._TYPE),
184          get(g:_ret, '_VAL', g:_ret)
185        ]
186        : [0, g:_ret]][1]
187    ]=]):format(expr or '"_A"', argexpr):gsub('\n', '')))
188  end
189
190  it('passes special dictionaries', function()
191    eq({ 0, '\000\n\000' }, luaevalarg(sp('string', '["\\n", "\\n"]')))
192    eq({ 0, true }, luaevalarg(sp('boolean', 1)))
193    eq({ 0, false }, luaevalarg(sp('boolean', 0)))
194    eq({ 0, NIL }, luaevalarg(sp('nil', 0)))
195    eq({ 0, { [''] = '' } }, luaevalarg(mapsp(sp('string', '[""]'), '""')))
196  end)
197
198  it('failure modes', function()
199    eq(
200      'Vim(call):E5100: Cannot convert given Lua table: table should contain either only integer keys or only string keys',
201      pcall_err(command, 'call luaeval("{1, foo=2}")')
202    )
203
204    startswith(
205      'Vim(call):E5107: Lua: [string "luaeval()"]:',
206      pcall_err(command, 'call luaeval("1, 2, 3")')
207    )
208    startswith(
209      'Vim(call):E5108: Lua: [string "luaeval()"]:',
210      pcall_err(command, 'call luaeval("(nil)()")')
211    )
212  end)
213
214  it('handles sending lua functions to viml', function()
215    eq(
216      true,
217      exec_lua [[
218      can_pass_lua_callback_to_vim_from_lua_result = nil
219
220      vim.fn.call(function()
221        can_pass_lua_callback_to_vim_from_lua_result = true
222      end, {})
223
224      return can_pass_lua_callback_to_vim_from_lua_result
225    ]]
226    )
227  end)
228
229  it('run functions even in timers', function()
230    eq(
231      true,
232      exec_lua [[
233      can_pass_lua_callback_to_vim_from_lua_result = nil
234
235      vim.fn.timer_start(50, function()
236        can_pass_lua_callback_to_vim_from_lua_result = true
237      end)
238
239      vim.wait(1000, function()
240        return can_pass_lua_callback_to_vim_from_lua_result
241      end)
242
243      return can_pass_lua_callback_to_vim_from_lua_result
244    ]]
245    )
246  end)
247
248  it('can run named functions more than once', function()
249    eq(
250      5,
251      exec_lua [[
252      count_of_vals = 0
253
254      vim.fn.timer_start(5, function()
255        count_of_vals = count_of_vals + 1
256      end, {['repeat'] = 5})
257
258      vim.fn.wait(1000, function()
259        return count_of_vals >= 5
260      end)
261
262      return count_of_vals
263    ]]
264    )
265  end)
266
267  it('can handle clashing names', function()
268    eq(
269      1,
270      exec_lua [[
271      local f_loc = function() return 1 end
272
273      local result = nil
274      vim.fn.timer_start(100, function()
275        result = f_loc()
276      end)
277
278      local f_loc = function() return 2 end
279      vim.wait(1000, function() return result ~= nil end)
280
281      return result
282    ]]
283    )
284  end)
285
286  it('can handle functions with errors', function()
287    eq(
288      true,
289      exec_lua [[
290      vim.fn.timer_start(10, function()
291        error("dead function")
292      end)
293
294      vim.wait(1000, function() return false end)
295
296      return true
297    ]]
298    )
299    -- v:errmsg is set properly #35554
300    matches(': dead function\n', api.nvim_get_vvar('errmsg'))
301  end)
302
303  it('can pass functions around', function()
304    command [[
305      function VimCanCallLuaCallbacks(Concat, Cb)
306        let message = a:Concat("Hello Vim", "I'm Lua")
307        call a:Cb(message)
308      endfunction
309    ]]
310
311    eq(
312      "Hello Vim I'm Lua",
313      exec_lua [[
314      can_pass_lua_callback_to_vim_from_lua_result = ""
315
316      vim.fn.VimCanCallLuaCallbacks(
317        function(greeting, message) return greeting .. " " .. message end,
318        function(message) can_pass_lua_callback_to_vim_from_lua_result = message end
319      )
320
321      return can_pass_lua_callback_to_vim_from_lua_result
322    ]]
323    )
324  end)
325
326  it('handles funcrefs', function()
327    command [[
328      function VimCanCallLuaCallbacks(Concat, Cb)
329        let message = a:Concat("Hello Vim", "I'm Lua")
330        call a:Cb(message)
331      endfunction
332    ]]
333
334    eq(
335      "Hello Vim I'm Lua",
336      exec_lua [[
337      can_pass_lua_callback_to_vim_from_lua_result = ""
338
339      vim.funcref('VimCanCallLuaCallbacks')(
340        function(greeting, message) return greeting .. " " .. message end,
341        function(message) can_pass_lua_callback_to_vim_from_lua_result = message end
342      )
343
344      return can_pass_lua_callback_to_vim_from_lua_result
345    ]]
346    )
347  end)
348
349  it('works with metatables using __call', function()
350    eq(
351      1,
352      exec_lua [[
353      local this_is_local_variable = false
354      local callable_table = setmetatable({x = 1}, {
355        __call = function(t, ...)
356          this_is_local_variable = t.x
357        end
358      })
359
360      vim.fn.timer_start(5, callable_table)
361
362      vim.wait(1000, function()
363        return this_is_local_variable
364      end)
365
366      return this_is_local_variable
367    ]]
368    )
369  end)
370
371  it('handles being called from a timer once.', function()
372    eq(
373      3,
374      exec_lua [[
375      local this_is_local_variable = false
376      local callable_table = setmetatable({5, 4, 3, 2, 1}, {
377        __call = function(t, ...) this_is_local_variable = t[3] end
378      })
379
380      vim.fn.timer_start(5, callable_table)
381      vim.wait(1000, function()
382        return this_is_local_variable
383      end)
384
385      return this_is_local_variable
386    ]]
387    )
388  end)
389
390  it('calls functions once with __call metamethod', function()
391    eq(
392      true,
393      exec_lua [[
394      local this_is_local_variable = false
395      local callable_table = setmetatable({a = true, b = false}, {
396        __call = function(t, ...) this_is_local_variable = t.a end
397      })
398
399      assert(getmetatable(callable_table).__call)
400      vim.fn.call(callable_table, {})
401
402      return this_is_local_variable
403    ]]
404    )
405  end)
406
407  it('works with lists using __call', function()
408    eq(
409      3,
410      exec_lua [[
411      local this_is_local_variable = false
412      local mt = {
413        __call = function(t, ...)
414          this_is_local_variable = t[3]
415        end
416      }
417      local callable_table = setmetatable({5, 4, 3, 2, 1}, mt)
418
419      -- Call it once...
420      vim.fn.timer_start(5, callable_table)
421      vim.wait(1000, function()
422        return this_is_local_variable
423      end)
424
425      assert(this_is_local_variable)
426      this_is_local_variable = false
427
428      vim.fn.timer_start(5, callable_table)
429      vim.wait(1000, function()
430        return this_is_local_variable
431      end)
432
433      return this_is_local_variable
434    ]]
435    )
436  end)
437
438  it('fails with tables not using __call', function()
439    eq(
440      { false, 'Vim:E921: Invalid callback argument' },
441      exec_lua [[
442      local this_is_local_variable = false
443      local callable_table = setmetatable({x = 1}, {})
444
445      return {pcall(function() vim.fn.timer_start(5, callable_table) end)}
446    ]]
447    )
448  end)
449
450  it('converts containers with type_idx', function()
451    eq(5, eval('type(luaeval("{[vim.type_idx]=vim.types.float, [vim.val_idx]=0}"))'))
452    eq(4, eval([[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]]))
453    eq(3, eval([[type(luaeval('{[vim.type_idx]=vim.types.array}'))]]))
454
455    eq({}, fn.luaeval('{[vim.type_idx]=vim.types.array}'))
456
457    -- Presence of type_idx makes Vim ignore some keys
458    eq(
459      { 42 },
460      fn.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')
461    )
462    eq(
463      { foo = 2 },
464      fn.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')
465    )
466    eq(10, fn.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}'))
467
468    -- The following should not crash
469    eq({}, fn.luaeval('{[vim.type_idx]=vim.types.dictionary}'))
470  end)
471
472  it('converts self-containing containers', function()
473    api.nvim_set_var('l', {})
474    eval('add(l, l)')
475    eq(true, eval('luaeval("_A == _A[1]", l)'))
476    eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])'))
477    eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})'))
478    eq(true, eval('luaeval("_A ~= _A[1]", [l])'))
479
480    api.nvim_set_var('d', { foo = 42 })
481    eval('extend(d, {"d": d})')
482    eq(true, eval('luaeval("_A == _A.d", d)'))
483    eq(true, eval('luaeval("_A[1] == _A[1].d", [d])'))
484    eq(true, eval('luaeval("_A.d == _A.d.d", {"d": d})'))
485    eq(true, eval('luaeval("_A ~= _A.d", {"d": d})'))
486  end)
487
488  it('fails when doing incorrect things in lua', function()
489    -- Conversion errors
490    eq(
491      'Vim(call):E5108: Lua: [string "luaeval()"]:0: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)',
492      remove_trace(pcall_err(command, [[call luaeval("vim.xxx_nonexistent_key_xxx()")]]))
493    )
494    eq(
495      'Vim(call):E5108: Lua: [string "luaeval()"]:0: ERROR',
496      remove_trace(pcall_err(command, [[call luaeval("error('ERROR')")]]))
497    )
498    eq(
499      'Vim(call):E5108: Lua: nil',
500      remove_trace(pcall_err(command, [[call luaeval("error(nil)")]]))
501    )
502  end)
503
504  it('does not leak memory when called with too long line', function()
505    local s = ('x'):rep(65536)
506    eq(
507      'Vim(call):E5107: Lua: [string "luaeval()"]:0: unexpected symbol near \')\'',
508      pcall_err(command, [[call luaeval("(']] .. s .. [[' + )")]])
509    )
510    eq(s, fn.luaeval('"' .. s .. '"'))
511  end)
512end)
513
514describe('v:lua', function()
515  before_each(function()
516    exec_lua([[
517      function _G.foo(a,b,n)
518        _G.val = n
519        return a+b
520      end
521      mymod = {}
522      function mymod.noisy(name)
523        vim.api.nvim_set_current_line("hey "..name)
524      end
525      function mymod.crashy()
526        nonexistent()
527      end
528      function mymod.whatis(value)
529        return type(value) .. ": " .. tostring(value)
530      end
531      function mymod.omni(findstart, base)
532        if findstart == 1 then
533          return 5
534        else
535          if base == 'st' then
536            return {'stuff', 'steam', 'strange things'}
537          end
538        end
539      end
540    ]])
541  end)
542
543  it('in expressions', function()
544    eq(7, eval('v:lua.foo(3,4,v:null)'))
545    eq(true, exec_lua([[return _G.val == vim.NIL]]))
546    eq(NIL, eval('v:lua.mymod.noisy("eval")'))
547    eq('hey eval', api.nvim_get_current_line())
548    eq('string: abc', eval('v:lua.mymod.whatis(0z616263)'))
549    eq('string: ', eval('v:lua.mymod.whatis(v:_null_blob)'))
550
551    eq(
552      'Vim:E5108: Lua: [string "<nvim>"]:0: attempt to call global \'nonexistent\' (a nil value)',
553      pcall_err(eval, 'v:lua.mymod.crashy()')
554    )
555  end)
556
557  it('when called as a method', function()
558    eq(123, eval('110->v:lua.foo(13)'))
559    eq(true, exec_lua([[return _G.val == nil]]))
560
561    eq(321, eval('300->v:lua.foo(21, "boop")'))
562    eq('boop', exec_lua([[return _G.val]]))
563
564    eq(NIL, eval('"there"->v:lua.mymod.noisy()'))
565    eq('hey there', api.nvim_get_current_line())
566    eq({ 5, 10, 15, 20 }, eval('[[1], [2, 3], [4]]->v:lua.vim.tbl_flatten()->map({_, v -> v * 5})'))
567
568    eq(
569      'Vim:E5108: Lua: [string "<nvim>"]:0: attempt to call global \'nonexistent\' (a nil value)',
570      pcall_err(eval, '"huh?"->v:lua.mymod.crashy()')
571    )
572  end)
573
574  it('in :call', function()
575    command(":call v:lua.mymod.noisy('command')")
576    eq('hey command', api.nvim_get_current_line())
577    eq(
578      'Vim(call):E5108: Lua: [string "<nvim>"]:0: attempt to call global \'nonexistent\' (a nil value)',
579      pcall_err(command, 'call v:lua.mymod.crashy()')
580    )
581  end)
582
583  it('in func options', function()
584    local screen = Screen.new(60, 8)
585    api.nvim_set_option_value('omnifunc', 'v:lua.mymod.omni', {})
586    feed('isome st<c-x><c-o>')
587    screen:expect {
588      grid = [[
589      some stuff^                                                  |
590      {1:~   }{12: stuff          }{1:                                        }|
591      {1:~   }{4: steam          }{1:                                        }|
592      {1:~   }{4: strange things }{1:                                        }|
593      {1:~                                                           }|*3
594      {5:-- Omni completion (^O^N^P) }{6:match 1 of 3}                    |
595    ]],
596    }
597    api.nvim_set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
598    feed('<Esc>g@g@')
599    eq('hey line', api.nvim_get_current_line())
600  end)
601
602  it('supports packages', function()
603    command('set pp+=test/functional/fixtures')
604    eq('\tbadval', eval("v:lua.require'leftpad'('badval')"))
605    eq(9003, eval("v:lua.require'bar'.doit()"))
606    eq(9004, eval("v:lua.require'baz-quux'.doit()"))
607    eq(9003, eval("1 ? v:lua.require'bar'.doit() : v:lua.require'baz-quux'.doit()"))
608    eq(9004, eval("0 ? v:lua.require'bar'.doit() : v:lua.require'baz-quux'.doit()"))
609  end)
610
611  it('fails for invalid usage', function()
612    eq(
613      [[Vim(let):E15: Invalid expression: "v:lua.func"]],
614      pcall_err(command, 'let g:Func = v:lua.func')
615    )
616    eq([[Vim(let):E15: Invalid expression: "v:lua"]], pcall_err(command, 'let g:Func = v:lua'))
617    eq(
618      [[Vim(let):E15: Invalid expression: "v:['lua']"]],
619      pcall_err(command, "let g:Func = v:['lua']")
620    )
621
622    eq([[Vim:E15: Invalid expression: "v:['lua'].foo()"]], pcall_err(eval, "v:['lua'].foo()"))
623    eq(
624      "Vim(call):E461: Illegal variable name: v:['lua']",
625      pcall_err(command, "call v:['lua'].baar()")
626    )
627    eq('Vim:E1085: Not a callable type: v:lua', pcall_err(eval, 'v:lua()'))
628
629    eq(
630      'Vim(let):E46: Cannot change read-only variable "v:[\'lua\']"',
631      pcall_err(command, "let v:['lua'] = 'xx'")
632    )
633    eq(
634      'Vim(let):E46: Cannot change read-only variable "v:lua"',
635      pcall_err(command, "let v:lua = 'xx'")
636    )
637
638    eq('Vim:E107: Missing parentheses: v:lua.func', pcall_err(eval, "'bad'->v:lua.func"))
639    eq(
640      'Vim:E274: No white space allowed before parenthesis',
641      pcall_err(eval, "'bad'->v:lua.func ()")
642    )
643    eq('Vim:E107: Missing parentheses: v:lua', pcall_err(eval, "'bad'->v:lua"))
644    eq('Vim:E1085: Not a callable type: v:lua', pcall_err(eval, "'bad'->v:lua()"))
645    eq([[Vim:E15: Invalid expression: "v:lua.()"]], pcall_err(eval, "'bad'->v:lua.()"))
646
647    eq('Vim:E1085: Not a callable type: v:lua', pcall_err(eval, 'v:lua()'))
648    eq([[Vim:E15: Invalid expression: "v:lua.()"]], pcall_err(eval, 'v:lua.()'))
649  end)
650
651  describe('invalid usage in fold text', function()
652    before_each(function()
653      feed('ifoo<CR>bar<Esc>')
654      command('1,2fold')
655    end)
656
657    it('with missing function name when used as simple function', function()
658      api.nvim_set_option_value('debug', 'throw', {})
659      eq(
660        [[Vim(eval):E15: Invalid expression: "v:lua.()"]],
661        pcall_err(command, 'set foldtext=v:lua.() | eval foldtextresult(1)')
662      )
663    end)
664
665    it('with missing function name when used in expression', function()
666      api.nvim_set_option_value('debug', 'throw', {})
667      eq(
668        [[Vim(eval):E15: Invalid expression: "+v:lua.()"]],
669        pcall_err(command, 'set foldtext=+v:lua.() | eval foldtextresult(1)')
670      )
671    end)
672
673    it('with non-existent function when used as simple function', function()
674      command('set foldtext=v:lua.NoSuchFunc() | eval foldtextresult(1)')
675      assert_alive()
676    end)
677
678    it('with non-existent function when used in expression', function()
679      command('set foldtext=+v:lua.NoSuchFunc() | eval foldtextresult(1)')
680      assert_alive()
681    end)
682  end)
683end)