Mercurial > vim
diff src/testdir/test_lua.vim @ 21060:89aba7895bb2 v8.2.1081
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Commit: https://github.com/vim/vim/commit/a1f9f8666ed3a462eb8a518e78418c57dc41bbd4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 28 22:41:26 2020 +0200
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Problem: Lua: cannot use table.insert() and table.remove().
Solution: Add the list functions. (Prabir Shrestha, closes https://github.com/vim/vim/issues/6353)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Jun 2020 22:45:04 +0200 |
parents | 08e284594211 |
children | 43e82e8133b9 |
line wrap: on
line diff
--- a/src/testdir/test_lua.vim +++ b/src/testdir/test_lua.vim @@ -353,6 +353,32 @@ func Test_lua_list_table() call assert_fails('lua vim.list(true)', '[string "vim chunk"]:1: table expected, got boolean') endfunc +func Test_lua_list_table_insert_remove() + let luaver = split(split(luaeval('_VERSION'), ' ')[1], '\.') + let major = str2nr(luaver[0]) + let minor = str2nr(luaver[1]) + + if major < 5 || (major == 5 && minor < 3) + throw 'Skipped: Lua version < 5.3' + endif + + let l = [1, 2] + lua t = vim.eval('l') + lua table.insert(t, 10) + lua t[#t + 1] = 20 + lua table.insert(t, 2, 30) + call assert_equal(l, [1, 30, 2, 10, 20]) + lua table.remove(t, 2) + call assert_equal(l, [1, 2, 10, 20]) + lua t[3] = nil + call assert_equal(l, [1, 2, 20]) + lua removed_value = table.remove(t, 3) + call assert_equal(luaeval('removed_value'), 20) + lua t = nil + lua removed_value = nil + unlet l +endfunc + " Test l() i.e. iterator on list func Test_lua_list_iter() lua l = vim.list():add('foo'):add('bar')