From 1d3ee1c44186c211611abd03bdb4e38004b14ff4 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 11 Jun 2021 11:13:43 -0400 Subject: fix(vim.opt): #14708 Now lets you put duplicate values in wildmode --- test/functional/lua/vim_spec.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test/functional/lua/vim_spec.lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 836f514433..51a0b58172 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1569,7 +1569,15 @@ describe('lua stdlib', function() eq(wildignore, 'super_first,first,foo') end) - end) + it('should not remove duplicates from wildmode: #14708', function() + local wildmode = exec_lua [[ + vim.opt.wildmode = {"full", "list", "full"} + return vim.o.wildmode + ]] + + eq(wildmode, 'full,list,full') + end) + end) -- vim.opt it('vim.cmd', function() exec_lua [[ -- cgit From e6175f6389ea3fdc685fe2158948d49caa8cdba2 Mon Sep 17 00:00:00 2001 From: ckipp01 Date: Sun, 30 May 2021 13:08:43 +0200 Subject: fix(vim.opt): Get window options before setting. This closes #14677, but I also am a little unsure if there are times where this may not be correct. However, this just changes the behavior that even if `was_set` was false, we still get for `nvim_win_get_option`. --- test/functional/lua/vim_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/lua/vim_spec.lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 51a0b58172..890f6427bb 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1228,6 +1228,21 @@ describe('lua stdlib', function() eq("only-local", result[8]) end) + it('should allow you to retrieve window opts even if they have not been set', function() + local result = exec_lua [[ + local result = {} + table.insert(result, vim.opt.number:get()) + table.insert(result, vim.opt_local.number:get()) + + vim.opt_local.number = true + table.insert(result, vim.opt.number:get()) + table.insert(result, vim.opt_local.number:get()) + + return result + ]] + eq({false, false, true, true}, result) + end) + it('should allow all sorts of string manipulation', function() eq({'hello', 'hello world', 'start hello world'}, exec_lua [[ local results = {} -- cgit From b02e64c4dffd9044ea83e3f2d74b5f6db6bf6b99 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Sun, 30 May 2021 20:49:19 +0800 Subject: fix(vim.opt): Add basic error handling --- test/functional/lua/vim_spec.lua | 122 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) (limited to 'test/functional/lua/vim_spec.lua') 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() -- cgit From 9119ea1becd5024ad14db04e2868feeae7c7d4de Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 11 Jun 2021 12:28:15 -0400 Subject: fix(vim.opt): Fix #14669 whichwrap now acts as expected --- test/functional/lua/vim_spec.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'test/functional/lua/vim_spec.lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e3d19008cc..cb94004872 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1314,6 +1314,22 @@ describe('lua stdlib', function() eq("*.c", wildignore[1]) end) + it('should work for options that are both commalist and flaglist', function() + local result = exec_lua [[ + vim.opt.whichwrap = "b,s" + return vim.opt.whichwrap:get() + ]] + + eq({b = true, s = true}, result) + + result = exec_lua [[ + vim.opt.whichwrap = { b = true, s = false, h = true } + return vim.opt.whichwrap:get() + ]] + + eq({b = true, h = true}, result) + end) + it('should work for key-value pair options', function() local listchars = exec_lua [[ vim.opt.listchars = "tab:>~,space:_" @@ -1695,7 +1711,8 @@ describe('lua stdlib', function() } return vim.go.whichwrap ]] - eq(true, ww == "bs" or ww == "sb") + + eq(ww, "b,s") eq("b,s,<,>,[,]", exec_lua [[ vim.opt.whichwrap = "b,s,<,>,[,]" return vim.go.whichwrap -- cgit From 6ecec87c099ce6182b4a1cc81846be9e0e70c1cd Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 11 Jun 2021 13:39:59 -0400 Subject: fix(vim.opt): Fix #14668 Now correctly handles unescaped commas in isfname style --- test/functional/lua/vim_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional/lua/vim_spec.lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index cb94004872..ad0bb50c6e 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1731,6 +1731,26 @@ describe('lua stdlib', function() ]])) end) end) + + -- isfname=a,b,c,,,d,e,f + it('can handle isfname ,,,', function() + local result = exec_lua [[ + vim.opt.isfname = "a,b,,,c" + return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') } + ]] + + eq({{",", "a", "b", "c"}, "a,b,,,c"}, result) + end) + + -- isfname=a,b,c,^,,def + it('can handle isfname ,^,,', function() + local result = exec_lua [[ + vim.opt.isfname = "a,b,^,,c" + return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') } + ]] + + eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result) + end) end) -- vim.opt it('vim.cmd', function() -- cgit From 19b7cef0a7dc52f3ec016e0dd0ae82f0f6ecd4b1 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 29 Jun 2021 09:18:59 -0400 Subject: fix(vim.opt): Fix #14828 with empty values being incorrectly inserted --- test/functional/lua/vim_spec.lua | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'test/functional/lua/vim_spec.lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index ad0bb50c6e..eff838aea3 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1751,6 +1751,70 @@ describe('lua stdlib', function() eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result) end) + + + + describe('https://github.com/neovim/neovim/issues/14828', function() + it('gives empty list when item is empty:array', function() + eq({}, exec_lua [[ + vim.cmd("set wildignore=") + return vim.opt.wildignore:get() + ]]) + + eq({}, exec_lua [[ + vim.opt.wildignore = {} + return vim.opt.wildignore:get() + ]]) + end) + + it('gives empty list when item is empty:set', function() + eq({}, exec_lua [[ + vim.cmd("set formatoptions=") + return vim.opt.formatoptions:get() + ]]) + + eq({}, exec_lua [[ + vim.opt.formatoptions = {} + return vim.opt.formatoptions:get() + ]]) + end) + + it('does not append to empty item', function() + eq({"*.foo", "*.bar"}, exec_lua [[ + vim.opt.wildignore = {} + vim.opt.wildignore:append { "*.foo", "*.bar" } + + return vim.opt.wildignore:get() + ]]) + end) + + it('does not prepend to empty item', function() + eq({"*.foo", "*.bar"}, exec_lua [[ + vim.opt.wildignore = {} + vim.opt.wildignore:prepend { "*.foo", "*.bar" } + + return vim.opt.wildignore:get() + ]]) + end) + + it('append to empty set', function() + eq({ t = true }, exec_lua [[ + vim.opt.formatoptions = {} + vim.opt.formatoptions:append("t") + + return vim.opt.formatoptions:get() + ]]) + end) + + it('prepend to empty set', function() + eq({ t = true }, exec_lua [[ + vim.opt.formatoptions = {} + vim.opt.formatoptions:prepend("t") + + return vim.opt.formatoptions:get() + ]]) + end) + end) end) -- vim.opt it('vim.cmd', function() -- cgit