diff options
author | Evgeni Chasnovski <evgeni.chasnovski@gmail.com> | 2024-06-21 16:23:02 +0300 |
---|---|---|
committer | Evgeni Chasnovski <evgeni.chasnovski@gmail.com> | 2024-06-24 20:23:11 +0300 |
commit | f8795365deb88ab4e108858c563284b1082d06d4 (patch) | |
tree | e84418252f17b60412e265b139e68ab99b1b1dd7 /runtime/lua/vim/shared.lua | |
parent | 5581a95534e44b8714e715c925c9de2d95ae1c21 (diff) | |
download | rneovim-f8795365deb88ab4e108858c563284b1082d06d4.tar.gz rneovim-f8795365deb88ab4e108858c563284b1082d06d4.tar.bz2 rneovim-f8795365deb88ab4e108858c563284b1082d06d4.zip |
test(lua): cover `vim._with()` with tests
Problem: `vim._with()` has many different use cases which are not
covered with tests.
Solution: cover with tests. Some (many) test cases are intentionally
marked as "pending" because they cover cases which don't work as
expected at the moment (and fixing them requires specific knowledge of
C codebase). Use them as a reference for future fixes.
Also some of "can be nested" tests currently might pass only because
the tested context doesn't work.
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 7fd29d5f7b..79e614aaaa 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -1144,7 +1144,6 @@ end --- @field buf? integer --- @field emsg_silent? boolean --- @field hide? boolean ---- @field horizontal? boolean --- @field keepalt? boolean --- @field keepjumps? boolean --- @field keepmarks? boolean @@ -1159,6 +1158,15 @@ end --- Executes function `f` with the given context specification. --- +--- Notes: +--- - Context `{ buf = buf }` has no guarantees about current window when +--- inside context. +--- - Context `{ buf = buf, win = win }` is yet not allowed, but this seems +--- to be an implementation detail. +--- - There should be no way to revert currently set `context.sandbox = true` +--- (like with nested `vim._with()` calls). Otherwise it kind of breaks the +--- whole purpose of sandbox execution. +--- --- @param context vim.context.mods function vim._with(context, f) vim.validate('context', context, 'table') @@ -1167,7 +1175,6 @@ function vim._with(context, f) vim.validate('context.buf', context.buf, 'number', true) vim.validate('context.emsg_silent', context.emsg_silent, 'boolean', true) vim.validate('context.hide', context.hide, 'boolean', true) - vim.validate('context.horizontal', context.horizontal, 'boolean', true) vim.validate('context.keepalt', context.keepalt, 'boolean', true) vim.validate('context.keepjumps', context.keepjumps, 'boolean', true) vim.validate('context.keepmarks', context.keepmarks, 'boolean', true) @@ -1192,6 +1199,10 @@ function vim._with(context, f) if not vim.api.nvim_win_is_valid(context.win) then error('Invalid window id: ' .. context.win) end + -- TODO: Maybe allow it? + if context.buf and vim.api.nvim_win_get_buf(context.win) ~= context.buf then + error('Can not set both `buf` and `win` context.') + end end -- Store original options @@ -1214,7 +1225,7 @@ function vim._with(context, f) end end - return unpack(retval) + return unpack(retval, 1, table.maxn(retval)) end return vim |