Fix access on vim.wo (#11517)

* Add more tests for vim.wo
This commit is contained in:
Ashkan Kiani
2019-12-07 03:34:02 -08:00
committed by GitHub
parent fbae9f8541
commit 0e6c6261e1
2 changed files with 11 additions and 6 deletions

View File

@@ -374,9 +374,9 @@ do
if winnr == nil and type(k) == "number" then if winnr == nil and type(k) == "number" then
return new_win_opt_accessor(k) return new_win_opt_accessor(k)
end end
return a.nvim_win_get_option(winnr or nil, k) return a.nvim_win_get_option(winnr or 0, k)
end end
local function set(k, v) return a.nvim_win_set_option(winnr or nil, k, v) end local function set(k, v) return a.nvim_win_set_option(winnr or 0, k, v) end
return make_meta_accessor(get, set) return make_meta_accessor(get, set)
end end
vim.wo = new_win_opt_accessor(nil) vim.wo = new_win_opt_accessor(nil)

View File

@@ -629,22 +629,27 @@ describe('lua stdlib', function()
end) end)
it('vim.wo', function() it('vim.wo', function()
eq('', funcs.luaeval "vim.bo.filetype")
exec_lua [[ exec_lua [[
vim.api.nvim_win_set_option(0, "cole", 2) vim.api.nvim_win_set_option(0, "cole", 2)
BUF = vim.api.nvim_create_buf(false, true) vim.cmd "split"
vim.api.nvim_buf_set_option(BUF, "modifiable", false) vim.api.nvim_win_set_option(0, "cole", 2)
]] ]]
eq(2, funcs.luaeval "vim.wo.cole") eq(2, funcs.luaeval "vim.wo.cole")
exec_lua [[ exec_lua [[
vim.wo.conceallevel = 0 vim.wo.conceallevel = 0
vim.bo[BUF].modifiable = true
]] ]]
eq(0, funcs.luaeval "vim.wo.cole") 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("^Error executing lua: .*: Invalid option name: 'notanopt'$",
pcall_err(exec_lua, 'return vim.wo.notanopt')) pcall_err(exec_lua, 'return vim.wo.notanopt'))
matches("^Error executing lua: .*: Expected lua string$", matches("^Error executing lua: .*: Expected lua string$",
pcall_err(exec_lua, 'return vim.wo[0][0].list')) pcall_err(exec_lua, 'return vim.wo[0][0].list'))
eq(2, funcs.luaeval "vim.wo[1000].cole")
exec_lua [[
vim.wo[1000].cole = 0
]]
eq(0, funcs.luaeval "vim.wo[1000].cole")
end) end)
it('vim.cmd', function() it('vim.cmd', function()