Patch 8.1.0136
Problem:    Lua tests don't cover new features.
Solution:   Add more tests. (Dominique Pelle, closes #3130)
Files:      runtime/doc/if_lua.txt, src/testdir/test_lua.vim


*** ../vim-8.1.0135/runtime/doc/if_lua.txt      2018-05-17 13:41:41.000000000 
+0200
--- runtime/doc/if_lua.txt      2018-07-01 19:45:39.183210699 +0200
***************
*** 127,133 ****
                                rules. Example: >
                                        :lua t = {math.pi, false, say = 'hi'}
                                        :echo luaeval('vim.list(t)')
!                                       :" [3.141593, 0], 'say' is ignored
  <
        vim.dict([arg])         Returns an empty dictionary or, if "arg" is a
                                Lua table, returns a dict d such that d[k] =
--- 127,133 ----
                                rules. Example: >
                                        :lua t = {math.pi, false, say = 'hi'}
                                        :echo luaeval('vim.list(t)')
!                                       :" [3.141593, v:false], 'say' is ignored
  <
        vim.dict([arg])         Returns an empty dictionary or, if "arg" is a
                                Lua table, returns a dict d such that d[k] =
***************
*** 141,148 ****
                                        :" {'say': 'hi'}, numeric keys ignored
  <
        vim.funcref({name})     Returns a Funcref to function {name} (see
!                               |Funcref|). It is equivalent to Vim's
!                               "function". NOT IMPLEMENTED YET
  
        vim.buffer([arg])       If "arg" is a number, returns buffer with
                                number "arg" in the buffer list or, if "arg"
--- 141,147 ----
                                        :" {'say': 'hi'}, numeric keys ignored
  <
        vim.funcref({name})     Returns a Funcref to function {name} (see
!                               |Funcref|). It is equivalent to Vim's 
function().
  
        vim.buffer([arg])       If "arg" is a number, returns buffer with
                                number "arg" in the buffer list or, if "arg"
***************
*** 166,172 ****
                                or window, respectively. Examples: >
                                        :lua l = vim.list()
                                        :lua print(type(l), vim.type(l))
!                                       :" userdata list
  <
        vim.command({cmd})      Executes the vim (ex-mode) command {cmd}.
                                Examples: >
--- 165,171 ----
                                or window, respectively. Examples: >
                                        :lua l = vim.list()
                                        :lua print(type(l), vim.type(l))
!                                       :" list
  <
        vim.command({cmd})      Executes the vim (ex-mode) command {cmd}.
                                Examples: >
*** ../vim-8.1.0135/src/testdir/test_lua.vim    2018-07-01 15:12:00.224057865 
+0200
--- src/testdir/test_lua.vim    2018-07-01 19:45:39.183210699 +0200
***************
*** 124,130 ****
    lua w2()
    call assert_equal('Xfoo2', bufname('%'))
  
!   lua w1, w2 = nil, nil
    %bwipe!
  endfunc
  
--- 124,130 ----
    lua w2()
    call assert_equal('Xfoo2', bufname('%'))
  
!   lua w1, w2 = nil
    %bwipe!
  endfunc
  
***************
*** 142,148 ****
    lua b2()
    call assert_equal('Xfoo2', bufname('%'))
  
!   lua b1, b2 = nil, nil
    %bwipe!
  endfunc
  
--- 142,148 ----
    lua b2()
    call assert_equal('Xfoo2', bufname('%'))
  
!   lua b1, b2, w1, w2 = nil
    %bwipe!
  endfunc
  
***************
*** 191,197 ****
    call assert_equal('Xfoo1', luaeval("vim.buffer(" . bn1 . ").name"))
    call assert_equal('Xfoo2', luaeval("vim.buffer(" . bn2 . ").name"))
  
!   lua bn1, bn2 = nil, nil
    %bwipe!
  endfunc
  
--- 191,197 ----
    call assert_equal('Xfoo1', luaeval("vim.buffer(" . bn1 . ").name"))
    call assert_equal('Xfoo2', luaeval("vim.buffer(" . bn2 . ").name"))
  
!   lua bn1, bn2 = nil
    %bwipe!
  endfunc
  
***************
*** 275,281 ****
    call assert_equal('Xfoo1', luaeval('vim.buffer().name'))
    call assert_equal('Xfoo1', bufname('%'))
  
!   lua bn, bp = nil, nil
    %bwipe!
  endfunc
  
--- 275,281 ----
    call assert_equal('Xfoo1', luaeval('vim.buffer().name'))
    call assert_equal('Xfoo1', bufname('%'))
  
!   lua bn, bp = nil
    %bwipe!
  endfunc
  
***************
*** 295,306 ****
  func Test_list()
    call assert_equal([], luaeval('vim.list()'))
  
-   " Same example as in :help lua-vim.
-   " FIXME: test is disabled because it does not work.
-   " See https://github.com/vim/vim/issues/3086
-   " lua t = {math.pi, false, say = 'hi'}
-   " call assert_equal([3.141593, 0], luaeval('vim.list(t)'))
- 
    let l = []
    lua l = vim.eval('l')
    lua l:add(123)
--- 295,300 ----
***************
*** 319,327 ****
--- 313,338 ----
    lua l:insert('xx', 3)
    call assert_equal(['first', 124.0, 'abc', 'xx', v:true, v:false, {'a': 1, 
'b': 2, 'c': 3}], l)
  
+   lockvar 1 l
+   call assert_fails('lua l:add("x")', '[string "vim chunk"]:1: list is 
locked')
+ 
    lua l = nil
  endfunc
  
+ func Test_list_table()
+   " See :help lua-vim
+   " Non-numeric keys should not be used to initialize the list
+   " so say = 'hi' should be ignored.
+   lua t = {3.14, 'hello', false, true, say = 'hi'}
+   call assert_equal([3.14, 'hello', v:false, v:true], luaeval('vim.list(t)'))
+   lua t = nil
+ 
+   call assert_fails('lua vim.list(1)', '[string "vim chunk"]:1: table 
expected, got number')
+   call assert_fails('lua vim.list("x")', '[string "vim chunk"]:1: table 
expected, got string')
+   call assert_fails('lua vim.list(print)', '[string "vim chunk"]:1: table 
expected, got function')
+   call assert_fails('lua vim.list(true)', '[string "vim chunk"]:1: table 
expected, got boolean')
+ endfunc
+ 
  " Test l() i.e. iterator on list
  func Test_list_iter()
    lua l = vim.list():add('foo'):add('bar')
***************
*** 329,335 ****
    lua for v in l() do str = str .. v end
    call assert_equal('foobar', luaeval('str'))
  
!   lua str, v, l = nil, nil, nil
  endfunc
  
  func Test_recursive_list()
--- 340,346 ----
    lua for v in l() do str = str .. v end
    call assert_equal('foobar', luaeval('str'))
  
!   lua str, l = nil
  endfunc
  
  func Test_recursive_list()
***************
*** 359,370 ****
  func Test_dict()
    call assert_equal({}, luaeval('vim.dict()'))
  
-   " Same example as in :help lua-vim.
-   " FIXME: test is disabled because it does not work.
-   " See https://github.com/vim/vim/issues/3086
-   " lua t = {math.pi, false, say = 'hi'}
-   " call assert_equal({'say' : 'hi'}, luaeval('vim.dict(t)'))
- 
    let d = {}
    lua d = vim.eval('d')
    lua d[0] = 123
--- 370,375 ----
***************
*** 383,391 ****
--- 388,419 ----
    lua d[4] = nil
    call assert_equal({'0':124.0, '1':'abc', '2':v:true, '3':v:false, '5': 
{'a':1, 'b':2, 'c':3}}, d)
  
+   lockvar 1 d
+   call assert_fails('lua d[6] = 1', '[string "vim chunk"]:1: dict is locked')
+ 
    lua d = nil
  endfunc
  
+ func Test_dict_table()
+   lua t = {key1 = 'x', key2 = 3.14, key3 = true, key4 = false}
+   call assert_equal({'key1': 'x', 'key2': 3.14, 'key3': v:true, 'key4': 
v:false},
+         \           luaeval('vim.dict(t)'))
+ 
+   " Same example as in :help lua-vim.
+   lua t = {math.pi, false, say = 'hi'}
+   " FIXME: commented out as it currently does not work as documented:
+   " Expected {'say': 'hi'}
+   " but got {'1': 3.141593, '2': v:false, 'say': 'hi'}
+   " Is the documentation or the code wrong?
+   "call assert_equal({'say' : 'hi'}, luaeval('vim.dict(t)'))
+   lua t = nil
+ 
+   call assert_fails('lua vim.dict(1)', '[string "vim chunk"]:1: table 
expected, got number')
+   call assert_fails('lua vim.dict("x")', '[string "vim chunk"]:1: table 
expected, got string')
+   call assert_fails('lua vim.dict(print)', '[string "vim chunk"]:1: table 
expected, got function')
+   call assert_fails('lua vim.dict(true)', '[string "vim chunk"]:1: table 
expected, got boolean')
+ endfunc
+ 
  " Test d() i.e. iterator on dictionary
  func Test_dict_iter()
    let d = {'a': 1, 'b':2}
***************
*** 394,400 ****
    lua for k,v in d() do str = str .. k ..':' .. v .. ',' end
    call assert_equal('a:1,b:2,', luaeval('str'))
  
!   lua str, k, v, d = nil, nil, nil, nil
  endfunc
  
  func Test_funcref()
--- 422,428 ----
    lua for k,v in d() do str = str .. k ..':' .. v .. ',' end
    call assert_equal('a:1,b:2,', luaeval('str'))
  
!   lua str, d = nil
  endfunc
  
  func Test_funcref()
***************
*** 418,423 ****
--- 446,453 ----
    lua d.len = vim.funcref"Mylen" -- assign d as 'self'
    lua res = (d.len() == vim.funcref"len"(vim.eval"l")) and "OK" or "FAIL"
    call assert_equal("OK", luaeval('res'))
+ 
+   lua i1, i2, msg, d, res = nil
  endfunc
  
  " Test vim.type()
***************
*** 496,502 ****
    call assert_equal('hello', luaeval('str'))
    call assert_equal(123.0, luaeval('num'))
  
!   lua str, num = nil, nil
    call delete('Xlua_file')
  endfunc
  
--- 526,532 ----
    call assert_equal('hello', luaeval('str'))
    call assert_equal(123.0, luaeval('num'))
  
!   lua str, num = nil
    call delete('Xlua_file')
  endfunc
  
***************
*** 512,518 ****
    let msg = split(execute('message'), "\n")[-1]
    call assert_equal('str=foo, num=321', msg)
  
!   lua str, num = nil, nil
    call delete('Xlua_file')
    bwipe!
  endfunc
--- 542,560 ----
    let msg = split(execute('message'), "\n")[-1]
    call assert_equal('str=foo, num=321', msg)
  
!   lua str, num = nil
!   call delete('Xlua_file')
!   bwipe!
! endfunc
! 
! " Test :luafile with syntax error
! func Test_luafile_error()
!   new Xlua_file
!   call writefile(['nil = 0' ], 'Xlua_file')
!   call setfperm('Xlua_file', 'r-xr-xr-x')
! 
!   call assert_fails('luafile Xlua_file', "Xlua_file:1: unexpected symbol near 
'nil'")
! 
    call delete('Xlua_file')
    bwipe!
  endfunc
*** ../vim-8.1.0135/src/version.c       2018-07-01 16:43:59.850736541 +0200
--- src/version.c       2018-07-01 19:47:47.126402301 +0200
***************
*** 791,792 ****
--- 791,794 ----
  {   /* Add new patch number below this line */
+ /**/
+     136,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
165. You have a web page burned into your glasses

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui