aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-07-05 17:04:17 +0800
committerGitHub <noreply@github.com>2023-07-05 17:04:17 +0800
commit8a788e2daa5c62201f2bb278522eddd42f315d41 (patch)
treee92a4873cffa28ae5f62683191c93ac08538815f /test/functional
parentdf297e3c2bd743616371db73467a3f08d2b96d9b (diff)
parentaa4e47f704c53ab1d825260d2bf34e2872e3ca89 (diff)
downloadrneovim-8a788e2daa5c62201f2bb278522eddd42f315d41.tar.gz
rneovim-8a788e2daa5c62201f2bb278522eddd42f315d41.tar.bz2
rneovim-8a788e2daa5c62201f2bb278522eddd42f315d41.zip
Merge pull request #23228 from seandewar/cmdwin-jail
fix(api): use `text_locked()` to check for textlock
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/terminal/buffer_spec.lua14
-rw-r--r--test/functional/vimscript/api_functions_spec.lua39
2 files changed, 52 insertions, 1 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 4ce354b9a9..bd898ba99e 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -498,3 +498,17 @@ if is_os('win') then
end)
end)
end
+
+describe('termopen()', function()
+ before_each(clear)
+
+ it('disallowed when textlocked and in cmdwin buffer', function()
+ command("autocmd TextYankPost <buffer> ++once call termopen('foo')")
+ matches("Vim%(call%):E565: Not allowed to change text or change window$",
+ pcall_err(command, "normal! yy"))
+
+ feed("q:")
+ eq("Vim:E11: Invalid in command-line window; <CR> executes, CTRL-C quits",
+ pcall_err(funcs.termopen, "bar"))
+ end)
+end)
diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua
index 14678a966d..6548548a9e 100644
--- a/test/functional/vimscript/api_functions_spec.lua
+++ b/test/functional/vimscript/api_functions_spec.lua
@@ -7,6 +7,7 @@ local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval
local insert, pcall_err = helpers.insert, helpers.pcall_err
local matches = helpers.matches
local meths = helpers.meths
+local feed = helpers.feed
describe('eval-API', function()
before_each(clear)
@@ -48,10 +49,46 @@ describe('eval-API', function()
eq('Vim(call):E5555: API call: Invalid buffer id: 17', err)
end)
- it('cannot change texts if textlocked', function()
+ it('cannot change text or window if textlocked', function()
command("autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])")
matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$',
pcall_err(command, "normal! yy"))
+
+ command("autocmd TextYankPost <buffer> ++once call nvim_open_term(0, {})")
+ matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$',
+ pcall_err(command, "normal! yy"))
+
+ -- Functions checking textlock should also not be usable from <expr> mappings.
+ command("inoremap <expr> <f2> nvim_win_close(0, 1)")
+ eq('Vim(normal):E5555: API call: E565: Not allowed to change text or change window',
+ pcall_err(command, [[execute "normal i\<f2>"]]))
+
+ -- Text-changing functions gave a "Failed to save undo information" error when called from an
+ -- <expr> mapping outside do_cmdline() (msg_list == NULL), so use feed() to test this.
+ command("inoremap <expr> <f2> nvim_buf_set_text(0, 0, 0, 0, 0, ['hi'])")
+ meths.set_vvar('errmsg', '')
+ feed("i<f2><esc>")
+ eq('E5555: API call: E565: Not allowed to change text or change window',
+ meths.get_vvar('errmsg'))
+
+ -- Some functions checking textlock (usually those that may change the current window or buffer)
+ -- also ought to not be usable in the cmdwin.
+ feed("q:")
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.win_hide, 0))
+
+ -- But others, like nvim_buf_set_lines(), which just changes text, is OK.
+ curbufmeths.set_lines(0, -1, 1, {"wow!"})
+ eq({'wow!'}, curbufmeths.get_lines(0, -1, 1))
+
+ -- Turning the cmdwin buffer into a terminal buffer would be pretty weird.
+ eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
+ pcall_err(meths.open_term, 0, {}))
+
+ -- But turning a different buffer into a terminal from the cmdwin is OK.
+ local term_buf = meths.create_buf(false, true)
+ meths.open_term(term_buf, {})
+ eq('terminal', meths.get_option_value("buftype", {buf = term_buf}))
end)
it("use buffer numbers and windows ids as handles", function()