aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorDavid Zhang <crispgm@gmail.com>2021-05-30 20:49:19 +0800
committerTJ DeVries <devries.timothyj@gmail.com>2021-06-29 08:42:07 -0400
commitb02e64c4dffd9044ea83e3f2d74b5f6db6bf6b99 (patch)
tree9b920cc72dc83001e68a702410acb72005209eb2 /test/functional/lua/vim_spec.lua
parente6175f6389ea3fdc685fe2158948d49caa8cdba2 (diff)
downloadrneovim-b02e64c4dffd9044ea83e3f2d74b5f6db6bf6b99.tar.gz
rneovim-b02e64c4dffd9044ea83e3f2d74b5f6db6bf6b99.tar.bz2
rneovim-b02e64c4dffd9044ea83e3f2d74b5f6db6bf6b99.zip
fix(vim.opt): Add basic error handling
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua122
1 files changed, 122 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 890f6427bb..e3d19008cc 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -1592,6 +1592,128 @@ describe('lua stdlib', function()
eq(wildmode, 'full,list,full')
end)
+
+ describe('option types', function()
+ it('should allow to set option with numeric value', function()
+ eq(4, exec_lua [[
+ vim.opt.tabstop = 4
+ return vim.bo.tabstop
+ ]])
+
+ matches("Invalid option type 'string' for 'tabstop'", pcall_err(exec_lua, [[
+ vim.opt.tabstop = '4'
+ ]]))
+ matches("Invalid option type 'boolean' for 'tabstop'", pcall_err(exec_lua, [[
+ vim.opt.tabstop = true
+ ]]))
+ matches("Invalid option type 'table' for 'tabstop'", pcall_err(exec_lua, [[
+ vim.opt.tabstop = {4, 2}
+ ]]))
+ matches("Invalid option type 'function' for 'tabstop'", pcall_err(exec_lua, [[
+ vim.opt.tabstop = function()
+ return 4
+ end
+ ]]))
+ end)
+
+ it('should allow to set option with boolean value', function()
+ eq(true, exec_lua [[
+ vim.opt.undofile = true
+ return vim.bo.undofile
+ ]])
+
+ matches("Invalid option type 'number' for 'undofile'", pcall_err(exec_lua, [[
+ vim.opt.undofile = 0
+ ]]))
+ matches("Invalid option type 'table' for 'undofile'", pcall_err(exec_lua, [[
+ vim.opt.undofile = {true}
+ ]]))
+ matches("Invalid option type 'string' for 'undofile'", pcall_err(exec_lua, [[
+ vim.opt.undofile = 'true'
+ ]]))
+ matches("Invalid option type 'function' for 'undofile'", pcall_err(exec_lua, [[
+ vim.opt.undofile = function()
+ return true
+ end
+ ]]))
+ end)
+
+ it('should allow to set option with array or string value', function()
+ eq('indent,eol,start', exec_lua [[
+ vim.opt.backspace = {'indent','eol','start'}
+ return vim.go.backspace
+ ]])
+ eq('indent,eol,start', exec_lua [[
+ vim.opt.backspace = 'indent,eol,start'
+ return vim.go.backspace
+ ]])
+
+ matches("Invalid option type 'boolean' for 'backspace'", pcall_err(exec_lua, [[
+ vim.opt.backspace = true
+ ]]))
+ matches("Invalid option type 'number' for 'backspace'", pcall_err(exec_lua, [[
+ vim.opt.backspace = 2
+ ]]))
+ matches("Invalid option type 'function' for 'backspace'", pcall_err(exec_lua, [[
+ vim.opt.backspace = function()
+ return 'indent,eol,start'
+ end
+ ]]))
+ end)
+
+ it('should allow set option with map or string value', function()
+ eq("eol:~,space:.", exec_lua [[
+ vim.opt.listchars = {
+ eol = "~",
+ space = ".",
+ }
+ return vim.o.listchars
+ ]])
+ eq("eol:~,space:.,tab:>~", exec_lua [[
+ vim.opt.listchars = "eol:~,space:.,tab:>~"
+ return vim.o.listchars
+ ]])
+
+ matches("Invalid option type 'boolean' for 'listchars'", pcall_err(exec_lua, [[
+ vim.opt.listchars = true
+ ]]))
+ matches("Invalid option type 'number' for 'listchars'", pcall_err(exec_lua, [[
+ vim.opt.listchars = 2
+ ]]))
+ matches("Invalid option type 'function' for 'listchars'", pcall_err(exec_lua, [[
+ vim.opt.listchars = function()
+ return "eol:~,space:.,tab:>~"
+ end
+ ]]))
+ end)
+
+ it('should allow set option with set or string value', function()
+ local ww = exec_lua [[
+ vim.opt.whichwrap = {
+ b = true,
+ s = 1,
+ }
+ return vim.go.whichwrap
+ ]]
+ eq(true, ww == "bs" or ww == "sb")
+ eq("b,s,<,>,[,]", exec_lua [[
+ vim.opt.whichwrap = "b,s,<,>,[,]"
+ return vim.go.whichwrap
+ ]])
+
+ matches("Invalid option type 'boolean' for 'whichwrap'", pcall_err(exec_lua, [[
+ vim.opt.whichwrap = true
+ ]]))
+ matches("Invalid option type 'number' for 'whichwrap'", pcall_err(exec_lua, [[
+ vim.opt.whichwrap = 2
+ ]]))
+ matches("Invalid option type 'function' for 'whichwrap'", pcall_err(exec_lua, [[
+ vim.opt.whichwrap = function()
+ return "b,s,<,>,[,]"
+ end
+ ]]))
+ end)
+ end)
end) -- vim.opt
it('vim.cmd', function()