@@ -124,7 +124,7 @@ func Test_window_set_current()
124124 lua w2 ()
125125 call assert_equal (' Xfoo2' , bufname (' %' ))
126126
127- lua w1, w2 = nil, nil
127+ lua w1, w2 = nil
128128 % bwipe!
129129endfunc
130130
@@ -142,7 +142,7 @@ func Test_window_buffer()
142142 lua b2 ()
143143 call assert_equal (' Xfoo2' , bufname (' %' ))
144144
145- lua b1, b2 = nil, nil
145+ lua b1, b2, w1, w2 = nil
146146 % bwipe!
147147endfunc
148148
@@ -191,7 +191,7 @@ func Test_buffer()
191191 call assert_equal (' Xfoo1' , luaeval (" vim.buffer(" . bn1 . " ).name" ))
192192 call assert_equal (' Xfoo2' , luaeval (" vim.buffer(" . bn2 . " ).name" ))
193193
194- lua bn1, bn2 = nil, nil
194+ lua bn1, bn2 = nil
195195 % bwipe!
196196endfunc
197197
@@ -275,7 +275,7 @@ func Test_buffer_next_previous()
275275 call assert_equal (' Xfoo1' , luaeval (' vim.buffer().name' ))
276276 call assert_equal (' Xfoo1' , bufname (' %' ))
277277
278- lua bn , bp = nil, nil
278+ lua bn , bp = nil
279279 % bwipe!
280280endfunc
281281
@@ -295,12 +295,6 @@ endfunc
295295func Test_list ()
296296 call assert_equal ([], luaeval (' vim.list()' ))
297297
298- " Same example as in :help lua-vim.
299- " FIXME: test is disabled because it does not work.
300- " See https://github.com/vim/vim/issues/3086
301- " lua t = {math.pi, false, say = 'hi'}
302- " call assert_equal([3.141593, 0], luaeval('vim.list(t)'))
303-
304298 let l = []
305299 lua l = vim .eval (' l' )
306300 lua l: add (123 )
@@ -319,17 +313,34 @@ func Test_list()
319313 lua l: insert (' xx' , 3 )
320314 call assert_equal ([' first' , 124.0 , ' abc' , ' xx' , v: true , v: false , {' a' : 1 , ' b' : 2 , ' c' : 3 }], l )
321315
316+ lockvar 1 l
317+ call assert_fails (' lua l:add("x")' , ' [string "vim chunk"]:1: list is locked' )
318+
322319 lua l = nil
323320endfunc
324321
322+ func Test_list_table ()
323+ " See :help lua-vim
324+ " Non-numeric keys should not be used to initialize the list
325+ " so say = 'hi' should be ignored.
326+ lua t = {3.14 , ' hello' , false, true, say = ' hi' }
327+ call assert_equal ([3.14 , ' hello' , v: false , v: true ], luaeval (' vim.list(t)' ))
328+ lua t = nil
329+
330+ call assert_fails (' lua vim.list(1)' , ' [string "vim chunk"]:1: table expected, got number' )
331+ call assert_fails (' lua vim.list("x")' , ' [string "vim chunk"]:1: table expected, got string' )
332+ call assert_fails (' lua vim.list(print)' , ' [string "vim chunk"]:1: table expected, got function' )
333+ call assert_fails (' lua vim.list(true)' , ' [string "vim chunk"]:1: table expected, got boolean' )
334+ endfunc
335+
325336" Test l() i.e. iterator on list
326337func Test_list_iter ()
327338 lua l = vim .list (): add (' foo' ): add (' bar' )
328339 lua str = ' '
329340 lua for v in l () do str = str .. v end
330341 call assert_equal (' foobar' , luaeval (' str' ))
331342
332- lua str, v , l = nil, nil, nil
343+ lua str, l = nil
333344endfunc
334345
335346func Test_recursive_list ()
@@ -359,12 +370,6 @@ endfunc
359370func Test_dict ()
360371 call assert_equal ({}, luaeval (' vim.dict()' ))
361372
362- " Same example as in :help lua-vim.
363- " FIXME: test is disabled because it does not work.
364- " See https://github.com/vim/vim/issues/3086
365- " lua t = {math.pi, false, say = 'hi'}
366- " call assert_equal({'say' : 'hi'}, luaeval('vim.dict(t)'))
367-
368373 let d = {}
369374 lua d = vim .eval (' d' )
370375 lua d [0 ] = 123
@@ -383,9 +388,32 @@ func Test_dict()
383388 lua d [4 ] = nil
384389 call assert_equal ({' 0' :124.0 , ' 1' :' abc' , ' 2' :v: true , ' 3' :v: false , ' 5' : {' a' :1 , ' b' :2 , ' c' :3 }}, d )
385390
391+ lockvar 1 d
392+ call assert_fails (' lua d[6] = 1' , ' [string "vim chunk"]:1: dict is locked' )
393+
386394 lua d = nil
387395endfunc
388396
397+ func Test_dict_table ()
398+ lua t = {key1 = ' x' , key2 = 3.14 , key3 = true, key4 = false}
399+ call assert_equal ({' key1' : ' x' , ' key2' : 3.14 , ' key3' : v: true , ' key4' : v: false },
400+ \ luaeval (' vim.dict(t)' ))
401+
402+ " Same example as in :help lua-vim.
403+ lua t = {math.pi , false, say = ' hi' }
404+ " FIXME: commented out as it currently does not work as documented:
405+ " Expected {'say': 'hi'}
406+ " but got {'1': 3.141593, '2': v:false, 'say': 'hi'}
407+ " Is the documentation or the code wrong?
408+ " call assert_equal({'say' : 'hi'}, luaeval('vim.dict(t)'))
409+ lua t = nil
410+
411+ call assert_fails (' lua vim.dict(1)' , ' [string "vim chunk"]:1: table expected, got number' )
412+ call assert_fails (' lua vim.dict("x")' , ' [string "vim chunk"]:1: table expected, got string' )
413+ call assert_fails (' lua vim.dict(print)' , ' [string "vim chunk"]:1: table expected, got function' )
414+ call assert_fails (' lua vim.dict(true)' , ' [string "vim chunk"]:1: table expected, got boolean' )
415+ endfunc
416+
389417" Test d() i.e. iterator on dictionary
390418func Test_dict_iter ()
391419 let d = {' a' : 1 , ' b' :2 }
@@ -394,7 +422,7 @@ func Test_dict_iter()
394422 lua for k ,v in d () do str = str .. k ..' :' .. v .. ' ,' end
395423 call assert_equal (' a:1,b:2,' , luaeval (' str' ))
396424
397- lua str, k , v , d = nil, nil, nil, nil
425+ lua str, d = nil
398426endfunc
399427
400428func Test_funcref ()
@@ -418,6 +446,8 @@ func Test_funcref()
418446 lua d .len = vim .funcref " Mylen" -- assign d as ' self'
419447 lua res = (d .len () == vim .funcref " len" (vim .eval " l" )) and " OK" or " FAIL"
420448 call assert_equal (" OK" , luaeval (' res' ))
449+
450+ lua i1, i2, msg, d , res = nil
421451endfunc
422452
423453" Test vim.type()
@@ -496,7 +526,7 @@ func Test_luafile()
496526 call assert_equal (' hello' , luaeval (' str' ))
497527 call assert_equal (123.0 , luaeval (' num' ))
498528
499- lua str, num = nil, nil
529+ lua str, num = nil
500530 call delete (' Xlua_file' )
501531endfunc
502532
@@ -512,7 +542,19 @@ func Test_luafile_percent()
512542 let msg = split (execute (' message' ), " \n " )[-1 ]
513543 call assert_equal (' str=foo, num=321' , msg)
514544
515- lua str, num = nil, nil
545+ lua str, num = nil
546+ call delete (' Xlua_file' )
547+ bwipe!
548+ endfunc
549+
550+ " Test :luafile with syntax error
551+ func Test_luafile_error ()
552+ new Xlua_file
553+ call writefile ([' nil = 0' ], ' Xlua_file' )
554+ call setfperm (' Xlua_file' , ' r-xr-xr-x' )
555+
556+ call assert_fails (' luafile Xlua_file' , " Xlua_file:1: unexpected symbol near 'nil'" )
557+
516558 call delete (' Xlua_file' )
517559 bwipe!
518560endfunc
0 commit comments