diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:40:31 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:40:31 +0000 |
commit | 339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch) | |
tree | a6167fc8fcfc6ae2dc102f57b2473858eac34063 /test/functional/vimscript/api_functions_spec.lua | |
parent | 067dc73729267c0262438a6fdd66e586f8496946 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2 rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip |
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'test/functional/vimscript/api_functions_spec.lua')
-rw-r--r-- | test/functional/vimscript/api_functions_spec.lua | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index c032ac3030..0a7e7c1137 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -1,12 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local lfs = require('lfs') +local luv = require('luv') local neq, eq, command = helpers.neq, helpers.eq, helpers.command local clear, curbufmeths = helpers.clear, helpers.curbufmeths 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) @@ -32,8 +33,8 @@ describe('eval-API', function() local err = exc_exec('call nvim_get_current_buf("foo")') eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err) - err = exc_exec('call nvim_set_option("hlsearch")') - eq('Vim(call):E119: Not enough arguments for function: nvim_set_option', err) + err = exc_exec('call nvim_set_option_value("hlsearch")') + eq('Vim(call):E119: Not enough arguments for function: nvim_set_option_value', err) err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])') eq('Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', err) @@ -48,10 +49,47 @@ 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. + local old_win = meths.get_current_win() + feed("q:") + eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', + pcall_err(meths.set_current_win, old_win)) + + -- 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() @@ -118,7 +156,7 @@ describe('eval-API', function() end) it('are highlighted by vim.vim syntax file', function() - if lfs.attributes("build/runtime/syntax/vim/generated.vim",'uid') == nil then + if luv.fs_stat("build/runtime/syntax/vim/generated.vim").uid == nil then pending("runtime was not built, skipping test") return end @@ -133,7 +171,7 @@ describe('eval-API', function() }) command("set ft=vim") - command("let &rtp='build/runtime/,'.&rtp") + command("set rtp^=build/runtime/") command("syntax on") insert([[ call bufnr('%') |