diff options
author | William Boman <william@redwill.se> | 2022-12-15 02:27:23 +0100 |
---|---|---|
committer | William Boman <william@redwill.se> | 2022-12-15 02:43:43 +0100 |
commit | 26c918d03f5b38df900316c0601065ec1ea96264 (patch) | |
tree | 0464a2b496b72523b2f6487374ef0d09b57a8fd9 /test/functional/lua/vim_spec.lua | |
parent | 0887ad1cbb050d2bc6169ad46aa07cf42c90493f (diff) | |
download | rneovim-26c918d03f5b38df900316c0601065ec1ea96264.tar.gz rneovim-26c918d03f5b38df900316c0601065ec1ea96264.tar.bz2 rneovim-26c918d03f5b38df900316c0601065ec1ea96264.zip |
fix(lua): always return nil values in vim.tbl_get when no results
While `return` and `return nil` are for most intents and purposes
identical, there are situations where they're not. For example,
calculating the amount of values via the `select()` function will yield
varying results:
```lua
local function nothing() return end
local function null() return nil end
select('#', nothing()) -- 0
select('#', null()) -- 1
```
`vim.tbl_get` currently returns both nil and no results, which makes it
unreliable to use in certain situations without manually accounting for
these discrepancies.
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r-- | test/functional/lua/vim_spec.lua | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e390619a5a..90eccc49c8 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -512,6 +512,8 @@ describe('lua stdlib', function() eq(NIL, exec_lua("return vim.tbl_get({ unindexable = function () end }, 'unindexable', 'missing_key')")) eq(NIL, exec_lua("return vim.tbl_get({}, 'missing_key')")) eq(NIL, exec_lua("return vim.tbl_get({})")) + eq(1, exec_lua("return select('#', vim.tbl_get({}))")) + eq(1, exec_lua("return select('#', vim.tbl_get({ nested = {} }, 'nested', 'missing_key'))")) end) it('vim.tbl_extend', function() |