mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.0136: Lua tests don't cover new features
Problem: Lua tests don't cover new features. Solution: Add more tests. (Dominique Pelle, closes #3130)
This commit is contained in:
parent
e0429681ae
commit
2f362bf7f9
@ -127,7 +127,7 @@ Vim evaluation and command execution, and others.
|
|||||||
rules. Example: >
|
rules. Example: >
|
||||||
:lua t = {math.pi, false, say = 'hi'}
|
:lua t = {math.pi, false, say = 'hi'}
|
||||||
:echo luaeval('vim.list(t)')
|
:echo luaeval('vim.list(t)')
|
||||||
:" [3.141593, 0], 'say' is ignored
|
:" [3.141593, v:false], 'say' is ignored
|
||||||
<
|
<
|
||||||
vim.dict([arg]) Returns an empty dictionary or, if "arg" is a
|
vim.dict([arg]) Returns an empty dictionary or, if "arg" is a
|
||||||
Lua table, returns a dict d such that d[k] =
|
Lua table, returns a dict d such that d[k] =
|
||||||
@ -141,8 +141,7 @@ Vim evaluation and command execution, and others.
|
|||||||
:" {'say': 'hi'}, numeric keys ignored
|
:" {'say': 'hi'}, numeric keys ignored
|
||||||
<
|
<
|
||||||
vim.funcref({name}) Returns a Funcref to function {name} (see
|
vim.funcref({name}) Returns a Funcref to function {name} (see
|
||||||
|Funcref|). It is equivalent to Vim's
|
|Funcref|). It is equivalent to Vim's function().
|
||||||
"function". NOT IMPLEMENTED YET
|
|
||||||
|
|
||||||
vim.buffer([arg]) If "arg" is a number, returns buffer with
|
vim.buffer([arg]) If "arg" is a number, returns buffer with
|
||||||
number "arg" in the buffer list or, if "arg"
|
number "arg" in the buffer list or, if "arg"
|
||||||
@ -166,7 +165,7 @@ Vim evaluation and command execution, and others.
|
|||||||
or window, respectively. Examples: >
|
or window, respectively. Examples: >
|
||||||
:lua l = vim.list()
|
:lua l = vim.list()
|
||||||
:lua print(type(l), vim.type(l))
|
:lua print(type(l), vim.type(l))
|
||||||
:" userdata list
|
:" list
|
||||||
<
|
<
|
||||||
vim.command({cmd}) Executes the vim (ex-mode) command {cmd}.
|
vim.command({cmd}) Executes the vim (ex-mode) command {cmd}.
|
||||||
Examples: >
|
Examples: >
|
||||||
|
@ -124,7 +124,7 @@ func Test_window_set_current()
|
|||||||
lua w2()
|
lua w2()
|
||||||
call assert_equal('Xfoo2', bufname('%'))
|
call assert_equal('Xfoo2', bufname('%'))
|
||||||
|
|
||||||
lua w1, w2 = nil, nil
|
lua w1, w2 = nil
|
||||||
%bwipe!
|
%bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ func Test_window_buffer()
|
|||||||
lua b2()
|
lua b2()
|
||||||
call assert_equal('Xfoo2', bufname('%'))
|
call assert_equal('Xfoo2', bufname('%'))
|
||||||
|
|
||||||
lua b1, b2 = nil, nil
|
lua b1, b2, w1, w2 = nil
|
||||||
%bwipe!
|
%bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ func Test_buffer()
|
|||||||
call assert_equal('Xfoo1', luaeval("vim.buffer(" . bn1 . ").name"))
|
call assert_equal('Xfoo1', luaeval("vim.buffer(" . bn1 . ").name"))
|
||||||
call assert_equal('Xfoo2', luaeval("vim.buffer(" . bn2 . ").name"))
|
call assert_equal('Xfoo2', luaeval("vim.buffer(" . bn2 . ").name"))
|
||||||
|
|
||||||
lua bn1, bn2 = nil, nil
|
lua bn1, bn2 = nil
|
||||||
%bwipe!
|
%bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ func Test_buffer_next_previous()
|
|||||||
call assert_equal('Xfoo1', luaeval('vim.buffer().name'))
|
call assert_equal('Xfoo1', luaeval('vim.buffer().name'))
|
||||||
call assert_equal('Xfoo1', bufname('%'))
|
call assert_equal('Xfoo1', bufname('%'))
|
||||||
|
|
||||||
lua bn, bp = nil, nil
|
lua bn, bp = nil
|
||||||
%bwipe!
|
%bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -295,12 +295,6 @@ endfunc
|
|||||||
func Test_list()
|
func Test_list()
|
||||||
call assert_equal([], luaeval('vim.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 = []
|
let l = []
|
||||||
lua l = vim.eval('l')
|
lua l = vim.eval('l')
|
||||||
lua l:add(123)
|
lua l:add(123)
|
||||||
@ -319,9 +313,26 @@ func Test_list()
|
|||||||
lua l:insert('xx', 3)
|
lua l:insert('xx', 3)
|
||||||
call assert_equal(['first', 124.0, 'abc', 'xx', v:true, v:false, {'a': 1, 'b': 2, 'c': 3}], l)
|
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
|
lua l = nil
|
||||||
endfunc
|
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
|
" Test l() i.e. iterator on list
|
||||||
func Test_list_iter()
|
func Test_list_iter()
|
||||||
lua l = vim.list():add('foo'):add('bar')
|
lua l = vim.list():add('foo'):add('bar')
|
||||||
@ -329,7 +340,7 @@ func Test_list_iter()
|
|||||||
lua for v in l() do str = str .. v end
|
lua for v in l() do str = str .. v end
|
||||||
call assert_equal('foobar', luaeval('str'))
|
call assert_equal('foobar', luaeval('str'))
|
||||||
|
|
||||||
lua str, v, l = nil, nil, nil
|
lua str, l = nil
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_recursive_list()
|
func Test_recursive_list()
|
||||||
@ -359,12 +370,6 @@ endfunc
|
|||||||
func Test_dict()
|
func Test_dict()
|
||||||
call assert_equal({}, luaeval('vim.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 = {}
|
let d = {}
|
||||||
lua d = vim.eval('d')
|
lua d = vim.eval('d')
|
||||||
lua d[0] = 123
|
lua d[0] = 123
|
||||||
@ -383,9 +388,32 @@ func Test_dict()
|
|||||||
lua d[4] = nil
|
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)
|
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
|
lua d = nil
|
||||||
endfunc
|
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
|
" Test d() i.e. iterator on dictionary
|
||||||
func Test_dict_iter()
|
func Test_dict_iter()
|
||||||
let d = {'a': 1, 'b':2}
|
let d = {'a': 1, 'b':2}
|
||||||
@ -394,7 +422,7 @@ func Test_dict_iter()
|
|||||||
lua for k,v in d() do str = str .. k ..':' .. v .. ',' end
|
lua for k,v in d() do str = str .. k ..':' .. v .. ',' end
|
||||||
call assert_equal('a:1,b:2,', luaeval('str'))
|
call assert_equal('a:1,b:2,', luaeval('str'))
|
||||||
|
|
||||||
lua str, k, v, d = nil, nil, nil, nil
|
lua str, d = nil
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_funcref()
|
func Test_funcref()
|
||||||
@ -418,6 +446,8 @@ func Test_funcref()
|
|||||||
lua d.len = vim.funcref"Mylen" -- assign d as 'self'
|
lua d.len = vim.funcref"Mylen" -- assign d as 'self'
|
||||||
lua res = (d.len() == vim.funcref"len"(vim.eval"l")) and "OK" or "FAIL"
|
lua res = (d.len() == vim.funcref"len"(vim.eval"l")) and "OK" or "FAIL"
|
||||||
call assert_equal("OK", luaeval('res'))
|
call assert_equal("OK", luaeval('res'))
|
||||||
|
|
||||||
|
lua i1, i2, msg, d, res = nil
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test vim.type()
|
" Test vim.type()
|
||||||
@ -496,7 +526,7 @@ func Test_luafile()
|
|||||||
call assert_equal('hello', luaeval('str'))
|
call assert_equal('hello', luaeval('str'))
|
||||||
call assert_equal(123.0, luaeval('num'))
|
call assert_equal(123.0, luaeval('num'))
|
||||||
|
|
||||||
lua str, num = nil, nil
|
lua str, num = nil
|
||||||
call delete('Xlua_file')
|
call delete('Xlua_file')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -512,7 +542,19 @@ func Test_luafile_percent()
|
|||||||
let msg = split(execute('message'), "\n")[-1]
|
let msg = split(execute('message'), "\n")[-1]
|
||||||
call assert_equal('str=foo, num=321', msg)
|
call assert_equal('str=foo, num=321', msg)
|
||||||
|
|
||||||
lua str, num = nil, nil
|
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')
|
call delete('Xlua_file')
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -789,6 +789,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
136,
|
||||||
/**/
|
/**/
|
||||||
135,
|
135,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user