aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-04-07 08:22:47 -0600
committerGitHub <noreply@github.com>2023-04-07 08:22:47 -0600
commitd675bd01b1e78b93e559320b262bdae40b3b54b2 (patch)
tree2ede624b4ad283bcadebbd26382d7521d6114937 /test/functional/lua/vim_spec.lua
parent82cfedab5009c0f5003451ef0b105a019887edb3 (diff)
downloadrneovim-d675bd01b1e78b93e559320b262bdae40b3b54b2.tar.gz
rneovim-d675bd01b1e78b93e559320b262bdae40b3b54b2.tar.bz2
rneovim-d675bd01b1e78b93e559320b262bdae40b3b54b2.zip
feat(lua): allow vim.F.if_nil to take multiple arguments (#22903)
The first argument which is non-nil is returned. This is useful when using nested default values (e.g. in the EditorConfig plugin). Before: local enable = vim.F.if_nil(vim.b.editorconfig, vim.F.if_nil(vim.g.editorconfig, true)) After: local enable = vim.F.if_nil(vim.b.editorconfig, vim.g.editorconfig, true)
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 9508469a61..45d9263c0c 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -2967,6 +2967,32 @@ describe('lua stdlib', function()
}]],
eval[[execute('lua vim.print(42, "abc", { a = { b = 77 }})')]])
end)
+
+ it('vim.F.if_nil', function()
+ local function if_nil(...)
+ return exec_lua([[
+ local args = {...}
+ local nargs = select('#', ...)
+ for i = 1, nargs do
+ if args[i] == vim.NIL then
+ args[i] = nil
+ end
+ end
+ return vim.F.if_nil(unpack(args, 1, nargs))
+ ]], ...)
+ end
+
+ local a = NIL
+ local b = NIL
+ local c = 42
+ local d = false
+ eq(42, if_nil(a, c))
+ eq(false, if_nil(d, b))
+ eq(42, if_nil(a, b, c, d))
+ eq(false, if_nil(d))
+ eq(false, if_nil(d, c))
+ eq(NIL, if_nil(a))
+ end)
end)
describe('lua: builtin modules', function()