aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua112
1 files changed, 63 insertions, 49 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 3832d27a22..317f92fcdc 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -131,9 +131,9 @@ describe('lua stdlib', function()
eq(false, funcs.luaeval('vim.startswith("123", "2")'))
eq(false, funcs.luaeval('vim.startswith("123", "1234")'))
- eq("Error executing lua: vim/shared.lua:0: prefix: expected string, got nil",
+ matches("prefix: expected string, got nil",
pcall_err(exec_lua, 'return vim.startswith("123", nil)'))
- eq("Error executing lua: vim/shared.lua:0: s: expected string, got nil",
+ matches("s: expected string, got nil",
pcall_err(exec_lua, 'return vim.startswith(nil, "123")'))
end)
@@ -147,9 +147,9 @@ describe('lua stdlib', function()
eq(false, funcs.luaeval('vim.endswith("123", "2")'))
eq(false, funcs.luaeval('vim.endswith("123", "1234")'))
- eq("Error executing lua: vim/shared.lua:0: suffix: expected string, got nil",
+ matches("suffix: expected string, got nil",
pcall_err(exec_lua, 'return vim.endswith("123", nil)'))
- eq("Error executing lua: vim/shared.lua:0: s: expected string, got nil",
+ matches("s: expected string, got nil",
pcall_err(exec_lua, 'return vim.endswith(nil, "123")'))
end)
@@ -220,9 +220,9 @@ describe('lua stdlib', function()
eq({"yy","xx"}, exec_lua("return test_table"))
-- Validates args.
- eq('Error executing lua: vim.schedule: expected function',
+ matches('vim.schedule: expected function',
pcall_err(exec_lua, "vim.schedule('stringly')"))
- eq('Error executing lua: vim.schedule: expected function',
+ matches('vim.schedule: expected function',
pcall_err(exec_lua, "vim.schedule()"))
exec_lua([[
@@ -232,7 +232,7 @@ describe('lua stdlib', function()
]])
feed("<cr>")
- eq('Error executing vim.schedule lua callback: [string "<nvim>"]:2: big failure\nvery async', remove_trace(eval("v:errmsg")))
+ matches('big failure\nvery async', remove_trace(eval("v:errmsg")))
local screen = Screen.new(60,5)
screen:set_default_attr_ids({
@@ -300,16 +300,16 @@ describe('lua stdlib', function()
}
for _, t in ipairs(loops) do
- eq("Error executing lua: vim/shared.lua:0: Infinite loop detected", pcall_err(split, t[1], t[2]))
+ matches("Infinite loop detected", pcall_err(split, t[1], t[2]))
end
-- Validates args.
eq(true, pcall(split, 'string', 'string'))
- eq('Error executing lua: vim/shared.lua:0: s: expected string, got number',
+ matches('s: expected string, got number',
pcall_err(split, 1, 'string'))
- eq('Error executing lua: vim/shared.lua:0: sep: expected string, got number',
+ matches('sep: expected string, got number',
pcall_err(split, 'string', 1))
- eq('Error executing lua: vim/shared.lua:0: kwargs: expected table, got number',
+ matches('kwargs: expected table, got number',
pcall_err(split, 'string', 'string', 1))
end)
@@ -330,7 +330,7 @@ describe('lua stdlib', function()
end
-- Validates args.
- eq('Error executing lua: vim/shared.lua:0: s: expected string, got number',
+ matches('s: expected string, got number',
pcall_err(trim, 2))
end)
@@ -396,7 +396,21 @@ describe('lua stdlib', function()
return t1.f() ~= t2.f()
]]))
- eq('Error executing lua: vim/shared.lua:0: Cannot deepcopy object of type thread',
+ ok(exec_lua([[
+ local t1 = {a = 5}
+ t1.self = t1
+ local t2 = vim.deepcopy(t1)
+ return t2.self == t2 and t2.self ~= t1
+ ]]))
+
+ ok(exec_lua([[
+ local mt = {mt=true}
+ local t1 = setmetatable({a = 5}, mt)
+ local t2 = vim.deepcopy(t1)
+ return getmetatable(t2) == mt
+ ]]))
+
+ matches('Cannot deepcopy object of type thread',
pcall_err(exec_lua, [[
local thread = coroutine.create(function () return 0 end)
local t = {thr = thread}
@@ -409,7 +423,7 @@ describe('lua stdlib', function()
eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]]))
-- Validates args.
- eq('Error executing lua: vim/shared.lua:0: s: expected string, got number',
+ matches('s: expected string, got number',
pcall_err(exec_lua, [[return vim.pesc(2)]]))
end)
@@ -534,19 +548,19 @@ describe('lua stdlib', function()
return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1
]]))
- eq('Error executing lua: vim/shared.lua:0: invalid "behavior": nil',
+ matches('invalid "behavior": nil',
pcall_err(exec_lua, [[
return vim.tbl_extend()
]])
)
- eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 1, expected at least 3)',
+ matches('wrong number of arguments %(given 1, expected at least 3%)',
pcall_err(exec_lua, [[
return vim.tbl_extend("keep")
]])
)
- eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 2, expected at least 3)',
+ matches('wrong number of arguments %(given 2, expected at least 3%)',
pcall_err(exec_lua, [[
return vim.tbl_extend("keep", {})
]])
@@ -647,19 +661,19 @@ describe('lua stdlib', function()
return vim.tbl_deep_extend("force", a, b)
]]), {a = 123 })
- eq('Error executing lua: vim/shared.lua:0: invalid "behavior": nil',
+ matches('invalid "behavior": nil',
pcall_err(exec_lua, [[
return vim.tbl_deep_extend()
]])
)
- eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 1, expected at least 3)',
+ matches('wrong number of arguments %(given 1, expected at least 3%)',
pcall_err(exec_lua, [[
return vim.tbl_deep_extend("keep")
]])
)
- eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 2, expected at least 3)',
+ matches('wrong number of arguments %(given 2, expected at least 3%)',
pcall_err(exec_lua, [[
return vim.tbl_deep_extend("keep", {})
]])
@@ -692,7 +706,7 @@ describe('lua stdlib', function()
it('vim.list_extend', function()
eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]])
- eq('Error executing lua: vim/shared.lua:0: src: expected table, got nil',
+ matches('src: expected table, got nil',
pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]]))
eq({1,2}, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]])
eq(true, exec_lua [[ local a = {1} return vim.list_extend(a, {2;a=1}) == a ]])
@@ -716,7 +730,7 @@ describe('lua stdlib', function()
assert(vim.deep_equal(a, { A = 1; [1] = 'A'; }))
vim.tbl_add_reverse_lookup(a)
]]
- matches('^Error executing lua: vim/shared%.lua:0: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$',
+ matches('The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$',
pcall_err(exec_lua, code))
end)
@@ -757,7 +771,7 @@ describe('lua stdlib', function()
end)
it('vim.fn should error when calling API function', function()
- eq('Error executing lua: vim.lua:0: Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead',
+ matches('Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead',
pcall_err(exec_lua, "vim.fn.nvim_get_current_line()"))
end)
@@ -893,37 +907,37 @@ describe('lua stdlib', function()
exec_lua("vim.validate{arg1={{}, 't' }, arg2={ 'foo', 's' }}")
exec_lua("vim.validate{arg1={2, function(a) return (a % 2) == 0 end, 'even number' }}")
- eq('Error executing lua: [string "<nvim>"]:0: opt[1]: expected table, got number',
+ matches('expected table, got number',
pcall_err(exec_lua, "vim.validate{ 1, 'x' }"))
- eq('Error executing lua: [string "<nvim>"]:0: invalid type name: x',
+ matches('invalid type name: x',
pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}"))
- eq('Error executing lua: [string "<nvim>"]:0: invalid type name: 1',
+ matches('invalid type name: 1',
pcall_err(exec_lua, "vim.validate{ arg1={ 1, 1 }}"))
- eq('Error executing lua: [string "<nvim>"]:0: invalid type name: nil',
+ matches('invalid type name: nil',
pcall_err(exec_lua, "vim.validate{ arg1={ 1 }}"))
-- Validated parameters are required by default.
- eq('Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil',
+ matches('arg1: expected string, got nil',
pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}"))
-- Explicitly required.
- eq('Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil',
+ matches('arg1: expected string, got nil',
pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}"))
- eq('Error executing lua: [string "<nvim>"]:0: arg1: expected table, got number',
+ matches('arg1: expected table, got number',
pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}"))
- eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got number',
+ matches('arg2: expected string, got number',
pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}"))
- eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil',
+ matches('arg2: expected string, got nil',
pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
- eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil',
+ matches('arg2: expected string, got nil',
pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
- eq('Error executing lua: [string "<nvim>"]:0: arg1: expected even number, got 3',
+ matches('arg1: expected even number, got 3',
pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}"))
- eq('Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3',
+ matches('arg1: expected %?, got 3',
pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}"))
-- Pass an additional message back.
- eq('Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3. Info: TEST_MSG',
+ matches('arg1: expected %?, got 3. Info: TEST_MSG',
pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}"))
end)
@@ -968,7 +982,7 @@ describe('lua stdlib', function()
]]
eq(NIL, funcs.luaeval "vim.g.to_delete")
- matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ matches([[attempt to index .* nil value]],
pcall_err(exec_lua, 'return vim.g[0].testing'))
end)
@@ -995,7 +1009,7 @@ describe('lua stdlib', function()
return {vim.b.nonexistant == vim.NIL, vim.b.nullvar == vim.NIL}
]])
- matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ matches([[attempt to index .* nil value]],
pcall_err(exec_lua, 'return vim.b[BUF][0].testing'))
eq({hello="world"}, funcs.luaeval "vim.b.to_delete")
@@ -1032,7 +1046,7 @@ describe('lua stdlib', function()
eq(NIL, funcs.luaeval "vim.w.nonexistant")
eq(NIL, funcs.luaeval "vim.w[WIN].nonexistant")
- matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ matches([[attempt to index .* nil value]],
pcall_err(exec_lua, 'return vim.w[WIN][0].testing'))
eq({hello="world"}, funcs.luaeval "vim.w.to_delete")
@@ -1064,7 +1078,7 @@ describe('lua stdlib', function()
eq(123, funcs.luaeval "vim.t[0].other")
eq(NIL, funcs.luaeval "vim.t[0].nonexistant")
- matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ matches([[attempt to index .* nil value]],
pcall_err(exec_lua, 'return vim.t[0][0].testing'))
eq({hello="world"}, funcs.luaeval "vim.t.to_delete")
@@ -1094,7 +1108,7 @@ describe('lua stdlib', function()
eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval "vim.v.progpath")
eq(false, funcs.luaeval "vim.v['false']")
eq(NIL, funcs.luaeval "vim.v.null")
- matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ matches([[attempt to index .* nil value]],
pcall_err(exec_lua, 'return vim.v[0].progpath'))
end)
@@ -1114,9 +1128,9 @@ describe('lua stdlib', function()
]]
eq('', funcs.luaeval "vim.bo.filetype")
eq(true, funcs.luaeval "vim.bo[BUF].modifiable")
- matches("^Error executing lua: .*: Invalid option name: 'nosuchopt'$",
+ matches("Invalid option name: 'nosuchopt'$",
pcall_err(exec_lua, 'return vim.bo.nosuchopt'))
- matches("^Error executing lua: .*: Expected lua string$",
+ matches("Expected lua string$",
pcall_err(exec_lua, 'return vim.bo[0][0].autoread'))
end)
@@ -1133,9 +1147,9 @@ describe('lua stdlib', function()
eq(0, funcs.luaeval "vim.wo.cole")
eq(0, funcs.luaeval "vim.wo[0].cole")
eq(0, funcs.luaeval "vim.wo[1001].cole")
- matches("^Error executing lua: .*: Invalid option name: 'notanopt'$",
+ matches("Invalid option name: 'notanopt'$",
pcall_err(exec_lua, 'return vim.wo.notanopt'))
- matches("^Error executing lua: .*: Expected lua string$",
+ matches("Expected lua string$",
pcall_err(exec_lua, 'return vim.wo[0][0].list'))
eq(2, funcs.luaeval "vim.wo[1000].cole")
exec_lua [[
@@ -1226,7 +1240,7 @@ describe('lua stdlib', function()
vim.opt.makeprg = "global-local"
table.insert(result, vim.api.nvim_get_option('makeprg'))
- table.insert(result, (pcall(vim.api.nvim_buf_get_option, 0, 'makeprg')))
+ table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg'))
vim.opt_local.mp = "only-local"
table.insert(result, vim.api.nvim_get_option('makeprg'))
@@ -1244,7 +1258,7 @@ describe('lua stdlib', function()
-- Set -> global & local
eq("global-local", result[1])
- eq(false, result[2])
+ eq("", result[2])
-- Setlocal -> only local
eq("global-local", result[3])
@@ -1254,9 +1268,9 @@ describe('lua stdlib', function()
eq("only-global", result[5])
eq("only-local", result[6])
- -- set -> doesn't override previously set value
+ -- Set -> sets global value and resets local value
eq("global-local", result[7])
- eq("only-local", result[8])
+ eq("", result[8])
end)
it('should allow you to retrieve window opts even if they have not been set', function()