From facd07bcf76b3c0b41eb046fce6b9d5bad62b89e Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Sat, 15 Jan 2022 08:37:44 -0800 Subject: Address review r3 --- test/functional/api/extmark_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index a8f538b951..e147e54bf5 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -110,6 +110,22 @@ describe('API/extmarks', function() pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })) end) + it("can end extranges past final newline when strict mode is false", function() + set_extmark(ns, marks[1], 0, 0, { + end_col = 1, + end_row = 1, + strict = false + }) + end) + + it("can end extranges past final column when strict mode is false", function() + set_extmark(ns, marks[1], 0, 0, { + end_col = 1, + end_row = 6, + strict = false + }) + end) + it('adds, updates and deletes marks', function() local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2]) eq(marks[1], rv) -- cgit From d8eec8e344120377f6e1a60dd74ac1f33ff34270 Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Sat, 15 Jan 2022 09:00:01 -0800 Subject: Hopefully last attempt --- test/functional/api/extmark_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index e147e54bf5..c027cfb5eb 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -114,15 +114,15 @@ describe('API/extmarks', function() set_extmark(ns, marks[1], 0, 0, { end_col = 1, end_row = 1, - strict = false + strict = false, }) end) it("can end extranges past final column when strict mode is false", function() set_extmark(ns, marks[1], 0, 0, { - end_col = 1, - end_row = 6, - strict = false + end_col = 6, + end_row = 0, + strict = false, }) end) -- cgit From be15ac06badbea6b11390ad7d9c2ddd4aea73480 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Jan 2022 18:44:28 +0800 Subject: feat(statusline): support multibyte fillchar This includes a partial port of Vim patch 8.2.2569 and some changes to nvim_eval_statusline() to allow a multibyte fillchar. Literally every line of C code touched by that patch has been refactored in Nvim, and that patch contains some irrelevant foldcolumn tests I'm not sure how to port (as Nvim's foldcolumn behavior has diverged from Vim's). --- test/functional/api/vim_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 22201e21a2..886915dfb4 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2551,6 +2551,34 @@ describe('API', function() 'Should be truncated%<', { maxwidth = 15 })) end) + it('supports ASCII fillchar', function() + eq({ str = 'a~~~b', width = 5 }, + meths.eval_statusline('a%=b', { fillchar = '~', maxwidth = 5 })) + end) + it('supports single-width multibyte fillchar', function() + eq({ str = 'a━━━b', width = 5 }, + meths.eval_statusline('a%=b', { fillchar = '━', maxwidth = 5 })) + end) + it('rejects double-width fillchar', function() + eq('fillchar must be a single-width character', + pcall_err(meths.eval_statusline, '', { fillchar = '哦' })) + end) + it('rejects control character fillchar', function() + eq('fillchar must be a single-width character', + pcall_err(meths.eval_statusline, '', { fillchar = '\a' })) + end) + it('rejects multiple-character fillchar', function() + eq('fillchar must be a single-width character', + pcall_err(meths.eval_statusline, '', { fillchar = 'aa' })) + end) + it('rejects empty string fillchar', function() + eq('fillchar must be a single-width character', + pcall_err(meths.eval_statusline, '', { fillchar = '' })) + end) + it('rejects non-string fillchar', function() + eq('fillchar must be a single-width character', + pcall_err(meths.eval_statusline, '', { fillchar = 1 })) + end) describe('highlight parsing', function() it('works', function() eq({ -- cgit From 5971b863383160d9bf744a9789c1fe5ca62b55a4 Mon Sep 17 00:00:00 2001 From: notomo Date: Thu, 13 Jan 2022 23:26:57 +0900 Subject: feat(api): expose extmark more details --- test/functional/api/extmark_spec.lua | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index c027cfb5eb..3f79515949 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1448,6 +1448,49 @@ describe('API/extmarks', function() }) eq({ {1, 0, 0, { end_col = 0, end_row = 1 }} }, get_extmarks(ns, 0, -1, {details=true})) end) + + it('can get details', function() + set_extmark(ns, marks[1], 0, 0, { + end_col = 0, + end_row = 1, + priority = 0, + hl_eol = true, + hl_mode = "blend", + hl_group = "String", + virt_text = { { "text", "Statement" } }, + virt_text_pos = "right_align", + virt_text_hide = true, + virt_lines = { { { "lines", "Statement" } }}, + virt_lines_above = true, + virt_lines_leftcol = true, + }) + set_extmark(ns, marks[2], 0, 0, { + priority = 0, + virt_text = { { "text", "Statement" } }, + virt_text_win_col = 1, + }) + eq({0, 0, { + end_col = 0, + end_row = 1, + priority = 0, + hl_eol = true, + hl_mode = "blend", + hl_group = "String", + virt_text = { { "text", "Statement" } }, + virt_text_pos = "right_align", + virt_text_hide = true, + virt_lines = { { { "lines", "Statement" } }}, + virt_lines_above = true, + virt_lines_leftcol = true, + } }, get_extmark_by_id(ns, marks[1], { details = true })) + eq({0, 0, { + priority = 0, + virt_text = { { "text", "Statement" } }, + virt_text_hide = false, + virt_text_pos = "win_col", + virt_text_win_col = 1, + } }, get_extmark_by_id(ns, marks[2], { details = true })) + end) end) describe('Extmarks buffer api with many marks', function() -- cgit From 6e69a3c3e79fd78b31753343213e68e73b0048c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 21 Jan 2022 18:08:56 +0800 Subject: refactor: remove CSI unescaping and clean up related names and comments --- test/functional/api/vim_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 22201e21a2..201ba45803 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1367,18 +1367,18 @@ describe('API', function() end) describe('nvim_feedkeys', function() - it('CSI escaping', function() + it('K_SPECIAL escaping', function() local function on_setup() -- notice the special char(…) \xe2\80\xa6 nvim('feedkeys', ':let x1="…"\n', '', true) -- Both nvim_replace_termcodes and nvim_feedkeys escape \x80 local inp = helpers.nvim('replace_termcodes', ':let x2="…"', true, true, true) - nvim('feedkeys', inp, '', true) -- escape_csi=true + nvim('feedkeys', inp, '', true) -- escape_ks=true - -- nvim_feedkeys with CSI escaping disabled + -- nvim_feedkeys with K_SPECIAL escaping disabled inp = helpers.nvim('replace_termcodes', ':let x3="…"', true, true, true) - nvim('feedkeys', inp, '', false) -- escape_csi=false + nvim('feedkeys', inp, '', false) -- escape_ks=false helpers.stop() end -- cgit From 8e84d1b93043f33d997627f99a181159aa66434d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 21 Jan 2022 18:18:18 +0800 Subject: vim-patch:8.2.3584: "verbose set efm" reports location of the :compiler command Problem: "verbose set efm" reports the location of the :compiler command. (Gary Johnson) Solution: Add the "-keepscript" argument to :command and use it when defining CompilerSet. https://github.com/vim/vim/commit/58ef8a31d7087d495ab1582be5b7a22796ac2451 --- test/functional/api/command_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 6c2c136edc..d64d324a88 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -16,8 +16,8 @@ local feed = helpers.feed local funcs = helpers.funcs describe('nvim_get_commands', function() - local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', range=NIL, register=false, script_id=0, } - local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', range=NIL, register=false, script_id=0, } + local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', range=NIL, register=false, keepscript=false, script_id=0, } + local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', range=NIL, register=false, keepscript=false, script_id=0, } before_each(clear) it('gets empty list if no commands were defined', function() @@ -59,11 +59,11 @@ describe('nvim_get_commands', function() end) it('gets various command attributes', function() - local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd ', name='TestCmd', nargs='1', range='10', register=false, script_id=0, } - local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger ', name='Finger', nargs='+', range=NIL, register=false, script_id=1, } - local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R2_foo()', name='Cmd2', nargs='*', range=NIL, register=false, script_id=2, } - local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R3_ohyeah()', name='Cmd3', nargs='0', range=NIL, register=false, script_id=3, } - local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R4_just_great()', name='Cmd4', nargs='0', range=NIL, register=true, script_id=4, } + local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd ', name='TestCmd', nargs='1', range='10', register=false, keepscript=false, script_id=0, } + local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger ', name='Finger', nargs='+', range=NIL, register=false, keepscript=false, script_id=1, } + local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R2_foo()', name='Cmd2', nargs='*', range=NIL, register=false, keepscript=false, script_id=2, } + local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R3_ohyeah()', name='Cmd3', nargs='0', range=NIL, register=false, keepscript=false, script_id=3, } + local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R4_just_great()', name='Cmd4', nargs='0', range=NIL, register=true, keepscript=false, script_id=4, } source([[ command -complete=custom,ListUsers -nargs=+ Finger !finger ]]) -- cgit From 3d9ae9d2dad88a4e2c2263dc7e256657842244c0 Mon Sep 17 00:00:00 2001 From: notomo Date: Mon, 24 Jan 2022 09:52:13 +0900 Subject: feat(api): expose extmark right_gravity and end_right_gravity --- test/functional/api/extmark_spec.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 3f79515949..3f96efd4ef 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1446,13 +1446,20 @@ describe('API/extmarks', function() end_col = 0, end_line = 1 }) - eq({ {1, 0, 0, { end_col = 0, end_row = 1 }} }, get_extmarks(ns, 0, -1, {details=true})) + eq({ {1, 0, 0, { + end_col = 0, + end_row = 1, + right_gravity = true, + end_right_gravity = false, + }} }, get_extmarks(ns, 0, -1, {details=true})) end) it('can get details', function() set_extmark(ns, marks[1], 0, 0, { end_col = 0, end_row = 1, + right_gravity = false, + end_right_gravity = true, priority = 0, hl_eol = true, hl_mode = "blend", @@ -1472,6 +1479,8 @@ describe('API/extmarks', function() eq({0, 0, { end_col = 0, end_row = 1, + right_gravity = false, + end_right_gravity = true, priority = 0, hl_eol = true, hl_mode = "blend", @@ -1484,6 +1493,7 @@ describe('API/extmarks', function() virt_lines_leftcol = true, } }, get_extmark_by_id(ns, marks[1], { details = true })) eq({0, 0, { + right_gravity = true, priority = 0, virt_text = { { "text", "Statement" } }, virt_text_hide = false, -- cgit From 4aa0cdd3aa117e032325edeb755107acd4ecbf84 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 24 Jan 2022 09:36:15 +0000 Subject: feat(highlight): ns=0 to set :highlight namespace Passing ns=0 to nvim_set_hl will alter the `:highlight` namespace. --- test/functional/api/highlight_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 21e3094f8e..a74da6073a 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -3,6 +3,7 @@ local clear, nvim = helpers.clear, helpers.nvim local Screen = require('test.functional.ui.screen') local eq, eval = helpers.eq, helpers.eval local command = helpers.command +local exec_capture = helpers.exec_capture local meths = helpers.meths local funcs = helpers.funcs local pcall_err = helpers.pcall_err @@ -252,4 +253,23 @@ describe("API: set highlight", function() eq(highlight3_result_gui, meths.get_hl_by_name('Test_hl', true)) eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false)) end) + + it ("can set a highlight in the global namespace", function() + meths.set_hl(0, 'Test_hl', highlight2_config) + eq('Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', + exec_capture('highlight Test_hl')) + + meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + eq('Test_hl xxx guibg=#0032aa', + exec_capture('highlight Test_hl')) + + meths.set_hl(0, 'Test_hl2', highlight3_config) + eq('Test_hl2 xxx cterm=undercurl,italic,reverse ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,italic,reverse guifg=#ff0000 guibg=#0032aa', + exec_capture('highlight Test_hl2')) + + -- Colors are stored exactly as they are defined. + meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue'}) + eq('Test_hl3 xxx guifg=bLue guibg=reD', + exec_capture('highlight Test_hl3')) + end) end) -- cgit From 5b34c2ab73d62431f391d454e68a84332148d609 Mon Sep 17 00:00:00 2001 From: glacambre Date: Tue, 25 Jan 2022 07:59:17 +0100 Subject: fix(--headless): do not block on press-enter prompts when no UI This commit fixes #9358, where emitting multiple messages with 'echo' or a single one with 'echom' or 'echoerr' would result in a press-enter prompt that couldn't be dismissed by pressing enter. This requires adapting a few tests to spawn a UI before testing whether press-enter prompts are blocking. It also fixes #11718, as when combined with #15910 it enables making sure that neovim never blocks and emits messages on startup. --- test/functional/api/vim_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index b5b10c049e..937b6559de 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -333,6 +333,7 @@ describe('API', function() describe('nvim_command_output', function() it('does not induce hit-enter prompt', function() + nvim("ui_attach", 80, 20, {}) -- Induce a hit-enter prompt use nvim_input (non-blocking). nvim('command', 'set cmdheight=1') nvim('input', [[:echo "hi\nhi2"]]) @@ -1093,7 +1094,20 @@ describe('API', function() eq({mode='n', blocking=false}, nvim("get_mode")) end) + it("during press-enter prompt without UI returns blocking=false", function() + eq({mode='n', blocking=false}, nvim("get_mode")) + command("echom 'msg1'") + command("echom 'msg2'") + command("echom 'msg3'") + command("echom 'msg4'") + command("echom 'msg5'") + eq({mode='n', blocking=false}, nvim("get_mode")) + nvim("input", ":messages") + eq({mode='n', blocking=false}, nvim("get_mode")) + end) + it("during press-enter prompt returns blocking=true", function() + nvim("ui_attach", 80, 20, {}) eq({mode='n', blocking=false}, nvim("get_mode")) command("echom 'msg1'") command("echom 'msg2'") @@ -1117,6 +1131,7 @@ describe('API', function() -- TODO: bug #6247#issuecomment-286403810 it("batched with input", function() + nvim("ui_attach", 80, 20, {}) eq({mode='n', blocking=false}, nvim("get_mode")) command("echom 'msg1'") command("echom 'msg2'") -- cgit From 23c3f7f572d3a1f3816a9a9ae1b3632c53856923 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Feb 2022 09:41:25 +0800 Subject: fix(api): use changedir_func() in nvim_set_current_dir() Co-Authored-By: smolck <46855713+smolck@users.noreply.github.com> --- test/functional/api/vim_spec.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 937b6559de..ccf3e81b22 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -536,6 +536,31 @@ describe('API', function() end) end) + describe('nvim_set_current_dir', function() + local start_dir + + before_each(function() + clear() + funcs.mkdir("Xtestdir") + start_dir = funcs.getcwd() + end) + + after_each(function() + helpers.rmdir("Xtestdir") + end) + + it('works', function() + meths.set_current_dir("Xtestdir") + eq(funcs.getcwd(), start_dir .. helpers.get_pathsep() .. "Xtestdir") + end) + + it('sets previous directory', function() + meths.set_current_dir("Xtestdir") + meths.exec('cd -', false) + eq(funcs.getcwd(), start_dir) + end) + end) + describe('nvim_exec_lua', function() it('works', function() meths.exec_lua('vim.api.nvim_set_var("test", 3)', {}) -- cgit From cb18545253259af339957316ab8361fb0cca48e5 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 12 Feb 2022 11:25:01 +0100 Subject: feat(api): add strikethrough, nocombine to set_hl --- test/functional/api/highlight_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a74da6073a..46a3798dc4 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -195,10 +195,12 @@ describe("API: set highlight", function() reverse = true, undercurl = true, underline = true, + strikethrough = true, cterm = { italic = true, reverse = true, undercurl = true, + strikethrough = true, } } local highlight3_result_gui = { @@ -209,6 +211,7 @@ describe("API: set highlight", function() reverse = true, undercurl = true, underline = true, + strikethrough = true, } local highlight3_result_cterm = { background = highlight_color.ctermbg, @@ -216,6 +219,7 @@ describe("API: set highlight", function() italic = true, reverse = true, undercurl = true, + strikethrough = true, } local function get_ns() @@ -264,7 +268,7 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl')) meths.set_hl(0, 'Test_hl2', highlight3_config) - eq('Test_hl2 xxx cterm=undercurl,italic,reverse ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,italic,reverse guifg=#ff0000 guibg=#0032aa', + eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2')) -- Colors are stored exactly as they are defined. -- cgit From f292dd2126f8dacd6446799ac750ab368b852f81 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:54:25 +0600 Subject: fix: autoload variables not loaded with vim.g & nvim_get_var --- test/functional/api/vim_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ccf3e81b22..5a387f3deb 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -898,6 +898,19 @@ describe('API', function() command('lockvar lua') eq('Key is locked: lua', pcall_err(meths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1)) + + -- Check if autoload works properly + local pathsep = helpers.get_pathsep() + local xconfig = 'Xhome' .. pathsep .. 'Xconfig' + local xdata = 'Xhome' .. pathsep .. 'Xdata' + local autoload_folder = table.concat({xconfig, 'nvim', 'autoload'}, pathsep) + local autoload_file = table.concat({autoload_folder , 'testload.vim'}, pathsep) + mkdir_p(autoload_folder) + write_file(autoload_file , [[let testload#value = 2]]) + + clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } } + eq(2, meths.get_var('testload#value')) + rmdir('Xhome') end) it('nvim_get_vvar, nvim_set_vvar', function() -- cgit From f92e74900fda4583001cb85ba7f974394948ce1a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Feb 2022 11:12:09 +0800 Subject: fix(api): nvim_win_set_cursor() redraw for cursorline and statusline --- test/functional/api/window_spec.lua | 44 +++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 4d2ffa316a..c31ab2060a 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, ok, feed, insert, eval, tabpage = helpers.clear, helpers.nvim, helpers.curbuf, helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq, @@ -73,8 +74,7 @@ describe('API/win', function() eq('typing\n some dumb text', curbuf_contents()) end) - it('does not leak memory when using invalid window ID with invalid pos', - function() + it('does not leak memory when using invalid window ID with invalid pos', function() eq('Invalid window id: 1', pcall_err(meths.win_set_cursor, 1, {"b\na"})) end) @@ -147,6 +147,46 @@ describe('API/win', function() eq({2, 5}, window('get_cursor', win)) end) + it('updates cursorline and statusline ruler in non-current window', function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {background = Screen.colors.Grey90}, -- CursorLine + [3] = {bold = true, reverse = true}, -- StatusLine + [4] = {reverse = true}, -- VertSplit, StatusLineNC + }) + screen:attach() + command('set ruler') + command('set cursorline') + insert([[ + aaa + bbb + ccc + ddd]]) + local oldwin = curwin() + command('vsplit') + screen:expect([[ + aaa {4:│}aaa | + bbb {4:│}bbb | + ccc {4:│}ccc | + {2:dd^d }{4:│}{2:ddd }| + {1:~ }{4:│}{1:~ }| + {1:~ }{4:│}{1:~ }| + {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}| + | + ]]) + window('set_cursor', oldwin, {1, 0}) + screen:expect([[ + aaa {4:│}{2:aaa }| + bbb {4:│}bbb | + ccc {4:│}ccc | + {2:dd^d }{4:│}ddd | + {1:~ }{4:│}{1:~ }| + {1:~ }{4:│}{1:~ }| + {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 1,1 All}| + | + ]]) + end) end) describe('{get,set}_height', function() -- cgit From 238b944e58d12a28245be996e69bf36a2a452a90 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 15 Feb 2022 13:08:40 -0700 Subject: fix(api): validate command names in nvim_add_user_command (#17406) This uses the same validation used when defining commands with `:command`. --- test/functional/api/command_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index d64d324a88..de22c9078c 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -180,6 +180,28 @@ describe('nvim_add_user_command', function() feed('Test b') eq('Test bbb', funcs.getcmdline()) end) + + it('does not allow invalid command names', function() + matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[ + vim.api.nvim_add_user_command('test', 'echo "hi"', {}) + ]])) + + matches('Invalid command name', pcall_err(exec_lua, [[ + vim.api.nvim_add_user_command('t@', 'echo "hi"', {}) + ]])) + + matches('Invalid command name', pcall_err(exec_lua, [[ + vim.api.nvim_add_user_command('T@st', 'echo "hi"', {}) + ]])) + + matches('Invalid command name', pcall_err(exec_lua, [[ + vim.api.nvim_add_user_command('Test!', 'echo "hi"', {}) + ]])) + + matches('Invalid command name', pcall_err(exec_lua, [[ + vim.api.nvim_add_user_command('💩', 'echo "hi"', {}) + ]])) + end) end) describe('nvim_del_user_command', function() -- cgit From d512be55a2ea54dd83914ff25f57c02d703f93b4 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 16 Dec 2021 11:40:23 +0000 Subject: fix(api): re-route nvim_get_runtime_file errors This allows nvim_get_runtime_file to be properly used via pcall --- test/functional/api/vim_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 5a387f3deb..71cd055e08 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -23,6 +23,7 @@ local next_msg = helpers.next_msg local tmpname = helpers.tmpname local write_file = helpers.write_file local exec_lua = helpers.exec_lua +local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local format_string = helpers.format_string @@ -2240,6 +2241,14 @@ describe('API', function() eq({}, meths.get_runtime_file("foobarlang/", true)) end) + it('can handle bad patterns', function() + if helpers.pending_win32(pending) then return end + + eq("Vim:E220: Missing }.", pcall_err(meths.get_runtime_file, "{", false)) + + eq('Vim(echo):E5555: API call: Vim:E220: Missing }.', + exc_exec("echo nvim_get_runtime_file('{', v:false)")) + end) end) describe('nvim_get_all_options_info', function() -- cgit From 07a98b1a75b8c4995ecf8b0e947a1909d91a3d51 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Wed, 16 Feb 2022 12:22:15 +0600 Subject: fix: not shown in :map commands --- test/functional/api/keymap_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 450a76ddac..06b699193a 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -1037,4 +1037,9 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) + + it ('shows as map rhs', function() + meths.set_keymap('n', 'asdf', '', {}) + eq('\nn asdf ', helpers.exec_capture('nmap asdf')) + end) end) -- cgit From 9a74c2b04ac8f54a17925a437b5a2f03b18f6281 Mon Sep 17 00:00:00 2001 From: Shadman <13149513+shadmansaleh@users.noreply.github.com> Date: Wed, 16 Feb 2022 14:39:50 +0600 Subject: feat(mappings): considering map description when filtering (#17423) --- test/functional/api/keymap_spec.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 06b699193a..e49e0b8cc4 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -877,6 +877,24 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq("\nn lhs rhs\n map description", helpers.exec_capture("nmap lhs")) end) + + it ('can :filter maps based on description', function() + meths.set_keymap('n', 'asdf1', 'qwert', {desc='do the one thing'}) + meths.set_keymap('n', 'asdf2', 'qwert', {desc='doesnot really do anything'}) + meths.set_keymap('n', 'asdf3', 'qwert', {desc='do the other thing'}) + eq([[ + +n asdf3 qwert + do the other thing +n asdf1 qwert + do the one thing]], + helpers.exec_capture('filter the nmap')) + end) + + it ('shows as map rhs', function() + meths.set_keymap('n', 'asdf', '', {}) + eq('\nn asdf ', helpers.exec_capture('nmap asdf')) + end) end) describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() @@ -1037,9 +1055,4 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) - - it ('shows as map rhs', function() - meths.set_keymap('n', 'asdf', '', {}) - eq('\nn asdf ', helpers.exec_capture('nmap asdf')) - end) end) -- cgit From 876aaf2003d1a6eb8f0701cf11e1834751b28980 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 15 Feb 2022 23:40:06 +0000 Subject: fix(highlight): allow globals to be cleared - and reduce heap allocations Fixes #17420 --- test/functional/api/highlight_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 46a3798dc4..a412a236a7 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -276,4 +276,26 @@ describe("API: set highlight", function() eq('Test_hl3 xxx guifg=bLue guibg=reD', exec_capture('highlight Test_hl3')) end) + + it ("can modify a highlight in the global namespace", function() + meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue'}) + eq('Test_hl3 xxx guifg=blue guibg=red', + exec_capture('highlight Test_hl3')) + + meths.set_hl(0, 'Test_hl3', { bg = 'red' }) + eq('Test_hl3 xxx guibg=red', + exec_capture('highlight Test_hl3')) + + meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12}) + eq('Test_hl3 xxx ctermfg=12 ctermbg=9', + exec_capture('highlight Test_hl3')) + + meths.set_hl(0, 'Test_hl3', { ctermbg = 9 }) + eq('Test_hl3 xxx ctermbg=9', + exec_capture('highlight Test_hl3')) + + meths.set_hl(0, 'Test_hl3', {}) + eq('Test_hl3 xxx cleared', + exec_capture('highlight Test_hl3')) + end) end) -- cgit From dc24eeb9febaa331e660e14c3c325fd0977b6b93 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 16 Feb 2022 20:38:40 +0000 Subject: feat(highlight): support color names for cterm --- test/functional/api/highlight_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a412a236a7..416945f379 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -290,6 +290,10 @@ describe("API: set highlight", function() eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { ctermbg = 'red' , ctermfg = 'blue'}) + eq('Test_hl3 xxx ctermfg=12 ctermbg=9', + exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { ctermbg = 9 }) eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) @@ -297,5 +301,18 @@ describe("API: set highlight", function() meths.set_hl(0, 'Test_hl3', {}) eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) + + eq("'redd' is not a valid color", + pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'})) + + eq("'bleu' is not a valid color", + pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'})) + + meths.set_hl(0, 'Test_hl3', {fg='#FF00FF'}) + eq('Test_hl3 xxx guifg=#FF00FF', + exec_capture('highlight Test_hl3')) + + eq("'#FF00FF' is not a valid color", + pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'})) end) end) -- cgit From e35a2d86fc2a8ed19aef00af9f35991385e833f1 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 17 Feb 2022 14:56:03 +0100 Subject: fix(api): allow empty list for cterm in nvim_set_hl Problem: when accessing `nvim_set_hl` from Lua, empty tables are converted to empty lists, not dictionaries, resulting in an error for :lua vim.api.nvim_set_hl(0, "Comment", { cterm = {} }) Workaround: add an empty array as a special case when checking `dict->cterm.type` and just set `cterm_mask_provided`. (Proper solution: handle this in `gen_api_dispatch.lua`.) --- test/functional/api/highlight_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 416945f379..03b407f4e0 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -242,6 +242,12 @@ describe("API: set highlight", function() eq(highlight2_result, meths.get_hl_by_name('Test_hl', false)) end) + it ("can set emtpy cterm attr", function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, meths.get_hl_by_name('Test_hl', false)) + end) + it ("cterm attr defaults to gui attr", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight1) -- cgit From f3e6cc1a23b84ee5a8698614e78bce6d702a6d61 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Wed, 16 Feb 2022 23:15:24 +0100 Subject: test: remove checks to see if current CI job is travis or appveyor --- test/functional/api/server_requests_spec.lua | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 309d9084c8..cdcf08c348 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -181,12 +181,6 @@ describe('server -> client', function() end) describe('recursive (child) nvim client', function() - if helpers.isCI('travis') and helpers.is_os('mac') then - -- XXX: Hangs Travis macOS since e9061117a5b8f195c3f26a5cb94e18ddd7752d86. - pending("[Hangs on Travis macOS. #5002]", function() end) - return - end - before_each(function() command("let vim = rpcstart('"..nvim_prog.."', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed', '--headless'])") neq(0, eval('vim')) -- cgit From 82c5a02050dcc91673d4ef66b4ad20ecf9cae8c8 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sat, 19 Feb 2022 11:11:05 +0100 Subject: ci: skip tests that fail on windows --- test/functional/api/buffer_updates_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index c9c9be5406..25ca8cfe4a 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -7,6 +7,7 @@ local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err local sleep = helpers.sleep local write_file = helpers.write_file +local iswin = helpers.iswin local origlines = {"original line 1", "original line 2", @@ -823,7 +824,7 @@ describe('API: buffer events:', function() end msg = next_msg() end - assert(false, 'did not match/receive expected nvim_buf_lines_event lines') + assert(iswin(), 'did not match/receive expected nvim_buf_lines_event lines') end it('when :terminal lines change', function() -- cgit From 1e7cb2dcd975aadeb91b913f117b21c7775c3374 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 21 Feb 2022 20:17:36 +0000 Subject: fix(highlight): accept NONE as a color name (#17487) ... for when `ns=0`. Also update the documentation of nvim_set_hl to clarify the set behaviour. Fixes #17478 --- test/functional/api/highlight_spec.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 03b407f4e0..6924d41e0b 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -304,10 +304,6 @@ describe("API: set highlight", function() eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', {}) - eq('Test_hl3 xxx cleared', - exec_capture('highlight Test_hl3')) - eq("'redd' is not a valid color", pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'})) @@ -320,5 +316,12 @@ describe("API: set highlight", function() eq("'#FF00FF' is not a valid color", pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'})) + + for _, fg_val in ipairs{ nil, 'NONE', 'nOnE', '', -1 } do + meths.set_hl(0, 'Test_hl3', {fg = fg_val}) + eq('Test_hl3 xxx cleared', + exec_capture('highlight Test_hl3')) + end + end) end) -- cgit From 11f7aeed7aa83d342d19897d9a69ba9f32ece7f7 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:19:21 -0700 Subject: feat(api): implement nvim_buf_get_text (#15181) nvim_buf_get_text is the mirror of nvim_buf_set_text. It differs from nvim_buf_get_lines in that it allows retrieving only portions of lines. While this can typically be done easily enough by API clients, implementing this function provides symmetry between the get/set text/lines APIs, and also provides a nice convenience that saves API clients the work of having to slice the result of nvim_buf_get_lines themselves. --- test/functional/api/buffer_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 688f3abba5..dac3324a0f 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -537,6 +537,34 @@ describe('api/buf', function() end) end) + describe('nvim_buf_get_text', function() + local get_text = curbufmeths.get_text + + it('works', function() + insert([[ + hello foo! + text]]) + + eq({'hello'}, get_text(0, 0, 0, 5, {})) + eq({'hello foo!'}, get_text(0, 0, 0, 42, {})) + eq({'foo!'}, get_text(0, 6, 0, 10, {})) + eq({'foo!', 'tex'}, get_text(0, 6, 1, 3, {})) + eq({'foo!', 'tex'}, get_text(-2, 6, -1, 3, {})) + eq({''}, get_text(0, 18, 0, 20, {})) + eq({'ext'}, get_text(-1, 1, -1, 4, {})) + end) + + it('errors on out-of-range', function() + eq(false, pcall(get_text, 2, 0, 3, 0, {})) + eq(false, pcall(get_text, 0, 0, 4, 0, {})) + end) + + it('errors when start is greater than end', function() + eq(false, pcall(get_text, 1, 0, 0, 0, {})) + eq(false, pcall(get_text, 0, 1, 0, 0, {})) + end) + end) + describe('nvim_buf_get_offset', function() local get_offset = curbufmeths.get_offset it('works', function() -- cgit From 15004473b531e37a6ff3aeca9e3bfeaaa1487d9e Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Wed, 23 Feb 2022 15:19:47 -0700 Subject: fix(api)!: correctly handle negative line numbers for nvim_buf_set_text (#17498) nvim_buf_set_text does not handle negative row numbers correctly: for example, nvim_buf_set_text(0, -2, 0, -1, 20, {"Hello", "world"}) should replace the 2nd to last line in the buffer with "Hello" and the first 20 characters of the last line with "world". Instead, it reports "start_row out of bounds". This happens because when negative line numbers are used, they are incremented by one additional number to make the non-negative line numbers end-exclusive. However, the line numbers for nvim_buf_set_text should be end-inclusive. In #15181 we handled this for nvim_buf_get_text by adding a new parameter to `normalize_index`. We can solve the problem with nvim_buf_set_text by simply availing ourselves of this new argument. This is a breaking change, but makes the semantics of negative line numbers much clearer and more obvious (as well as matching nvim_buf_get_text). BREAKING CHANGE: Existing usages of nvim_buf_set_text that use negative line numbers will be off-by-one. --- test/functional/api/buffer_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index dac3324a0f..dd3af8c28f 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -423,6 +423,13 @@ describe('api/buf', function() -- will join multiple lines if needed set_text(0, 6, 3, 4, {'bar'}) eq({'hello bar'}, get_lines(0, 1, true)) + + -- can use negative line numbers + set_text(-2, 0, -2, 5, {'goodbye'}) + eq({'goodbye bar', ''}, get_lines(0, -1, true)) + + set_text(-1, 0, -1, 0, {'text'}) + eq({'goodbye bar', 'text'}, get_lines(0, 2, true)) end) it('works with undo', function() -- cgit From b5bf4877c0239767c1095e4567e67c222bea38a0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 24 Feb 2022 16:50:05 +0000 Subject: feat(highlight): support for blend in nvim_set_hl (#17516) --- test/functional/api/highlight_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 6924d41e0b..443689754c 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -323,5 +323,9 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl3')) end + meths.set_hl(0, 'Test_hl3', {fg='#FF00FF', blend=50}) + eq('Test_hl3 xxx guifg=#FF00FF blend=50', + exec_capture('highlight Test_hl3')) + end) end) -- cgit From 0545bd21805b25b95ed6290d17e2c5804e9dbd98 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 26 Feb 2022 19:28:18 +0800 Subject: test: use helpers.pending_win32(pending) instead of iswin() --- test/functional/api/buffer_updates_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 25ca8cfe4a..e9ad756947 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -824,6 +824,7 @@ describe('API: buffer events:', function() end msg = next_msg() end + -- FIXME: Windows assert(iswin(), 'did not match/receive expected nvim_buf_lines_event lines') end -- cgit From 1b5767aa3480c0cdc43f7a4b78f36a14e85a182f Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Sun, 27 Feb 2022 14:35:06 -0500 Subject: feat(lua): add to user commands callback (#17522) Works similar to ex . It only splits the arguments if the command has more than one posible argument. In cases were the command can only have 1 argument opts.fargs = { opts.args } --- test/functional/api/command_spec.lua | 66 ++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 10 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index de22c9078c..b80004f67c 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -107,7 +107,8 @@ describe('nvim_add_user_command', function() ]] eq({ - args = "hello", + args = [[hello my\ friend how\ are\ you?]], + fargs = {[[hello]], [[my\ friend]], [[how\ are\ you?]]}, bang = false, line1 = 1, line2 = 1, @@ -115,13 +116,14 @@ describe('nvim_add_user_command', function() range = 0, count = 2, reg = "", - }, exec_lua [[ - vim.api.nvim_command('CommandWithLuaCallback hello') + }, exec_lua [=[ + vim.api.nvim_command([[CommandWithLuaCallback hello my\ friend how\ are\ you?]]) return result - ]]) + ]=]) eq({ - args = "", + args = 'h\tey', + fargs = {[[h]], [[ey]]}, bang = true, line1 = 10, line2 = 10, @@ -129,13 +131,14 @@ describe('nvim_add_user_command', function() range = 1, count = 10, reg = "", - }, exec_lua [[ - vim.api.nvim_command('botright 10CommandWithLuaCallback!') + }, exec_lua [=[ + vim.api.nvim_command('botright 10CommandWithLuaCallback! h\tey') return result - ]]) + ]=]) eq({ - args = "", + args = "h", + fargs = {"h"}, bang = false, line1 = 1, line2 = 42, @@ -144,9 +147,52 @@ describe('nvim_add_user_command', function() count = 42, reg = "", }, exec_lua [[ - vim.api.nvim_command('CommandWithLuaCallback 42') + vim.api.nvim_command('CommandWithLuaCallback 42 h') return result ]]) + + eq({ + args = "", + fargs = {""}, -- fargs works without args + bang = false, + line1 = 1, + line2 = 1, + mods = "", + range = 0, + count = 2, + reg = "", + }, exec_lua [[ + vim.api.nvim_command('CommandWithLuaCallback') + return result + ]]) + + -- f-args doesn't split when command nargs is 1 or "?" + exec_lua [[ + result = {} + vim.api.nvim_add_user_command('CommandWithOneArg', function(opts) + result = opts + end, { + nargs = "?", + bang = true, + count = 2, + }) + ]] + + eq({ + args = "hello I'm one argmuent", + fargs = {"hello I'm one argmuent"}, -- Doesn't split args + bang = false, + line1 = 1, + line2 = 1, + mods = "", + range = 0, + count = 2, + reg = "", + }, exec_lua [[ + vim.api.nvim_command('CommandWithOneArg hello I\'m one argmuent') + return result + ]]) + end) it('can define buffer-local commands', function() -- cgit From 991e472881bf29805982b402c1a010cde051ded3 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 28 May 2021 15:45:34 -0400 Subject: feat(lua): add api and lua autocmds --- test/functional/api/autocmd_spec.lua | 798 +++++++++++++++++++++++++++++++++++ 1 file changed, 798 insertions(+) create mode 100644 test/functional/api/autocmd_spec.lua (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua new file mode 100644 index 0000000000..2b48ffa6f0 --- /dev/null +++ b/test/functional/api/autocmd_spec.lua @@ -0,0 +1,798 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local neq = helpers.neq +local exec_lua = helpers.exec_lua +local matches = helpers.matches +local meths = helpers.meths +local source = helpers.source + +before_each(clear) + +describe('autocmd api', function() + describe('nvim_create_autocmd', function() + it('does not allow "command" and "callback" in the same autocmd', function() + local ok, _ = pcall(meths.create_autocmd, { + event = "BufReadPost", + pattern = "*.py,*.pyi", + command = "echo 'Should Have Errored", + callback = "not allowed", + }) + + eq(false, ok) + end) + + it('doesnt leak when you use ++once', function() + eq(1, exec_lua([[ + local count = 0 + + vim.api.nvim_create_autocmd { + event = "FileType", + pattern = "*", + callback = function() count = count + 1 end, + once = true + } + + vim.cmd "set filetype=txt" + vim.cmd "set filetype=python" + + return count + ]], {})) + end) + + it('allows passing buffer by key', function() + meths.set_var('called', 0) + + meths.create_autocmd { + event = "Filetype", + command = "let g:called = g:called + 1", + buffer = 0, + } + + meths.command "set filetype=txt" + eq(1, meths.get_var('called')) + + -- switch to a new buffer + meths.command "new" + meths.command "set filetype=python" + + eq(1, meths.get_var('called')) + end) + + it('does not allow passing buffer and patterns', function() + local ok = pcall(meths.create_autocmd, { + event = "Filetype", + command = "let g:called = g:called + 1", + buffer = 0, + pattern = "*.py", + }) + + eq(false, ok) + end) + + it('does not allow passing invalid buffers', function() + local ok, msg = pcall(meths.create_autocmd, { + event = "Filetype", + command = "let g:called = g:called + 1", + buffer = -1, + }) + + eq(false, ok) + matches('Invalid buffer id', msg) + end) + + it('errors on non-functions for cb', function() + eq(false, pcall(exec_lua, [[ + vim.api.nvim_create_autocmd { + event = "BufReadPost", + pattern = "*.py,*.pyi", + callback = 5, + } + ]])) + end) + + it('allow passing pattern and in same pattern', function() + local ok = pcall(meths.create_autocmd, { + event = "BufReadPost", + pattern = "*.py,", + command = "echo 'Should Not Error'" + }) + + eq(true, ok) + end) + + it('should handle multiple values as comma separated list', function() + meths.create_autocmd { + event = "BufReadPost", + pattern = "*.py,*.pyi", + command = "echo 'Should Not Have Errored'" + } + + -- We should have one autocmd for *.py and one for *.pyi + eq(2, #meths.get_autocmds { event = "BufReadPost" }) + end) + + it('should handle multiple values as array', function() + meths.create_autocmd { + event = "BufReadPost", + pattern = { "*.py", "*.pyi", }, + command = "echo 'Should Not Have Errored'" + } + + -- We should have one autocmd for *.py and one for *.pyi + eq(2, #meths.get_autocmds { event = "BufReadPost" }) + end) + + describe('desc', function() + it('can add description to one autocmd', function() + meths.create_autocmd { + event = "BufReadPost", + pattern = "*.py", + command = "echo 'Should Not Have Errored'", + desc = "Can show description", + } + + eq("Can show description", meths.get_autocmds { event = "BufReadPost" }[1].desc) + end) + + it('can add description to multiple autocmd', function() + meths.create_autocmd { + event = "BufReadPost", + pattern = {"*.py", "*.pyi"}, + command = "echo 'Should Not Have Errored'", + desc = "Can show description", + } + + local aus = meths.get_autocmds { event = "BufReadPost" } + eq(2, #aus) + eq("Can show description", aus[1].desc) + eq("Can show description", aus[2].desc) + end) + end) + + pending('script and verbose settings', function() + it('marks API client', function() + meths.create_autocmd { + event = "BufReadPost", + pattern = "*.py", + command = "echo 'Should Not Have Errored'", + desc = "Can show description", + } + + local aus = meths.get_autocmds { event = "BufReadPost" } + eq(1, #aus, aus) + end) + end) + end) + + describe('nvim_get_autocmds', function() + describe('events', function() + it('should return one autocmd when there is only one for an event', function() + command [[au! InsertEnter]] + command [[au InsertEnter * :echo "1"]] + + local aus = meths.get_autocmds { event = "InsertEnter" } + eq(1, #aus) + end) + + it('should return two autocmds when there are two for an event', function() + command [[au! InsertEnter]] + command [[au InsertEnter * :echo "1"]] + command [[au InsertEnter * :echo "2"]] + + local aus = meths.get_autocmds { event = "InsertEnter" } + eq(2, #aus) + end) + + it('should return the same thing if you use string or list', function() + command [[au! InsertEnter]] + command [[au InsertEnter * :echo "1"]] + command [[au InsertEnter * :echo "2"]] + + local string_aus = meths.get_autocmds { event = "InsertEnter" } + local array_aus = meths.get_autocmds { event = { "InsertEnter" } } + eq(string_aus, array_aus) + end) + + it('should return two autocmds when there are two for an event', function() + command [[au! InsertEnter]] + command [[au! InsertLeave]] + command [[au InsertEnter * :echo "1"]] + command [[au InsertEnter * :echo "2"]] + + local aus = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + eq(2, #aus) + end) + + it('should return different IDs for different autocmds', function() + command [[au! InsertEnter]] + command [[au! InsertLeave]] + command [[au InsertEnter * :echo "1"]] + source [[ + call nvim_create_autocmd(#{ + \ event: "InsertLeave", + \ command: ":echo 2", + \ }) + ]] + + local aus = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + local first = aus[1] + eq(first.id, nil) + + -- TODO: Maybe don't have this number, just assert it's not nil + local second = aus[2] + neq(second.id, nil) + + meths.del_autocmd(second.id) + local new_aus = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + eq(1, #new_aus) + eq(first, new_aus[1]) + end) + end) + + describe('groups', function() + before_each(function() + command [[au! InsertEnter]] + + command [[au InsertEnter * :echo "No Group"]] + + command [[augroup GroupOne]] + command [[ au InsertEnter * :echo "GroupOne:1"]] + command [[augroup END]] + + command [[augroup GroupTwo]] + command [[ au InsertEnter * :echo "GroupTwo:2"]] + command [[ au InsertEnter * :echo "GroupTwo:3"]] + command [[augroup END]] + end) + + it('should return all groups if no group is specified', function() + local aus = meths.get_autocmds { event = "InsertEnter" } + if #aus ~= 4 then + eq({}, aus) + end + + eq(4, #aus) + end) + + it('should return only the group specified', function() + local aus = meths.get_autocmds { + event = "InsertEnter", + group = "GroupOne", + } + + eq(1, #aus) + eq([[:echo "GroupOne:1"]], aus[1].command) + end) + + it('should return only the group specified, multiple values', function() + local aus = meths.get_autocmds { + event = "InsertEnter", + group = "GroupTwo", + } + + eq(2, #aus) + eq([[:echo "GroupTwo:2"]], aus[1].command) + eq([[:echo "GroupTwo:3"]], aus[2].command) + end) + end) + + describe('groups: 2', function() + it('raises error for undefined augroup', function() + local success, code = unpack(meths.exec_lua([[ + return {pcall(function() + vim.api.nvim_create_autocmd { + event = "FileType", + pattern = "*", + group = "NotDefined", + command = "echo 'hello'", + } + end)} + ]], {})) + + eq(false, success) + matches('invalid augroup: NotDefined', code) + end) + end) + + describe('patterns', function() + before_each(function() + command [[au! InsertEnter]] + + command [[au InsertEnter * :echo "No Group"]] + command [[au InsertEnter *.one :echo "GroupOne:1"]] + command [[au InsertEnter *.two :echo "GroupTwo:2"]] + command [[au InsertEnter *.two :echo "GroupTwo:3"]] + command [[au InsertEnter :echo "Buffer"]] + end) + + it('should should return for literal match', function() + local aus = meths.get_autocmds { + event = "InsertEnter", + pattern = "*" + } + + eq(1, #aus) + eq([[:echo "No Group"]], aus[1].command) + end) + + it('should return for multiple matches', function() + -- vim.api.nvim_get_autocmds + local aus = meths.get_autocmds { + event = "InsertEnter", + pattern = { "*.one", "*.two" }, + } + + eq(3, #aus) + eq([[:echo "GroupOne:1"]], aus[1].command) + eq([[:echo "GroupTwo:2"]], aus[2].command) + eq([[:echo "GroupTwo:3"]], aus[3].command) + end) + + it('should work for buffer autocmds', function() + local normalized_aus = meths.get_autocmds { + event = "InsertEnter", + pattern = "", + } + + local raw_aus = meths.get_autocmds { + event = "InsertEnter", + pattern = "", + } + + local zero_aus = meths.get_autocmds { + event = "InsertEnter", + pattern = "", + } + + eq(normalized_aus, raw_aus) + eq(normalized_aus, zero_aus) + eq([[:echo "Buffer"]], normalized_aus[1].command) + end) + end) + end) + + describe('nvim_do_autocmd', function() + it("can trigger builtin autocmds", function() + meths.set_var("autocmd_executed", false) + + meths.create_autocmd { + event = "BufReadPost", + pattern = "*", + command = "let g:autocmd_executed = v:true", + } + + eq(false, meths.get_var("autocmd_executed")) + meths.do_autocmd { event = "BufReadPost" } + eq(true, meths.get_var("autocmd_executed")) + end) + + it("can pass the buffer", function() + meths.set_var("buffer_executed", -1) + eq(-1, meths.get_var("buffer_executed")) + + meths.create_autocmd { + event = "BufLeave", + pattern = "*", + command = 'let g:buffer_executed = +expand("")', + } + + -- Doesn't execute for other non-matching events + meths.do_autocmd { event = "CursorHold", buffer = 1 } + eq(-1, meths.get_var("buffer_executed")) + + meths.do_autocmd { event = "BufLeave", buffer = 1 } + eq(1, meths.get_var("buffer_executed")) + end) + + it("can pass the filename, pattern match", function() + meths.set_var("filename_executed", 'none') + eq('none', meths.get_var("filename_executed")) + + meths.create_autocmd { + event = "BufEnter", + pattern = "*.py", + command = 'let g:filename_executed = expand("")', + } + + -- Doesn't execute for other non-matching events + meths.do_autocmd { event = "CursorHold", buffer = 1 } + eq('none', meths.get_var("filename_executed")) + + meths.command('edit __init__.py') + eq('__init__.py', meths.get_var("filename_executed")) + end) + + it('cannot pass buf and fname', function() + local ok = pcall(meths.do_autocmd, { pattern = "literally_cannot_error.rs", buffer = 1 }) + eq(false, ok) + end) + + it("can pass the filename, exact match", function() + meths.set_var("filename_executed", 'none') + eq('none', meths.get_var("filename_executed")) + + meths.command('edit other_file.txt') + meths.command('edit __init__.py') + eq('none', meths.get_var("filename_executed")) + + meths.create_autocmd { + event = "CursorHoldI", + pattern = "__init__.py", + command = 'let g:filename_executed = expand("")', + } + + -- Doesn't execute for other non-matching events + meths.do_autocmd { event = "CursorHoldI", buffer = 1 } + eq('none', meths.get_var("filename_executed")) + + meths.do_autocmd { event = "CursorHoldI", buffer = tonumber(meths.get_current_buf()) } + eq('__init__.py', meths.get_var("filename_executed")) + + -- Reset filename + meths.set_var("filename_executed", 'none') + + meths.do_autocmd { event = "CursorHoldI", pattern = '__init__.py' } + eq('__init__.py', meths.get_var("filename_executed")) + end) + + it("works with user autocmds", function() + meths.set_var("matched", 'none') + + meths.create_autocmd { + event = "User", + pattern = "TestCommand", + command = 'let g:matched = "matched"' + } + + meths.do_autocmd { event = "User", pattern = "OtherCommand" } + eq('none', meths.get_var('matched')) + meths.do_autocmd { event = "User", pattern = "TestCommand" } + eq('matched', meths.get_var('matched')) + end) + end) + + describe('nvim_create_augroup', function() + before_each(function() + clear() + + meths.set_var('executed', 0) + end) + + local make_counting_autocmd = function(opts) + opts = opts or {} + + local resulting = { + event = "FileType", + pattern = "*", + command = "let g:executed = g:executed + 1", + } + + resulting.group = opts.group + resulting.once = opts.once + + meths.create_autocmd(resulting) + end + + local set_ft = function(ft) + ft = ft or "txt" + source(string.format("set filetype=%s", ft)) + end + + local get_executed_count = function() + return meths.get_var('executed') + end + + it('can be added in a group', function() + local augroup = "TestGroup" + meths.create_augroup({ name = augroup, clear = true }) + make_counting_autocmd { group = augroup } + + set_ft("txt") + set_ft("python") + + eq(get_executed_count(), 2) + end) + + it('works getting called multiple times', function() + make_counting_autocmd() + set_ft() + set_ft() + set_ft() + + eq(get_executed_count(), 3) + end) + + it('handles ++once', function() + make_counting_autocmd {once = true} + set_ft('txt') + set_ft('help') + set_ft('txt') + set_ft('help') + + eq(get_executed_count(), 1) + end) + + it('errors on unexpected keys', function() + local success, code = pcall(meths.create_autocmd, { + event = "FileType", + pattern = "*", + not_a_valid_key = "NotDefined", + }) + + eq(false, success) + matches('not_a_valid_key', code) + end) + + it('can execute simple callback', function() + exec_lua([[ + vim.g.executed = false + + vim.api.nvim_create_autocmd { + event = "FileType", + pattern = "*", + callback = function() vim.g.executed = true end, + } + ]], {}) + + + eq(true, exec_lua([[ + vim.cmd "set filetype=txt" + return vim.g.executed + ]], {})) + end) + + it('calls multiple lua callbacks for the same autocmd execution', function() + eq(4, exec_lua([[ + local count = 0 + local counter = function() + count = count + 1 + end + + vim.api.nvim_create_autocmd { + event = "FileType", + pattern = "*", + callback = counter, + } + + vim.api.nvim_create_autocmd { + event = "FileType", + pattern = "*", + callback = counter, + } + + vim.cmd "set filetype=txt" + vim.cmd "set filetype=txt" + + return count + ]], {})) + end) + + it('properly releases functions with ++once', function() + exec_lua([[ + WeakTable = setmetatable({}, { __mode = "k" }) + + OnceCount = 0 + + MyVal = {} + WeakTable[MyVal] = true + + vim.api.nvim_create_autocmd { + event = "FileType", + pattern = "*", + callback = function() + OnceCount = OnceCount + 1 + MyVal = {} + end, + once = true + } + ]]) + + command [[set filetype=txt]] + eq(1, exec_lua([[return OnceCount]], {})) + + exec_lua([[collectgarbage()]], {}) + + command [[set filetype=txt]] + eq(1, exec_lua([[return OnceCount]], {})) + + eq(0, exec_lua([[ + local count = 0 + for _ in pairs(WeakTable) do + count = count + 1 + end + + return count + ]]), "Should have no keys remaining") + end) + + it('groups can be cleared', function() + local augroup = "TestGroup" + meths.create_augroup({ name = augroup, clear = true }) + meths.create_autocmd({ + group = augroup, + event = "FileType", + command = "let g:executed = g:executed + 1" + }) + + set_ft("txt") + set_ft("txt") + eq(2, get_executed_count(), "should only count twice") + + meths.create_augroup({ name = augroup, clear = true }) + eq({}, meths.get_autocmds { group = augroup }) + + set_ft("txt") + set_ft("txt") + eq(2, get_executed_count(), "No additional counts") + end) + + it('groups work with once', function() + local augroup = "TestGroup" + + meths.create_augroup({ name = augroup, clear = true }) + make_counting_autocmd { group = augroup, once = true } + + set_ft("txt") + set_ft("python") + + eq(get_executed_count(), 1) + end) + + it('autocmds can be registered multiple times.', function() + local augroup = "TestGroup" + + meths.create_augroup({ name = augroup, clear = true }) + make_counting_autocmd { group = augroup, once = false } + make_counting_autocmd { group = augroup, once = false } + make_counting_autocmd { group = augroup, once = false } + + set_ft("txt") + set_ft("python") + + eq(get_executed_count(), 3 * 2) + end) + + it('can be deleted', function() + local augroup = "WillBeDeleted" + + meths.create_augroup({ name = augroup, clear = true }) + meths.create_autocmd { + event = {"Filetype"}, + pattern = "*", + command = "echo 'does not matter'", + } + + -- Clears the augroup from before, which erases the autocmd + meths.create_augroup({ name = augroup, clear = true }) + + local result = #meths.get_autocmds { group = augroup } + + eq(0, result) + end) + + it('can be used for buffer local autocmds', function() + local augroup = "WillBeDeleted" + + meths.set_var("value_set", false) + + meths.create_augroup({ name = augroup, clear = true }) + meths.create_autocmd { + event = "Filetype", + pattern = "", + command = "let g:value_set = v:true", + } + + command "new" + command "set filetype=python" + + eq(false, meths.get_var("value_set")) + end) + + it('can accept vimscript functions', function() + source [[ + let g:vimscript_executed = 0 + + function! MyVimscriptFunction() abort + let g:vimscript_executed = g:vimscript_executed + 1 + endfunction + + call nvim_create_autocmd(#{ + \ event: "Filetype", + \ pattern: ["python", "javascript"], + \ callback: "MyVimscriptFunction", + \ }) + + set filetype=txt + set filetype=python + set filetype=txt + set filetype=javascript + set filetype=txt + ]] + + eq(2, meths.get_var("vimscript_executed")) + end) + end) + + describe('augroup!', function() + it('legacy: should clear and not return any autocmds for delete groups', function() + command('augroup TEMP_A') + command(' autocmd! BufReadPost *.py :echo "Hello"') + command('augroup END') + + command('augroup! TEMP_A') + + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_A' })) + + -- For some reason, augroup! doesn't clear the autocmds themselves, which is just wild + -- but we managed to keep this behavior. + eq(1, #meths.get_autocmds { event = 'BufReadPost' }) + end) + + it('legacy: remove augroups that have no autocmds', function() + command('augroup TEMP_AB') + command('augroup END') + + command('augroup! TEMP_AB') + + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_AB' })) + eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + end) + + it('legacy: multiple remove and add augroup', function() + command('augroup TEMP_ABC') + command(' au!') + command(' autocmd BufReadPost *.py echo "Hello"') + command('augroup END') + + command('augroup! TEMP_ABC') + + -- Should still have one autocmd :'( + local aus = meths.get_autocmds { event = 'BufReadPost' } + eq(1, #aus, aus) + + command('augroup TEMP_ABC') + command(' au!') + command(' autocmd BufReadPost *.py echo "Hello"') + command('augroup END') + + -- Should now have two autocmds :'( + aus = meths.get_autocmds { event = 'BufReadPost' } + eq(2, #aus, aus) + + command('augroup! TEMP_ABC') + + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABC' })) + eq(2, #meths.get_autocmds { event = 'BufReadPost' }) + end) + + it('api: should clear and not return any autocmds for delete groups by id', function() + command('augroup TEMP_ABCD') + command('autocmd! BufReadPost *.py :echo "Hello"') + command('augroup END') + + local augroup_id = meths.create_augroup { name = "TEMP_ABCD", clear = false } + meths.del_augroup_by_id(augroup_id) + + -- For good reason, we kill all the autocmds from del_augroup, + -- so now this works as expected + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCD' })) + eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + end) + + it('api: should clear and not return any autocmds for delete groups by name', function() + command('augroup TEMP_ABCDE') + command('autocmd! BufReadPost *.py :echo "Hello"') + command('augroup END') + + meths.del_augroup_by_name("TEMP_ABCDE") + + -- For good reason, we kill all the autocmds from del_augroup, + -- so now this works as expected + eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCDE' })) + eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + end) + end) +end) -- cgit From ebfe083337701534887ac3ea3d8e7ad47f7a206a Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 8 Jan 2022 00:39:44 +0600 Subject: feat(lua): show proper verbose output for lua configuration `:verbose` didn't work properly with lua configs (For example: options or keymaps are set from lua, just say that they were set from lua, doesn't say where they were set at. This fixes that issue. Now `:verbose` will provide filename and line no when option/keymap is set from lua. Changes: - compiles lua/vim/keymap.lua as vim/keymap.lua - When souring a lua file current_sctx.sc_sid is set to SID_LUA - Moved finding scripts SID out of `do_source()` to `get_current_script_id()`. So it can be reused for lua files. - Added new function `nlua_get_sctx` that extracts current lua scripts name and line no with debug library. And creates a sctx for it. NOTE: This function ignores C functions and blacklist which currently contains only vim/_meta.lua so vim.o/opt wrappers aren't targeted. - Added function `nlua_set_sctx` that changes provided sctx to current lua scripts sctx if a lua file is being executed. - Added tests in tests/functional/lua/verbose_spec.lua - add primary support for additional types (:autocmd, :function, :syntax) to lua verbose Note: These can't yet be directly set from lua but once that's possible :verbose should work for them hopefully :D - add :verbose support for nvim_exec & nvim_command within lua Currently auto commands/commands/functions ... can only be defined by nvim_exec/nvim_command this adds support for them. Means if those Are defined within lua with vim.cmd/nvim_exec :verbose will show their location . Though note it'll show the line no on which nvim_exec call was made. --- test/functional/api/keymap_spec.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index e49e0b8cc4..6562b40d53 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -15,6 +15,9 @@ local pcall_err = helpers.pcall_err local shallowcopy = helpers.shallowcopy local sleep = helpers.sleep +local sid_api_client = -9 +local sid_lua = -8 + describe('nvim_get_keymap', function() before_each(clear) @@ -340,7 +343,7 @@ describe('nvim_get_keymap', function() script=0, silent=0, expr=0, - sid=0, + sid=sid_lua, buffer=0, nowait=0, mode='n', @@ -357,7 +360,7 @@ describe('nvim_get_keymap', function() script=0, silent=0, expr=0, - sid=0, + sid=sid_api_client, buffer=0, nowait=0, mode='n', @@ -400,7 +403,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() to_return.silent = not opts.silent and 0 or 1 to_return.nowait = not opts.nowait and 0 or 1 to_return.expr = not opts.expr and 0 or 1 - to_return.sid = not opts.sid and 0 or opts.sid + to_return.sid = not opts.sid and sid_api_client or opts.sid to_return.buffer = not opts.buffer and 0 or opts.buffer to_return.lnum = not opts.lnum and 0 or opts.lnum to_return.desc = opts.desc @@ -625,7 +628,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('interprets control sequences in expr-quotes correctly when called ' ..'inside vim', function() command([[call nvim_set_keymap('i', "\", "\", {})]]) - eq(generate_mapargs('i', '', '\t', {}), + eq(generate_mapargs('i', '', '\t', {sid=0}), get_mapargs('i', '')) feed('i ') eq({'\t'}, curbufmeths.get_lines(0, -1, 0)) @@ -807,7 +810,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() local mapargs = funcs.maparg('asdf', 'n', false, true) assert.Truthy(type(mapargs.callback) == 'number', 'callback is not luaref number') mapargs.callback = nil - eq(generate_mapargs('n', 'asdf', nil, {}), mapargs) + eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs) end) it('can make lua expr mappings', function() -- cgit From 0f613482b389ad259dd53d893907b024a115352e Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 28 May 2021 15:45:34 -0400 Subject: feat(lua): add missing changes to autocmds lost in the rebase Note: some of these changes are breaking, like change of API signatures --- test/functional/api/autocmd_spec.lua | 165 +++++++++++++++-------------------- 1 file changed, 68 insertions(+), 97 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 2b48ffa6f0..32a3db34a3 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -14,8 +14,7 @@ before_each(clear) describe('autocmd api', function() describe('nvim_create_autocmd', function() it('does not allow "command" and "callback" in the same autocmd', function() - local ok, _ = pcall(meths.create_autocmd, { - event = "BufReadPost", + local ok, _ = pcall(meths.create_autocmd, "BufReadPost", { pattern = "*.py,*.pyi", command = "echo 'Should Have Errored", callback = "not allowed", @@ -28,12 +27,11 @@ describe('autocmd api', function() eq(1, exec_lua([[ local count = 0 - vim.api.nvim_create_autocmd { - event = "FileType", + vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() count = count + 1 end, once = true - } + }) vim.cmd "set filetype=txt" vim.cmd "set filetype=python" @@ -45,11 +43,10 @@ describe('autocmd api', function() it('allows passing buffer by key', function() meths.set_var('called', 0) - meths.create_autocmd { - event = "Filetype", + meths.create_autocmd("FileType", { command = "let g:called = g:called + 1", buffer = 0, - } + }) meths.command "set filetype=txt" eq(1, meths.get_var('called')) @@ -62,8 +59,7 @@ describe('autocmd api', function() end) it('does not allow passing buffer and patterns', function() - local ok = pcall(meths.create_autocmd, { - event = "Filetype", + local ok = pcall(meths.create_autocmd, "Filetype", { command = "let g:called = g:called + 1", buffer = 0, pattern = "*.py", @@ -73,8 +69,7 @@ describe('autocmd api', function() end) it('does not allow passing invalid buffers', function() - local ok, msg = pcall(meths.create_autocmd, { - event = "Filetype", + local ok, msg = pcall(meths.create_autocmd, "Filetype", { command = "let g:called = g:called + 1", buffer = -1, }) @@ -85,17 +80,15 @@ describe('autocmd api', function() it('errors on non-functions for cb', function() eq(false, pcall(exec_lua, [[ - vim.api.nvim_create_autocmd { - event = "BufReadPost", + vim.api.nvim_create_autocmd("BufReadPost", { pattern = "*.py,*.pyi", callback = 5, - } + }) ]])) end) it('allow passing pattern and in same pattern', function() - local ok = pcall(meths.create_autocmd, { - event = "BufReadPost", + local ok = pcall(meths.create_autocmd, "BufReadPost", { pattern = "*.py,", command = "echo 'Should Not Error'" }) @@ -104,22 +97,20 @@ describe('autocmd api', function() end) it('should handle multiple values as comma separated list', function() - meths.create_autocmd { - event = "BufReadPost", + meths.create_autocmd("BufReadPost", { pattern = "*.py,*.pyi", command = "echo 'Should Not Have Errored'" - } + }) -- We should have one autocmd for *.py and one for *.pyi eq(2, #meths.get_autocmds { event = "BufReadPost" }) end) it('should handle multiple values as array', function() - meths.create_autocmd { - event = "BufReadPost", + meths.create_autocmd("BufReadPost", { pattern = { "*.py", "*.pyi", }, command = "echo 'Should Not Have Errored'" - } + }) -- We should have one autocmd for *.py and one for *.pyi eq(2, #meths.get_autocmds { event = "BufReadPost" }) @@ -127,23 +118,21 @@ describe('autocmd api', function() describe('desc', function() it('can add description to one autocmd', function() - meths.create_autocmd { - event = "BufReadPost", + meths.create_autocmd("BufReadPost", { pattern = "*.py", command = "echo 'Should Not Have Errored'", desc = "Can show description", - } + }) eq("Can show description", meths.get_autocmds { event = "BufReadPost" }[1].desc) end) it('can add description to multiple autocmd', function() - meths.create_autocmd { - event = "BufReadPost", + meths.create_autocmd("BufReadPost", { pattern = {"*.py", "*.pyi"}, command = "echo 'Should Not Have Errored'", desc = "Can show description", - } + }) local aus = meths.get_autocmds { event = "BufReadPost" } eq(2, #aus) @@ -154,12 +143,11 @@ describe('autocmd api', function() pending('script and verbose settings', function() it('marks API client', function() - meths.create_autocmd { - event = "BufReadPost", + meths.create_autocmd("BufReadPost", { pattern = "*.py", command = "echo 'Should Not Have Errored'", desc = "Can show description", - } + }) local aus = meths.get_autocmds { event = "BufReadPost" } eq(1, #aus, aus) @@ -211,8 +199,7 @@ describe('autocmd api', function() command [[au! InsertLeave]] command [[au InsertEnter * :echo "1"]] source [[ - call nvim_create_autocmd(#{ - \ event: "InsertLeave", + call nvim_create_autocmd("InsertLeave", #{ \ command: ":echo 2", \ }) ]] @@ -283,12 +270,11 @@ describe('autocmd api', function() it('raises error for undefined augroup', function() local success, code = unpack(meths.exec_lua([[ return {pcall(function() - vim.api.nvim_create_autocmd { - event = "FileType", + vim.api.nvim_create_autocmd("FileType", { pattern = "*", group = "NotDefined", command = "echo 'hello'", - } + }) end)} ]], {})) @@ -358,14 +344,13 @@ describe('autocmd api', function() it("can trigger builtin autocmds", function() meths.set_var("autocmd_executed", false) - meths.create_autocmd { - event = "BufReadPost", + meths.create_autocmd("BufReadPost", { pattern = "*", command = "let g:autocmd_executed = v:true", - } + }) eq(false, meths.get_var("autocmd_executed")) - meths.do_autocmd { event = "BufReadPost" } + meths.do_autocmd("BufReadPost", {}) eq(true, meths.get_var("autocmd_executed")) end) @@ -373,17 +358,16 @@ describe('autocmd api', function() meths.set_var("buffer_executed", -1) eq(-1, meths.get_var("buffer_executed")) - meths.create_autocmd { - event = "BufLeave", + meths.create_autocmd("BufLeave", { pattern = "*", command = 'let g:buffer_executed = +expand("")', - } + }) -- Doesn't execute for other non-matching events - meths.do_autocmd { event = "CursorHold", buffer = 1 } + meths.do_autocmd("CursorHold", { buffer = 1 }) eq(-1, meths.get_var("buffer_executed")) - meths.do_autocmd { event = "BufLeave", buffer = 1 } + meths.do_autocmd("BufLeave", { buffer = 1 }) eq(1, meths.get_var("buffer_executed")) end) @@ -391,14 +375,13 @@ describe('autocmd api', function() meths.set_var("filename_executed", 'none') eq('none', meths.get_var("filename_executed")) - meths.create_autocmd { - event = "BufEnter", + meths.create_autocmd("BufEnter", { pattern = "*.py", command = 'let g:filename_executed = expand("")', - } + }) -- Doesn't execute for other non-matching events - meths.do_autocmd { event = "CursorHold", buffer = 1 } + meths.do_autocmd("CursorHold", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) meths.command('edit __init__.py') @@ -406,7 +389,7 @@ describe('autocmd api', function() end) it('cannot pass buf and fname', function() - local ok = pcall(meths.do_autocmd, { pattern = "literally_cannot_error.rs", buffer = 1 }) + local ok = pcall(meths.do_autocmd, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) eq(false, ok) end) @@ -418,38 +401,36 @@ describe('autocmd api', function() meths.command('edit __init__.py') eq('none', meths.get_var("filename_executed")) - meths.create_autocmd { - event = "CursorHoldI", + meths.create_autocmd("CursorHoldI", { pattern = "__init__.py", command = 'let g:filename_executed = expand("")', - } + }) -- Doesn't execute for other non-matching events - meths.do_autocmd { event = "CursorHoldI", buffer = 1 } + meths.do_autocmd("CursorHoldI", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) - meths.do_autocmd { event = "CursorHoldI", buffer = tonumber(meths.get_current_buf()) } + meths.do_autocmd("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) eq('__init__.py', meths.get_var("filename_executed")) -- Reset filename meths.set_var("filename_executed", 'none') - meths.do_autocmd { event = "CursorHoldI", pattern = '__init__.py' } + meths.do_autocmd("CursorHoldI", { pattern = '__init__.py' }) eq('__init__.py', meths.get_var("filename_executed")) end) it("works with user autocmds", function() meths.set_var("matched", 'none') - meths.create_autocmd { - event = "User", + meths.create_autocmd("User", { pattern = "TestCommand", command = 'let g:matched = "matched"' - } + }) - meths.do_autocmd { event = "User", pattern = "OtherCommand" } + meths.do_autocmd("User", { pattern = "OtherCommand" }) eq('none', meths.get_var('matched')) - meths.do_autocmd { event = "User", pattern = "TestCommand" } + meths.do_autocmd("User", { pattern = "TestCommand" }) eq('matched', meths.get_var('matched')) end) end) @@ -465,7 +446,6 @@ describe('autocmd api', function() opts = opts or {} local resulting = { - event = "FileType", pattern = "*", command = "let g:executed = g:executed + 1", } @@ -473,7 +453,7 @@ describe('autocmd api', function() resulting.group = opts.group resulting.once = opts.once - meths.create_autocmd(resulting) + meths.create_autocmd("FileType", resulting) end local set_ft = function(ft) @@ -487,7 +467,7 @@ describe('autocmd api', function() it('can be added in a group', function() local augroup = "TestGroup" - meths.create_augroup({ name = augroup, clear = true }) + meths.create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup } set_ft("txt") @@ -516,8 +496,7 @@ describe('autocmd api', function() end) it('errors on unexpected keys', function() - local success, code = pcall(meths.create_autocmd, { - event = "FileType", + local success, code = pcall(meths.create_autocmd, "FileType", { pattern = "*", not_a_valid_key = "NotDefined", }) @@ -530,11 +509,10 @@ describe('autocmd api', function() exec_lua([[ vim.g.executed = false - vim.api.nvim_create_autocmd { - event = "FileType", + vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() vim.g.executed = true end, - } + }) ]], {}) @@ -551,17 +529,15 @@ describe('autocmd api', function() count = count + 1 end - vim.api.nvim_create_autocmd { - event = "FileType", + vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = counter, - } + }) - vim.api.nvim_create_autocmd { - event = "FileType", + vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = counter, - } + }) vim.cmd "set filetype=txt" vim.cmd "set filetype=txt" @@ -579,15 +555,14 @@ describe('autocmd api', function() MyVal = {} WeakTable[MyVal] = true - vim.api.nvim_create_autocmd { - event = "FileType", + vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() OnceCount = OnceCount + 1 MyVal = {} end, once = true - } + }) ]]) command [[set filetype=txt]] @@ -610,10 +585,9 @@ describe('autocmd api', function() it('groups can be cleared', function() local augroup = "TestGroup" - meths.create_augroup({ name = augroup, clear = true }) - meths.create_autocmd({ + meths.create_augroup(augroup, { clear = true }) + meths.create_autocmd("FileType", { group = augroup, - event = "FileType", command = "let g:executed = g:executed + 1" }) @@ -621,7 +595,7 @@ describe('autocmd api', function() set_ft("txt") eq(2, get_executed_count(), "should only count twice") - meths.create_augroup({ name = augroup, clear = true }) + meths.create_augroup(augroup, { clear = true }) eq({}, meths.get_autocmds { group = augroup }) set_ft("txt") @@ -632,7 +606,7 @@ describe('autocmd api', function() it('groups work with once', function() local augroup = "TestGroup" - meths.create_augroup({ name = augroup, clear = true }) + meths.create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup, once = true } set_ft("txt") @@ -644,7 +618,7 @@ describe('autocmd api', function() it('autocmds can be registered multiple times.', function() local augroup = "TestGroup" - meths.create_augroup({ name = augroup, clear = true }) + meths.create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup, once = false } make_counting_autocmd { group = augroup, once = false } make_counting_autocmd { group = augroup, once = false } @@ -658,15 +632,14 @@ describe('autocmd api', function() it('can be deleted', function() local augroup = "WillBeDeleted" - meths.create_augroup({ name = augroup, clear = true }) - meths.create_autocmd { - event = {"Filetype"}, + meths.create_augroup(augroup, { clear = true }) + meths.create_autocmd({"Filetype"}, { pattern = "*", command = "echo 'does not matter'", - } + }) -- Clears the augroup from before, which erases the autocmd - meths.create_augroup({ name = augroup, clear = true }) + meths.create_augroup(augroup, { clear = true }) local result = #meths.get_autocmds { group = augroup } @@ -678,12 +651,11 @@ describe('autocmd api', function() meths.set_var("value_set", false) - meths.create_augroup({ name = augroup, clear = true }) - meths.create_autocmd { - event = "Filetype", + meths.create_augroup(augroup, { clear = true }) + meths.create_autocmd("Filetype", { pattern = "", command = "let g:value_set = v:true", - } + }) command "new" command "set filetype=python" @@ -699,8 +671,7 @@ describe('autocmd api', function() let g:vimscript_executed = g:vimscript_executed + 1 endfunction - call nvim_create_autocmd(#{ - \ event: "Filetype", + call nvim_create_autocmd("FileType", #{ \ pattern: ["python", "javascript"], \ callback: "MyVimscriptFunction", \ }) @@ -773,7 +744,7 @@ describe('autocmd api', function() command('autocmd! BufReadPost *.py :echo "Hello"') command('augroup END') - local augroup_id = meths.create_augroup { name = "TEMP_ABCD", clear = false } + local augroup_id = meths.create_augroup("TEMP_ABCD", { clear = false }) meths.del_augroup_by_id(augroup_id) -- For good reason, we kill all the autocmds from del_augroup, -- cgit From 37a86a2f964b5d6f9dbfae8b78acaa3a71f981bb Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 1 Mar 2022 09:07:41 +0100 Subject: fix(api): include event in get_autocmds (#17553) --- test/functional/api/autocmd_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 32a3db34a3..e50e812b4b 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -217,6 +217,14 @@ describe('autocmd api', function() eq(1, #new_aus) eq(first, new_aus[1]) end) + + it('should return event name', function() + command [[au! InsertEnter]] + command [[au InsertEnter * :echo "1"]] + + local aus = meths.get_autocmds { event = "InsertEnter" } + eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus) + end) end) describe('groups', function() -- cgit From 9a5a3c699eb369eb76f32800012aacec2cb33e0b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 2 Mar 2022 08:14:39 +0800 Subject: test: move two mapping tests to ex_cmds/map_spec.lua --- test/functional/api/keymap_spec.lua | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 6562b40d53..c0edcde476 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -880,24 +880,6 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq("\nn lhs rhs\n map description", helpers.exec_capture("nmap lhs")) end) - - it ('can :filter maps based on description', function() - meths.set_keymap('n', 'asdf1', 'qwert', {desc='do the one thing'}) - meths.set_keymap('n', 'asdf2', 'qwert', {desc='doesnot really do anything'}) - meths.set_keymap('n', 'asdf3', 'qwert', {desc='do the other thing'}) - eq([[ - -n asdf3 qwert - do the other thing -n asdf1 qwert - do the one thing]], - helpers.exec_capture('filter the nmap')) - end) - - it ('shows as map rhs', function() - meths.set_keymap('n', 'asdf', '', {}) - eq('\nn asdf ', helpers.exec_capture('nmap asdf')) - end) end) describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() -- cgit From f8b3a1691faa769c8a57b438eeac8c1cff848444 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 3 Mar 2022 16:07:39 +0800 Subject: test: use helpers.pending_win32(pending) in buffer_updates_spec --- test/functional/api/buffer_updates_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index e9ad756947..fc09e4cde0 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -7,7 +7,6 @@ local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err local sleep = helpers.sleep local write_file = helpers.write_file -local iswin = helpers.iswin local origlines = {"original line 1", "original line 2", @@ -824,11 +823,11 @@ describe('API: buffer events:', function() end msg = next_msg() end - -- FIXME: Windows - assert(iswin(), 'did not match/receive expected nvim_buf_lines_event lines') + assert(false, 'did not match/receive expected nvim_buf_lines_event lines') end it('when :terminal lines change', function() + if helpers.pending_win32(pending) then return end local buffer_lines = {} local expected_lines = {} command('terminal "'..nvim_prog..'" -u NONE -i NONE -n -c "set shortmess+=A"') -- cgit From f89fb41a7a8b499159bfa44afa26dd17a845af45 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 2 Mar 2022 00:48:11 +0300 Subject: feat(tui): add support for `CSI 4 : [2,4,5] m` This commit finishes support for colored and styled underlines adding `CSI 4 : [2,4,5] m` support providing double, dashed, and dotted underlines Fixes #17362. --- test/functional/api/highlight_spec.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 443689754c..06cdb0bc19 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -28,8 +28,11 @@ describe('API: highlight',function() bold = true, italic = true, reverse = true, - undercurl = true, underline = true, + underlineline = true, + undercurl = true, + underdot = true, + underdash = true, strikethrough = true, } @@ -52,7 +55,7 @@ describe('API: highlight',function() eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*')) -- Test all highlight properties. - command('hi NewHighlight gui=underline,bold,undercurl,italic,reverse,strikethrough') + command('hi NewHighlight gui=underline,bold,underlineline,undercurl,underdot,underdash,italic,reverse,strikethrough') eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true)) -- Test nil argument. @@ -195,6 +198,9 @@ describe("API: set highlight", function() reverse = true, undercurl = true, underline = true, + underdash = true, + underdot = true, + underlineline = true, strikethrough = true, cterm = { italic = true, @@ -211,6 +217,9 @@ describe("API: set highlight", function() reverse = true, undercurl = true, underline = true, + underdash = true, + underdot = true, + underlineline = true, strikethrough = true, } local highlight3_result_cterm = { @@ -274,7 +283,7 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl')) meths.set_hl(0, 'Test_hl2', highlight3_config) - eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa', + eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,underlineline,undercurl,underdot,underdash,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2')) -- Colors are stored exactly as they are defined. -- cgit From 92349b1db0039aac3a43089d0aade2437164505c Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sun, 6 Mar 2022 12:35:14 -0700 Subject: feat(api): add 'buffer' argument to nvim_get_autocmds (#17594) This enables retrieving autocommands defined in the given buffers. Under the hood this simply translates the buffer numbers into '' patterns. --- test/functional/api/autocmd_spec.lua | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index e50e812b4b..e8dc284925 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -8,6 +8,7 @@ local exec_lua = helpers.exec_lua local matches = helpers.matches local meths = helpers.meths local source = helpers.source +local pcall_err = helpers.pcall_err before_each(clear) @@ -225,6 +226,61 @@ describe('autocmd api', function() local aus = meths.get_autocmds { event = "InsertEnter" } eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus) end) + + it('should work with buffer numbers', function() + command [[new]] + command [[au! InsertEnter]] + command [[au InsertEnter :echo "1"]] + command [[au InsertEnter :echo "2"]] + + local aus = meths.get_autocmds { event = "InsertEnter", buffer = 0 } + eq({{ + buffer = 2, + buflocal = true, + command = ':echo "2"', + event = 'InsertEnter', + once = false, + pattern = '', + }}, aus) + + aus = meths.get_autocmds { event = "InsertEnter", buffer = 1 } + eq({{ + buffer = 1, + buflocal = true, + command = ':echo "1"', + event = "InsertEnter", + once = false, + pattern = "", + }}, aus) + + aus = meths.get_autocmds { event = "InsertEnter", buffer = { 1, 2 } } + eq({{ + buffer = 1, + buflocal = true, + command = ':echo "1"', + event = "InsertEnter", + once = false, + pattern = "", + }, { + buffer = 2, + buflocal = true, + command = ':echo "2"', + event = "InsertEnter", + once = false, + pattern = "", + }}, aus) + + eq("Invalid value for 'buffer': must be an integer or array of integers", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) + eq("Invalid value for 'buffer': must be an integer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) + eq("Invalid buffer id: 42", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { 42 } })) + + local bufs = {} + for _ = 1, 257 do + table.insert(bufs, meths.create_buf(true, false)) + end + + eq("Too many buffers. Please limit yourself to 256 or fewer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) + end) end) describe('groups', function() -- cgit From 2783f4cc4a410cd3b73e8cdfbdf8c859c426c6c6 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Tue, 8 Mar 2022 09:45:43 +0530 Subject: feat(api): autocmd `group` can be either name or id (#17559) * feat(api): `group` can be either string or int This affects the following API functions: - `vim.api.nvim_create_autocmd` - `vim.api.nvim_get_autocmds` - `vim.api.nvim_do_autocmd` closes #17552 * refactor: add two maps for fast lookups * fix: delete augroup info from id->name map When in "stupid_legacy_mode", the value in name->id map would be updated to `AUGROUP_DELETED`, but the entry would still remain in id->name. This would create a problem in `augroup_name` function which would return the name of the augroup instead of `--DELETED--`. The id->name map is only used for fast loopup in `augroup_name` function so there's no point in keeping the entry of deleted augroup in it. Co-authored-by: TJ DeVries --- test/functional/api/autocmd_spec.lua | 89 +++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index e8dc284925..372cbf2c30 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -281,6 +281,31 @@ describe('autocmd api', function() eq("Too many buffers. Please limit yourself to 256 or fewer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) end) + + it('should return autocmds when group is specified by id', function() + local auid = meths.create_augroup("nvim_test_augroup", { clear = true }) + meths.create_autocmd("FileType", { group = auid, command = 'echo "1"' }) + meths.create_autocmd("FileType", { group = auid, command = 'echo "2"' }) + + local aus = meths.get_autocmds { group = auid } + eq(2, #aus) + + local aus2 = meths.get_autocmds { group = auid, event = "InsertEnter" } + eq(0, #aus2) + end) + + it('should return autocmds when group is specified by name', function() + local auname = "nvim_test_augroup" + meths.create_augroup(auname, { clear = true }) + meths.create_autocmd("FileType", { group = auname, command = 'echo "1"' }) + meths.create_autocmd("FileType", { group = auname, command = 'echo "2"' }) + + local aus = meths.get_autocmds { group = auname } + eq(2, #aus) + + local aus2 = meths.get_autocmds { group = auname, event = "InsertEnter" } + eq(0, #aus2) + end) end) describe('groups', function() @@ -331,7 +356,7 @@ describe('autocmd api', function() end) describe('groups: 2', function() - it('raises error for undefined augroup', function() + it('raises error for undefined augroup name', function() local success, code = unpack(meths.exec_lua([[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { @@ -345,6 +370,39 @@ describe('autocmd api', function() eq(false, success) matches('invalid augroup: NotDefined', code) end) + + it('raises error for undefined augroup id', function() + local success, code = unpack(meths.exec_lua([[ + return {pcall(function() + -- Make sure the augroup is deleted + vim.api.nvim_del_augroup_by_id(1) + + vim.api.nvim_create_autocmd("FileType", { + pattern = "*", + group = 1, + command = "echo 'hello'", + }) + end)} + ]], {})) + + eq(false, success) + matches('invalid augroup: 1', code) + end) + + it('raises error for invalid group type', function() + local success, code = unpack(meths.exec_lua([[ + return {pcall(function() + vim.api.nvim_create_autocmd("FileType", { + pattern = "*", + group = true, + command = "echo 'hello'", + }) + end)} + ]], {})) + + eq(false, success) + matches("'group' must be a string or an integer", code) + end) end) describe('patterns', function() @@ -497,6 +555,35 @@ describe('autocmd api', function() meths.do_autocmd("User", { pattern = "TestCommand" }) eq('matched', meths.get_var('matched')) end) + + it('can pass group by id', function() + meths.set_var("group_executed", false) + + local auid = meths.create_augroup("nvim_test_augroup", { clear = true }) + meths.create_autocmd("FileType", { + group = auid, + command = 'let g:group_executed = v:true', + }) + + eq(false, meths.get_var("group_executed")) + meths.do_autocmd("FileType", { group = auid }) + eq(true, meths.get_var("group_executed")) + end) + + it('can pass group by name', function() + meths.set_var("group_executed", false) + + local auname = "nvim_test_augroup" + meths.create_augroup(auname, { clear = true }) + meths.create_autocmd("FileType", { + group = auname, + command = 'let g:group_executed = v:true', + }) + + eq(false, meths.get_var("group_executed")) + meths.do_autocmd("FileType", { group = auname }) + eq(true, meths.get_var("group_executed")) + end) end) describe('nvim_create_augroup', function() -- cgit From 3011794c8600f529bc049983a64ca99ae03908df Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Mar 2022 07:18:49 +0800 Subject: feat(api): relax statusline fillchar width check Treat fillchar as single-width even if it isn't. --- test/functional/api/vim_spec.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 71cd055e08..e945a6c706 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2621,24 +2621,24 @@ describe('API', function() eq({ str = 'a━━━b', width = 5 }, meths.eval_statusline('a%=b', { fillchar = '━', maxwidth = 5 })) end) - it('rejects double-width fillchar', function() - eq('fillchar must be a single-width character', - pcall_err(meths.eval_statusline, '', { fillchar = '哦' })) + it('treats double-width fillchar as single-width', function() + eq({ str = 'a哦哦哦b', width = 5 }, + meths.eval_statusline('a%=b', { fillchar = '哦', maxwidth = 5 })) end) - it('rejects control character fillchar', function() - eq('fillchar must be a single-width character', - pcall_err(meths.eval_statusline, '', { fillchar = '\a' })) + it('treats control character fillchar as single-width', function() + eq({ str = 'a\031\031\031b', width = 5 }, + meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 })) end) it('rejects multiple-character fillchar', function() - eq('fillchar must be a single-width character', + eq('fillchar must be a single character', pcall_err(meths.eval_statusline, '', { fillchar = 'aa' })) end) it('rejects empty string fillchar', function() - eq('fillchar must be a single-width character', + eq('fillchar must be a single character', pcall_err(meths.eval_statusline, '', { fillchar = '' })) end) it('rejects non-string fillchar', function() - eq('fillchar must be a single-width character', + eq('fillchar must be a single character', pcall_err(meths.eval_statusline, '', { fillchar = 1 })) end) describe('highlight parsing', function() -- cgit From 9b1e1fbc9f795921afd25ba38be5c79dec8b04d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: fix(paste): use getcmdtype() to determine whether in cmdline mode --- test/functional/api/vim_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e945a6c706..384e8d11f2 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -738,6 +738,12 @@ describe('API', function() eeffgghh iijjkkll]]) end) + it('when searching in Visual mode', function() + feed('v/') + nvim('paste', 'aabbccdd', true, -1) + eq('aabbccdd', funcs.getcmdline()) + expect('') + end) it('crlf=false does not break lines at CR, CRLF', function() nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') -- cgit From 2601e0873ff50ed804487dff00bd27e233709beb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: fix(paste): don't move cursor past the end of pasted text in Normal mode --- test/functional/api/vim_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 384e8d11f2..3d57953a11 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -665,6 +665,43 @@ describe('API', function() feed('u') -- Undo. expect(expected1) end) + it('stream: Insert mode', function() + feed('i') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('aaaaaabbbbbbccccccdddddd') + end) + it('stream: Normal mode on empty line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('aaaaaabbbbbbccccccdddddd') + feed('u') + expect('') + end) + it('stream: Normal mode not at the end of a line', function() + feed('i||0') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|aaaaaabbbbbbccccccdddddd|') + feed('u') + expect('||') + end) + it('stream: Normal mode at the end of a line', function() + feed('i||') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + feed('u') + expect('||') + end) it('non-streaming', function() -- With final "\n". nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) -- cgit From bfb77544425b7cca372cb87f00ef6b6e87c5f6d5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: fix(paste): deal with eol and eof in Visual mode --- test/functional/api/vim_spec.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3d57953a11..eaee9211f4 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -702,6 +702,42 @@ describe('API', function() feed('u') expect('||') end) + it('stream: Visual mode either end not at the end of a line', function() + feed('i|xxxxxx|hvhk') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|aaaaaabbbbbbccccccdddddd|') + feed('u') + expect([[ + |xxx + xxx|]]) + end) + it('stream: Visual mode cursor at the end of a line', function() + feed('i||xxxxxxvko') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + feed('u') + expect([[ + ||xxx + xxx]]) + end) + it('stream: Visual mode other end at the end of a line', function() + feed('i||xxxxxxvk') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + feed('u') + expect([[ + ||xxx + xxx]]) + end) it('non-streaming', function() -- With final "\n". nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) -- cgit From fcc6f66cf2a67cf85e72727a08e19d0f800badb9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: fix(paste): avoid edges cases caused by empty chunk --- test/functional/api/vim_spec.lua | 67 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index eaee9211f4..761cbb4036 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -630,6 +630,10 @@ describe('API', function() end) describe('nvim_paste', function() + before_each(function() + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('ifoou') + end) it('validates args', function() eq('Invalid phase: -2', pcall_err(request, 'nvim_paste', 'foo', true, -2)) @@ -702,7 +706,7 @@ describe('API', function() feed('u') expect('||') end) - it('stream: Visual mode either end not at the end of a line', function() + it('stream: Visual mode neither end at the end of a line', function() feed('i|xxxxxx|hvhk') nvim('paste', 'aaaaaa', false, 1) nvim('paste', 'bbbbbb', false, 2) @@ -714,6 +718,30 @@ describe('API', function() |xxx xxx|]]) end) + it('stream: Visual mode neither end at the end of a line with empty first chunk', function() + feed('i|xxxxxx|hvhk') + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|bbbbbbccccccdddddd|') + feed('u') + expect([[ + |xxx + xxx|]]) + end) + it('stream: Visual mode neither end at the end of a line with all chunks empty', function() + feed('i|xxxxxx|hvhk') + nvim('paste', '', false, 1) + nvim('paste', '', false, 2) + nvim('paste', '', false, 2) + nvim('paste', '', false, 3) + expect('||') + feed('u') + expect([[ + |xxx + xxx|]]) + end) it('stream: Visual mode cursor at the end of a line', function() feed('i||xxxxxxvko') nvim('paste', 'aaaaaa', false, 1) @@ -726,6 +754,18 @@ describe('API', function() ||xxx xxx]]) end) + it('stream: Visual mode cursor at the end of a line with empty first chunk', function() + feed('i||xxxxxxvko') + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + feed('u') + expect([[ + ||xxx + xxx]]) + end) it('stream: Visual mode other end at the end of a line', function() feed('i||xxxxxxvk') nvim('paste', 'aaaaaa', false, 1) @@ -738,6 +778,18 @@ describe('API', function() ||xxx xxx]]) end) + it('stream: Visual mode other end at the end of a line with empty first chunk', function() + feed('i||xxxxxxvk') + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + feed('u') + expect([[ + ||xxx + xxx]]) + end) it('non-streaming', function() -- With final "\n". nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) @@ -817,6 +869,19 @@ describe('API', function() eq('aabbccdd', funcs.getcmdline()) expect('') end) + it('pasting with empty last chunk in Cmdline mode', function() + local screen = Screen.new(20, 4) + screen:attach() + feed(':') + nvim('paste', 'Foo', true, 1) + nvim('paste', '', true, 3) + screen:expect([[ + | + ~ | + ~ | + :Foo^ | + ]]) + end) it('crlf=false does not break lines at CR, CRLF', function() nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') -- cgit From a6eafc77ceaf2d7036aed89361b6556f46131b17 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: fix(paste): deal with trailing new line in chunk --- test/functional/api/vim_spec.lua | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 761cbb4036..9818746251 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -686,6 +686,19 @@ describe('API', function() feed('u') expect('') end) + it('stream: Normal mode on empty line pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd]]) + feed('u') + expect('') + end) it('stream: Normal mode not at the end of a line', function() feed('i||0') nvim('paste', 'aaaaaa', false, 1) @@ -696,6 +709,20 @@ describe('API', function() feed('u') expect('||') end) + it('stream: Normal mode not at the end of a line pasting multiple lines', function() + feed('i||0') + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + |aaaaaa + bbbbbb + cccccc + dddddd|]]) + feed('u') + expect('||') + end) it('stream: Normal mode at the end of a line', function() feed('i||') nvim('paste', 'aaaaaa', false, 1) @@ -706,6 +733,20 @@ describe('API', function() feed('u') expect('||') end) + it('stream: Normal mode at the end of a line pasting multiple lines', function() + feed('i||') + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + ||aaaaaa + bbbbbb + cccccc + dddddd]]) + feed('u') + expect('||') + end) it('stream: Visual mode neither end at the end of a line', function() feed('i|xxxxxx|hvhk') nvim('paste', 'aaaaaa', false, 1) -- cgit From e4ec8d7d5001ff15a7a844a6f74d4a9c090ac5c6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: test(paste): reorganize tests and add tests for linewise Visual mode --- test/functional/api/vim_spec.lua | 471 ++++++++++++++++++++++++++------------- 1 file changed, 317 insertions(+), 154 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 9818746251..263add599c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -630,10 +630,6 @@ describe('API', function() end) describe('nvim_paste', function() - before_each(function() - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('ifoou') - end) it('validates args', function() eq('Invalid phase: -2', pcall_err(request, 'nvim_paste', 'foo', true, -2)) @@ -670,166 +666,333 @@ describe('API', function() expect(expected1) end) it('stream: Insert mode', function() + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') feed('i') nvim('paste', 'aaaaaa', false, 1) nvim('paste', 'bbbbbb', false, 2) nvim('paste', 'cccccc', false, 2) nvim('paste', 'dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') - end) - it('stream: Normal mode on empty line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('aaaaaabbbbbbccccccdddddd') - feed('u') - expect('') - end) - it('stream: Normal mode on empty line pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - aaaaaa - bbbbbb - cccccc - dddddd]]) - feed('u') + feed('u') expect('') end) - it('stream: Normal mode not at the end of a line', function() - feed('i||0') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('|aaaaaabbbbbbccccccdddddd|') - feed('u') - expect('||') - end) - it('stream: Normal mode not at the end of a line pasting multiple lines', function() - feed('i||0') - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - |aaaaaa - bbbbbb - cccccc - dddddd|]]) - feed('u') - expect('||') - end) - it('stream: Normal mode at the end of a line', function() - feed('i||') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||aaaaaabbbbbbccccccdddddd') - feed('u') - expect('||') - end) - it('stream: Normal mode at the end of a line pasting multiple lines', function() - feed('i||') - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - ||aaaaaa - bbbbbb - cccccc - dddddd]]) - feed('u') - expect('||') - end) - it('stream: Visual mode neither end at the end of a line', function() - feed('i|xxxxxx|hvhk') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('|aaaaaabbbbbbccccccdddddd|') - feed('u') - expect([[ - |xxx - xxx|]]) - end) - it('stream: Visual mode neither end at the end of a line with empty first chunk', function() - feed('i|xxxxxx|hvhk') - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('|bbbbbbccccccdddddd|') - feed('u') - expect([[ - |xxx - xxx|]]) - end) - it('stream: Visual mode neither end at the end of a line with all chunks empty', function() - feed('i|xxxxxx|hvhk') - nvim('paste', '', false, 1) - nvim('paste', '', false, 2) - nvim('paste', '', false, 2) - nvim('paste', '', false, 3) - expect('||') - feed('u') - expect([[ - |xxx - xxx|]]) - end) - it('stream: Visual mode cursor at the end of a line', function() - feed('i||xxxxxxvko') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||aaaaaabbbbbbccccccdddddd') - feed('u') - expect([[ - ||xxx - xxx]]) - end) - it('stream: Visual mode cursor at the end of a line with empty first chunk', function() - feed('i||xxxxxxvko') - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||bbbbbbccccccdddddd') - feed('u') - expect([[ - ||xxx - xxx]]) + describe('stream: Normal mode', function() + describe('on empty line', function() + before_each(function() + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + end) + after_each(function() + feed('u') + expect('') + end) + it('pasting one line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('aaaaaabbbbbbccccccdddddd') + end) + it('pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd]]) + end) + end) + describe('not at the end of a line', function() + before_each(function() + feed('i||') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('0') + end) + after_each(function() + feed('u') + expect('||') + end) + it('pasting one line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|aaaaaabbbbbbccccccdddddd|') + end) + it('pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + |aaaaaa + bbbbbb + cccccc + dddddd|]]) + end) + end) + describe('at the end of a line', function() + before_each(function() + feed('i||') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('$') + end) + after_each(function() + feed('u') + expect('||') + end) + it('pasting one line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + end) + it('pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + ||aaaaaa + bbbbbb + cccccc + dddddd]]) + end) + end) end) - it('stream: Visual mode other end at the end of a line', function() - feed('i||xxxxxxvk') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||aaaaaabbbbbbccccccdddddd') - feed('u') - expect([[ - ||xxx - xxx]]) + describe('stream: Visual mode', function() + describe('neither end at the end of a line', function() + before_each(function() + feed('i|xxxxxx|') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('hvhk') + end) + after_each(function() + feed('u') + expect([[ + |xxx + xxx|]]) + end) + it('with non-empty chunks', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|aaaaaabbbbbbccccccdddddd|') + end) + it('with empty first chunk', function() + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|bbbbbbccccccdddddd|') + end) + it('with all chunks empty', function() + nvim('paste', '', false, 1) + nvim('paste', '', false, 2) + nvim('paste', '', false, 2) + nvim('paste', '', false, 3) + expect('||') + end) + end) + describe('cursor at the end of a line', function() + before_each(function() + feed('i||xxxxxx') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('vko') + end) + after_each(function() + feed('u') + expect([[ + ||xxx + xxx]]) + end) + it('with non-empty chunks', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + end) + it('with empty first chunk', function() + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + end) + end) + describe('other end at the end of a line', function() + before_each(function() + feed('i||xxxxxx') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('vk') + end) + after_each(function() + feed('u') + expect([[ + ||xxx + xxx]]) + end) + it('with non-empty chunks', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + end) + it('with empty first chunk', function() + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + end) + end) end) - it('stream: Visual mode other end at the end of a line with empty first chunk', function() - feed('i||xxxxxxvk') - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||bbbbbbccccccdddddd') - feed('u') - expect([[ - ||xxx - xxx]]) + describe('stream: linewise Visual mode', function() + before_each(function() + feed('i123456789987654321123456789') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + end) + after_each(function() + feed('u') + expect([[ + 123456789 + 987654321 + 123456789]]) + end) + describe('selecting the start of a file', function() + before_each(function() + feed('ggV') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd987654321 + 123456789]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd + 987654321 + 123456789]]) + end) + end) + describe('selecting the middle of a file', function() + before_each(function() + feed('2ggV') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + 123456789 + aaaaaa + bbbbbb + cccccc + dddddd123456789]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + 123456789 + aaaaaa + bbbbbb + cccccc + dddddd + 123456789]]) + end) + end) + describe('selecting the end of a file', function() + before_each(function() + feed('3ggV') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + 123456789 + 987654321 + aaaaaa + bbbbbb + cccccc + dddddd]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + 123456789 + 987654321 + aaaaaa + bbbbbb + cccccc + dddddd + ]]) + end) + end) + describe('selecting the whole file', function() + before_each(function() + feed('ggVG') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd + ]]) + end) + end) end) it('non-streaming', function() -- With final "\n". -- cgit From 3470a9c3de076ec3170525c3de66544f9836c775 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Mar 2022 06:56:24 +0800 Subject: test(paste): add tests with virtualedit=onemore --- test/functional/api/vim_spec.lua | 667 ++++++++++++++++++++------------------- 1 file changed, 339 insertions(+), 328 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 263add599c..f4a7d38d31 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -636,363 +636,374 @@ describe('API', function() eq('Invalid phase: 4', pcall_err(request, 'nvim_paste', 'foo', true, 4)) end) - it('stream: multiple chunks form one undo-block', function() - nvim('paste', '1/chunk 1 (start)\n', true, 1) - nvim('paste', '1/chunk 2 (end)\n', true, 3) - local expected1 = [[ - 1/chunk 1 (start) - 1/chunk 2 (end) - ]] - expect(expected1) - nvim('paste', '2/chunk 1 (start)\n', true, 1) - nvim('paste', '2/chunk 2\n', true, 2) - expect([[ - 1/chunk 1 (start) - 1/chunk 2 (end) - 2/chunk 1 (start) - 2/chunk 2 - ]]) - nvim('paste', '2/chunk 3\n', true, 2) - nvim('paste', '2/chunk 4 (end)\n', true, 3) - expect([[ - 1/chunk 1 (start) - 1/chunk 2 (end) - 2/chunk 1 (start) - 2/chunk 2 - 2/chunk 3 - 2/chunk 4 (end) - ]]) - feed('u') -- Undo. - expect(expected1) - end) - it('stream: Insert mode', function() - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - feed('i') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('aaaaaabbbbbbccccccdddddd') - feed('u') - expect('') - end) - describe('stream: Normal mode', function() - describe('on empty line', function() - before_each(function() - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - end) - after_each(function() - feed('u') - expect('') - end) - it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('aaaaaabbbbbbccccccdddddd') - end) - it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - aaaaaa - bbbbbb - cccccc - dddddd]]) - end) + local function run_streamed_paste_tests() + it('stream: multiple chunks form one undo-block', function() + nvim('paste', '1/chunk 1 (start)\n', true, 1) + nvim('paste', '1/chunk 2 (end)\n', true, 3) + local expected1 = [[ + 1/chunk 1 (start) + 1/chunk 2 (end) + ]] + expect(expected1) + nvim('paste', '2/chunk 1 (start)\n', true, 1) + nvim('paste', '2/chunk 2\n', true, 2) + expect([[ + 1/chunk 1 (start) + 1/chunk 2 (end) + 2/chunk 1 (start) + 2/chunk 2 + ]]) + nvim('paste', '2/chunk 3\n', true, 2) + nvim('paste', '2/chunk 4 (end)\n', true, 3) + expect([[ + 1/chunk 1 (start) + 1/chunk 2 (end) + 2/chunk 1 (start) + 2/chunk 2 + 2/chunk 3 + 2/chunk 4 (end) + ]]) + feed('u') -- Undo. + expect(expected1) end) - describe('not at the end of a line', function() - before_each(function() - feed('i||') - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - feed('0') - end) - after_each(function() - feed('u') - expect('||') - end) - it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('|aaaaaabbbbbbccccccdddddd|') - end) - it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - |aaaaaa - bbbbbb - cccccc - dddddd|]]) - end) + it('stream: Insert mode', function() + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('i') + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('aaaaaabbbbbbccccccdddddd') + feed('u') + expect('') end) - describe('at the end of a line', function() - before_each(function() - feed('i||') - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - feed('$') - end) - after_each(function() - feed('u') - expect('||') - end) - it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||aaaaaabbbbbbccccccdddddd') - end) - it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - ||aaaaaa + describe('stream: Normal mode', function() + describe('on empty line', function() + before_each(function() + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + end) + after_each(function() + feed('u') + expect('') + end) + it('pasting one line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('aaaaaabbbbbbccccccdddddd') + end) + it('pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa bbbbbb cccccc dddddd]]) + end) end) - end) - end) - describe('stream: Visual mode', function() - describe('neither end at the end of a line', function() - before_each(function() - feed('i|xxxxxx|') - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - feed('hvhk') - end) - after_each(function() - feed('u') - expect([[ - |xxx - xxx|]]) - end) - it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('|aaaaaabbbbbbccccccdddddd|') - end) - it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('|bbbbbbccccccdddddd|') + describe('not at the end of a line', function() + before_each(function() + feed('i||') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('0') + end) + after_each(function() + feed('u') + expect('||') + end) + it('pasting one line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|aaaaaabbbbbbccccccdddddd|') + end) + it('pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + |aaaaaa + bbbbbb + cccccc + dddddd|]]) + end) end) - it('with all chunks empty', function() - nvim('paste', '', false, 1) - nvim('paste', '', false, 2) - nvim('paste', '', false, 2) - nvim('paste', '', false, 3) - expect('||') + describe('at the end of a line', function() + before_each(function() + feed('i||') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('2|') + end) + after_each(function() + feed('u') + expect('||') + end) + it('pasting one line', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + end) + it('pasting multiple lines', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + ||aaaaaa + bbbbbb + cccccc + dddddd]]) + end) end) end) - describe('cursor at the end of a line', function() - before_each(function() - feed('i||xxxxxx') - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - feed('vko') - end) - after_each(function() - feed('u') - expect([[ - ||xxx - xxx]]) + describe('stream: Visual mode', function() + describe('neither end at the end of a line', function() + before_each(function() + feed('i|xxxxxx|') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('3|vhk') + end) + after_each(function() + feed('u') + expect([[ + |xxx + xxx|]]) + end) + it('with non-empty chunks', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|aaaaaabbbbbbccccccdddddd|') + end) + it('with empty first chunk', function() + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|bbbbbbccccccdddddd|') + end) + it('with all chunks empty', function() + nvim('paste', '', false, 1) + nvim('paste', '', false, 2) + nvim('paste', '', false, 2) + nvim('paste', '', false, 3) + expect('||') + end) end) - it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||aaaaaabbbbbbccccccdddddd') + describe('cursor at the end of a line', function() + before_each(function() + feed('i||xxxxxx') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('3|vko') + end) + after_each(function() + feed('u') + expect([[ + ||xxx + xxx]]) + end) + it('with non-empty chunks', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + end) + it('with empty first chunk', function() + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + end) end) - it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||bbbbbbccccccdddddd') + describe('other end at the end of a line', function() + before_each(function() + feed('i||xxxxxx') + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('afoou') + feed('3|vk') + end) + after_each(function() + feed('u') + expect([[ + ||xxx + xxx]]) + end) + it('with non-empty chunks', function() + nvim('paste', 'aaaaaa', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||aaaaaabbbbbbccccccdddddd') + end) + it('with empty first chunk', function() + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + end) end) end) - describe('other end at the end of a line', function() + describe('stream: linewise Visual mode', function() before_each(function() - feed('i||xxxxxx') + feed('i123456789987654321123456789') -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. feed('afoou') - feed('vk') end) after_each(function() feed('u') expect([[ - ||xxx - xxx]]) - end) - it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||aaaaaabbbbbbccccccdddddd') - end) - it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) - expect('||bbbbbbccccccdddddd') - end) - end) - end) - describe('stream: linewise Visual mode', function() - before_each(function() - feed('i123456789987654321123456789') - -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. - feed('afoou') - end) - after_each(function() - feed('u') - expect([[ - 123456789 - 987654321 - 123456789]]) - end) - describe('selecting the start of a file', function() - before_each(function() - feed('ggV') - end) - it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - aaaaaa - bbbbbb - cccccc - dddddd987654321 - 123456789]]) - end) - it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) - expect([[ - aaaaaa - bbbbbb - cccccc - dddddd + 123456789 987654321 123456789]]) end) - end) - describe('selecting the middle of a file', function() - before_each(function() - feed('2ggV') + describe('selecting the start of a file', function() + before_each(function() + feed('ggV') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd987654321 + 123456789]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd + 987654321 + 123456789]]) + end) end) - it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - 123456789 - aaaaaa - bbbbbb - cccccc - dddddd123456789]]) + describe('selecting the middle of a file', function() + before_each(function() + feed('2ggV') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + 123456789 + aaaaaa + bbbbbb + cccccc + dddddd123456789]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + 123456789 + aaaaaa + bbbbbb + cccccc + dddddd + 123456789]]) + end) end) - it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) - expect([[ - 123456789 - aaaaaa - bbbbbb - cccccc - dddddd - 123456789]]) + describe('selecting the end of a file', function() + before_each(function() + feed('3ggV') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + 123456789 + 987654321 + aaaaaa + bbbbbb + cccccc + dddddd]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + 123456789 + 987654321 + aaaaaa + bbbbbb + cccccc + dddddd + ]]) + end) end) - end) - describe('selecting the end of a file', function() - before_each(function() - feed('3ggV') - end) - it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - 123456789 - 987654321 - aaaaaa - bbbbbb - cccccc - dddddd]]) - end) - it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) - expect([[ - 123456789 - 987654321 - aaaaaa - bbbbbb - cccccc - dddddd - ]]) + describe('selecting the whole file', function() + before_each(function() + feed('ggVG') + end) + it('pasting text without final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd]]) + end) + it('pasting text with final new line', function() + nvim('paste', 'aaaaaa\n', false, 1) + nvim('paste', 'bbbbbb\n', false, 2) + nvim('paste', 'cccccc\n', false, 2) + nvim('paste', 'dddddd\n', false, 3) + expect([[ + aaaaaa + bbbbbb + cccccc + dddddd + ]]) + end) end) end) - describe('selecting the whole file', function() - before_each(function() - feed('ggVG') - end) - it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) - expect([[ - aaaaaa - bbbbbb - cccccc - dddddd]]) - end) - it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) - expect([[ - aaaaaa - bbbbbb - cccccc - dddddd - ]]) - end) + end + describe('without virtualedit,', function() + run_streamed_paste_tests() + end) + describe('with virtualedit=onemore,', function() + before_each(function() + command('set virtualedit=onemore') end) + run_streamed_paste_tests() end) it('non-streaming', function() -- With final "\n". -- cgit From e263afc0e972d11d3b9b663c3ac0b5575c4deb88 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Mar 2022 06:04:50 +0800 Subject: fix(paste): escape control characters in Cmdline mode --- test/functional/api/vim_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index f4a7d38d31..af6872760a 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1097,6 +1097,18 @@ describe('API', function() :Foo^ | ]]) end) + it('pasting text with control characters in Cmdline mode', function() + local screen = Screen.new(20, 4) + screen:attach() + feed(':') + nvim('paste', 'normal! \023\022\006\027', true, -1) + screen:expect([[ + | + ~ | + ~ | + :normal! ^W^V^F^[^ | + ]]) + end) it('crlf=false does not break lines at CR, CRLF', function() nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') -- cgit From 77eb6f9dc75ebe00aa835441ad623ba46d7108bb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Mar 2022 08:08:50 +0800 Subject: fix(api, lua): return NIL on failure to find converted function (#17779) --- test/functional/api/vim_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index af6872760a..ed9d915954 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -6,6 +6,7 @@ local assert_alive = helpers.assert_alive local NIL = helpers.NIL local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq local command = helpers.command +local exec = helpers.exec local eval = helpers.eval local expect = helpers.expect local funcs = helpers.funcs @@ -1271,6 +1272,17 @@ describe('API', function() eq('Key is locked: lua', pcall_err(meths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1)) + exec([[ + function Test() + endfunction + function s:Test() + endfunction + let g:Unknown_func = function('Test') + let g:Unknown_script_func = function('s:Test') + ]]) + eq(NIL, meths.get_var('Unknown_func')) + eq(NIL, meths.get_var('Unknown_script_func')) + -- Check if autoload works properly local pathsep = helpers.get_pathsep() local xconfig = 'Xhome' .. pathsep .. 'Xconfig' -- cgit From be35d3c5ad501abb029279f8e1812d0e4525284f Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sat, 19 Mar 2022 18:57:58 -0600 Subject: feat(api): remove Lua autocommand callbacks when they return true (#17784) This copies the semantics of nvim_buf_attach callbacks, and is a convenient way to create oneshot autocommands gated by some condition. --- test/functional/api/autocmd_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 372cbf2c30..a58ca00a75 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -154,6 +154,34 @@ describe('autocmd api', function() eq(1, #aus, aus) end) end) + + it('removes an autocommand if the callback returns true', function() + meths.set_var("some_condition", false) + + exec_lua [[ + vim.api.nvim_create_autocmd("User", { + pattern = "Test", + desc = "A test autocommand", + callback = function() + return vim.g.some_condition + end, + }) + ]] + + meths.do_autocmd("User", {pattern = "Test"}) + eq({{ + buflocal = false, + command = 'A test autocommand', + desc = 'A test autocommand', + event = 'User', + id = 1, + once = false, + pattern = 'Test', + }}, meths.get_autocmds({event = "User", pattern = "Test"})) + meths.set_var("some_condition", true) + meths.do_autocmd("User", {pattern = "Test"}) + eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) + end) end) describe('nvim_get_autocmds', function() -- cgit From a490db5ba819218e9188cbb51d885dbf3a194000 Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Sat, 26 Mar 2022 09:34:56 -0500 Subject: refactor!: rename nvim_do_autocmd to nvim_exec_autocmd (#17854) according to established code standards (`:h dev-api`) --- test/functional/api/autocmd_spec.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index a58ca00a75..3b14ae9bf7 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -168,7 +168,7 @@ describe('autocmd api', function() }) ]] - meths.do_autocmd("User", {pattern = "Test"}) + meths.exec_autocmd("User", {pattern = "Test"}) eq({{ buflocal = false, command = 'A test autocommand', @@ -179,7 +179,7 @@ describe('autocmd api', function() pattern = 'Test', }}, meths.get_autocmds({event = "User", pattern = "Test"})) meths.set_var("some_condition", true) - meths.do_autocmd("User", {pattern = "Test"}) + meths.exec_autocmd("User", {pattern = "Test"}) eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) end) end) @@ -490,7 +490,7 @@ describe('autocmd api', function() end) end) - describe('nvim_do_autocmd', function() + describe('nvim_exec_autocmd', function() it("can trigger builtin autocmds", function() meths.set_var("autocmd_executed", false) @@ -500,7 +500,7 @@ describe('autocmd api', function() }) eq(false, meths.get_var("autocmd_executed")) - meths.do_autocmd("BufReadPost", {}) + meths.exec_autocmd("BufReadPost", {}) eq(true, meths.get_var("autocmd_executed")) end) @@ -514,10 +514,10 @@ describe('autocmd api', function() }) -- Doesn't execute for other non-matching events - meths.do_autocmd("CursorHold", { buffer = 1 }) + meths.exec_autocmd("CursorHold", { buffer = 1 }) eq(-1, meths.get_var("buffer_executed")) - meths.do_autocmd("BufLeave", { buffer = 1 }) + meths.exec_autocmd("BufLeave", { buffer = 1 }) eq(1, meths.get_var("buffer_executed")) end) @@ -531,7 +531,7 @@ describe('autocmd api', function() }) -- Doesn't execute for other non-matching events - meths.do_autocmd("CursorHold", { buffer = 1 }) + meths.exec_autocmd("CursorHold", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) meths.command('edit __init__.py') @@ -539,7 +539,7 @@ describe('autocmd api', function() end) it('cannot pass buf and fname', function() - local ok = pcall(meths.do_autocmd, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) + local ok = pcall(meths.exec_autocmd, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) eq(false, ok) end) @@ -557,16 +557,16 @@ describe('autocmd api', function() }) -- Doesn't execute for other non-matching events - meths.do_autocmd("CursorHoldI", { buffer = 1 }) + meths.exec_autocmd("CursorHoldI", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) - meths.do_autocmd("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) + meths.exec_autocmd("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) eq('__init__.py', meths.get_var("filename_executed")) -- Reset filename meths.set_var("filename_executed", 'none') - meths.do_autocmd("CursorHoldI", { pattern = '__init__.py' }) + meths.exec_autocmd("CursorHoldI", { pattern = '__init__.py' }) eq('__init__.py', meths.get_var("filename_executed")) end) @@ -578,9 +578,9 @@ describe('autocmd api', function() command = 'let g:matched = "matched"' }) - meths.do_autocmd("User", { pattern = "OtherCommand" }) + meths.exec_autocmd("User", { pattern = "OtherCommand" }) eq('none', meths.get_var('matched')) - meths.do_autocmd("User", { pattern = "TestCommand" }) + meths.exec_autocmd("User", { pattern = "TestCommand" }) eq('matched', meths.get_var('matched')) end) @@ -594,7 +594,7 @@ describe('autocmd api', function() }) eq(false, meths.get_var("group_executed")) - meths.do_autocmd("FileType", { group = auid }) + meths.exec_autocmd("FileType", { group = auid }) eq(true, meths.get_var("group_executed")) end) @@ -609,7 +609,7 @@ describe('autocmd api', function() }) eq(false, meths.get_var("group_executed")) - meths.do_autocmd("FileType", { group = auname }) + meths.exec_autocmd("FileType", { group = auname }) eq(true, meths.get_var("group_executed")) end) end) -- cgit From 72652cbc46f568128bfc296ba63fb2d26941da8e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Mar 2022 10:25:55 -0700 Subject: feat(test): use nvim_exec in helpers.source() #16064 helpers.source() was a hack to work around the lack of anonymous :source. Its "create tempfile" behavior is not a required part of most tests that use it. Some tests still need the old "create tempfile" behavior either because they test SID behavior, or because of missing nvim_exec features: #16071 --- test/functional/api/command_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index b80004f67c..94176fc2ce 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -65,6 +65,7 @@ describe('nvim_get_commands', function() local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R3_ohyeah()', name='Cmd3', nargs='0', range=NIL, register=false, keepscript=false, script_id=3, } local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R4_just_great()', name='Cmd4', nargs='0', range=NIL, register=true, keepscript=false, script_id=4, } source([[ + let s:foo = 1 command -complete=custom,ListUsers -nargs=+ Finger !finger ]]) eq({Finger=cmd1}, meths.get_commands({builtin=false})) @@ -72,12 +73,18 @@ describe('nvim_get_commands', function() eq({Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false})) source([[ + function! s:foo() abort + endfunction command -bang -nargs=* Cmd2 call foo() ]]) source([[ + function! s:ohyeah() abort + endfunction command -bar -nargs=0 Cmd3 call ohyeah() ]]) source([[ + function! s:just_great() abort + endfunction command -register Cmd4 call just_great() ]]) -- TODO(justinmk): Order is stable but undefined. Sort before return? -- cgit From a9665bb12cd8cbacbc6ef6df66c1989b0c6f9fcc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Mar 2022 05:25:00 +0800 Subject: fix(event-loop): duplicate display updating logic in vgetorpeek() (#17913) --- test/functional/api/vim_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ed9d915954..e6ed0f939b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1589,6 +1589,18 @@ describe('API', function() feed(':digraphs') eq({mode='rm', blocking=true}, nvim("get_mode")) end) + + it('after mapping returns blocking=false #17257', function() + command('nnoremap ') + feed('') + eq({mode='n', blocking=false}, nvim("get_mode")) + end) + + it('after empty string mapping returns blocking=false #17257', function() + command('nnoremap ""') + feed('') + eq({mode='n', blocking=false}, nvim("get_mode")) + end) end) describe('RPC (K_EVENT)', function() -- cgit From 7fb2310edb8f2fae1ddd175ef4bd6508ca3ce7e3 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 30 Mar 2022 11:59:36 -0400 Subject: fix: set nested before executing callback (#17801) --- test/functional/api/autocmd_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 3b14ae9bf7..b8fbd4f9a5 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -334,6 +334,33 @@ describe('autocmd api', function() local aus2 = meths.get_autocmds { group = auname, event = "InsertEnter" } eq(0, #aus2) end) + + it('should respect nested', function() + local bufs = exec_lua [[ + local count = 0 + vim.api.nvim_create_autocmd("BufNew", { + once = false, + nested = true, + callback = function() + count = count + 1 + if count > 5 then + return true + end + + vim.cmd(string.format("new README_%s.md", count)) + end + }) + + vim.cmd "new First.md" + + return vim.api.nvim_list_bufs() + ]] + + -- 1 for the first buffer + -- 2 for First.md + -- 3-7 for the 5 we make in the autocmd + eq({1, 2, 3, 4, 5, 6, 7}, bufs) + end) end) describe('groups', function() -- cgit From b80651eda9c50d4e438f02af9311b18c5c202656 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Sat, 12 Mar 2022 15:12:02 -0500 Subject: feat(api): nvim_clear_autocmd Co-authored-by: Christian Clason --- test/functional/api/autocmd_spec.lua | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index b8fbd4f9a5..254de6668d 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -972,4 +972,95 @@ describe('autocmd api', function() eq(0, #meths.get_autocmds { event = 'BufReadPost' }) end) end) + + describe('nvim_clear_autocmd', function() + it('should clear based on event + pattern', function() + command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') + command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') + + local search = { event = "InsertEnter", pattern = "*.txt" } + local before_delete = meths.get_autocmds(search) + eq(1, #before_delete) + + local before_delete_all = meths.get_autocmds { event = search.event } + eq(2, #before_delete_all) + + meths.clear_autocmd(search) + local after_delete = meths.get_autocmds(search) + eq(0, #after_delete) + + local after_delete_all = meths.get_autocmds { event = search.event } + eq(1, #after_delete_all) + end) + + it('should clear based on event', function() + command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') + command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') + + local search = { event = "InsertEnter"} + local before_delete = meths.get_autocmds(search) + eq(2, #before_delete) + + meths.clear_autocmd(search) + local after_delete = meths.get_autocmds(search) + eq(0, #after_delete) + end) + + it('should clear based on pattern', function() + command('autocmd InsertEnter *.TestPat1 :echo "Enter 1"') + command('autocmd InsertLeave *.TestPat1 :echo "Leave 1"') + command('autocmd InsertEnter *.TestPat2 :echo "Enter 2"') + command('autocmd InsertLeave *.TestPat2 :echo "Leave 2"') + + local search = { pattern = "*.TestPat1"} + local before_delete = meths.get_autocmds(search) + eq(2, #before_delete) + local before_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + eq(4, #before_delete_events) + + meths.clear_autocmd(search) + local after_delete = meths.get_autocmds(search) + eq(0, #after_delete) + + local after_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } + eq(2, #after_delete_events) + end) + + it('should allow clearing by buffer', function() + command('autocmd! InsertEnter') + command('autocmd InsertEnter :echo "Enter Buffer"') + command('autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"') + + local search = { event = "InsertEnter" } + local before_delete = meths.get_autocmds(search) + eq(2, #before_delete) + + meths.clear_autocmd { buffer = 0 } + local after_delete = meths.get_autocmds(search) + eq(1, #after_delete) + eq("*.TestPat1", after_delete[1].pattern) + end) + + it('should allow clearing by buffer and group', function() + command('augroup TestNvimClearAutocmds') + command(' au!') + command(' autocmd InsertEnter :echo "Enter Buffer"') + command(' autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"') + command('augroup END') + + local search = { event = "InsertEnter", group = "TestNvimClearAutocmds" } + local before_delete = meths.get_autocmds(search) + eq(2, #before_delete) + + -- Doesn't clear without passing group. + meths.clear_autocmd { buffer = 0 } + local without_group = meths.get_autocmds(search) + eq(2, #without_group) + + -- Doest clear with passing group. + meths.clear_autocmd { buffer = 0, group = search.group } + local with_group = meths.get_autocmds(search) + eq(1, #with_group) + end) + end) end) -- cgit From 929293815bc6b9b1b5fdd129970c4e2f7279a6d6 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 31 Mar 2022 09:59:14 +0100 Subject: fix(api): improve autocmd error handling - nvim_del_augroup_* now works with pcall - nvim_del_autocmd now errors for invalid ids --- test/functional/api/autocmd_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index b8fbd4f9a5..25220f7e74 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -809,6 +809,14 @@ describe('autocmd api', function() eq(2, get_executed_count(), "No additional counts") end) + it('can delete non-existent groups with pcall', function() + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_name, 'noexist')]]) + eq('Vim:E367: No such group: "noexist"', pcall_err(meths.del_augroup_by_name, 'noexist')) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]]) + eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312)) + end) + it('groups work with once', function() local augroup = "TestGroup" -- cgit From 9d40b2fda96709a8219369316a5768ca4b689e4f Mon Sep 17 00:00:00 2001 From: György Andorka Date: Thu, 31 Mar 2022 19:13:22 +0200 Subject: refactor(api)!: use singular/plural consistently in the autocmd API --- test/functional/api/autocmd_spec.lua | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 254de6668d..80fcb51677 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -168,7 +168,7 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmd("User", {pattern = "Test"}) + meths.exec_autocmds("User", {pattern = "Test"}) eq({{ buflocal = false, command = 'A test autocommand', @@ -179,7 +179,7 @@ describe('autocmd api', function() pattern = 'Test', }}, meths.get_autocmds({event = "User", pattern = "Test"})) meths.set_var("some_condition", true) - meths.exec_autocmd("User", {pattern = "Test"}) + meths.exec_autocmds("User", {pattern = "Test"}) eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) end) end) @@ -517,7 +517,7 @@ describe('autocmd api', function() end) end) - describe('nvim_exec_autocmd', function() + describe('nvim_exec_autocmds', function() it("can trigger builtin autocmds", function() meths.set_var("autocmd_executed", false) @@ -527,7 +527,7 @@ describe('autocmd api', function() }) eq(false, meths.get_var("autocmd_executed")) - meths.exec_autocmd("BufReadPost", {}) + meths.exec_autocmds("BufReadPost", {}) eq(true, meths.get_var("autocmd_executed")) end) @@ -541,10 +541,10 @@ describe('autocmd api', function() }) -- Doesn't execute for other non-matching events - meths.exec_autocmd("CursorHold", { buffer = 1 }) + meths.exec_autocmds("CursorHold", { buffer = 1 }) eq(-1, meths.get_var("buffer_executed")) - meths.exec_autocmd("BufLeave", { buffer = 1 }) + meths.exec_autocmds("BufLeave", { buffer = 1 }) eq(1, meths.get_var("buffer_executed")) end) @@ -558,7 +558,7 @@ describe('autocmd api', function() }) -- Doesn't execute for other non-matching events - meths.exec_autocmd("CursorHold", { buffer = 1 }) + meths.exec_autocmds("CursorHold", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) meths.command('edit __init__.py') @@ -566,7 +566,7 @@ describe('autocmd api', function() end) it('cannot pass buf and fname', function() - local ok = pcall(meths.exec_autocmd, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) + local ok = pcall(meths.exec_autocmds, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) eq(false, ok) end) @@ -584,16 +584,16 @@ describe('autocmd api', function() }) -- Doesn't execute for other non-matching events - meths.exec_autocmd("CursorHoldI", { buffer = 1 }) + meths.exec_autocmds("CursorHoldI", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) - meths.exec_autocmd("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) + meths.exec_autocmds("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) eq('__init__.py', meths.get_var("filename_executed")) -- Reset filename meths.set_var("filename_executed", 'none') - meths.exec_autocmd("CursorHoldI", { pattern = '__init__.py' }) + meths.exec_autocmds("CursorHoldI", { pattern = '__init__.py' }) eq('__init__.py', meths.get_var("filename_executed")) end) @@ -605,9 +605,9 @@ describe('autocmd api', function() command = 'let g:matched = "matched"' }) - meths.exec_autocmd("User", { pattern = "OtherCommand" }) + meths.exec_autocmds("User", { pattern = "OtherCommand" }) eq('none', meths.get_var('matched')) - meths.exec_autocmd("User", { pattern = "TestCommand" }) + meths.exec_autocmds("User", { pattern = "TestCommand" }) eq('matched', meths.get_var('matched')) end) @@ -621,7 +621,7 @@ describe('autocmd api', function() }) eq(false, meths.get_var("group_executed")) - meths.exec_autocmd("FileType", { group = auid }) + meths.exec_autocmds("FileType", { group = auid }) eq(true, meths.get_var("group_executed")) end) @@ -636,7 +636,7 @@ describe('autocmd api', function() }) eq(false, meths.get_var("group_executed")) - meths.exec_autocmd("FileType", { group = auname }) + meths.exec_autocmds("FileType", { group = auname }) eq(true, meths.get_var("group_executed")) end) end) @@ -973,7 +973,7 @@ describe('autocmd api', function() end) end) - describe('nvim_clear_autocmd', function() + describe('nvim_clear_autocmds', function() it('should clear based on event + pattern', function() command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') @@ -985,7 +985,7 @@ describe('autocmd api', function() local before_delete_all = meths.get_autocmds { event = search.event } eq(2, #before_delete_all) - meths.clear_autocmd(search) + meths.clear_autocmds(search) local after_delete = meths.get_autocmds(search) eq(0, #after_delete) @@ -1001,7 +1001,7 @@ describe('autocmd api', function() local before_delete = meths.get_autocmds(search) eq(2, #before_delete) - meths.clear_autocmd(search) + meths.clear_autocmds(search) local after_delete = meths.get_autocmds(search) eq(0, #after_delete) end) @@ -1018,7 +1018,7 @@ describe('autocmd api', function() local before_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } eq(4, #before_delete_events) - meths.clear_autocmd(search) + meths.clear_autocmds(search) local after_delete = meths.get_autocmds(search) eq(0, #after_delete) @@ -1035,7 +1035,7 @@ describe('autocmd api', function() local before_delete = meths.get_autocmds(search) eq(2, #before_delete) - meths.clear_autocmd { buffer = 0 } + meths.clear_autocmds { buffer = 0 } local after_delete = meths.get_autocmds(search) eq(1, #after_delete) eq("*.TestPat1", after_delete[1].pattern) @@ -1053,12 +1053,12 @@ describe('autocmd api', function() eq(2, #before_delete) -- Doesn't clear without passing group. - meths.clear_autocmd { buffer = 0 } + meths.clear_autocmds { buffer = 0 } local without_group = meths.get_autocmds(search) eq(2, #without_group) -- Doest clear with passing group. - meths.clear_autocmd { buffer = 0, group = search.group } + meths.clear_autocmds { buffer = 0, group = search.group } local with_group = meths.get_autocmds(search) eq(1, #with_group) end) -- cgit From 30bc02c6364f384e437a6f53b057522d585492fc Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sat, 19 Mar 2022 19:16:19 -0600 Subject: feat(api)!: pass args table to autocommand callbacks --- test/functional/api/autocmd_spec.lua | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index b4a9a4f01f..377b4fecf0 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -182,6 +182,54 @@ describe('autocmd api', function() meths.exec_autocmds("User", {pattern = "Test"}) eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) end) + + it('receives an args table', function() + local res = exec_lua [[ + local group_id = vim.api.nvim_create_augroup("TestGroup", {}) + local autocmd_id = vim.api.nvim_create_autocmd("User", { + group = "TestGroup", + pattern = "Te*", + callback = function(args) + vim.g.autocmd_args = args + end, + }) + + return {group_id, autocmd_id} + ]] + + meths.exec_autocmds("User", {pattern = "Test pattern"}) + eq({ + id = res[2], + group = res[1], + event = "User", + match = "Test pattern", + file = "Test pattern", + buf = 1, + }, meths.get_var("autocmd_args")) + + -- Test without a group + res = exec_lua [[ + local autocmd_id = vim.api.nvim_create_autocmd("User", { + pattern = "*", + callback = function(args) + vim.g.autocmd_args = args + end, + }) + + return {autocmd_id} + ]] + + meths.exec_autocmds("User", {pattern = "some_pat"}) + eq({ + id = res[1], + group = nil, + event = "User", + match = "some_pat", + file = "some_pat", + buf = 1, + }, meths.get_var("autocmd_args")) + + end) end) describe('nvim_get_autocmds', function() -- cgit From f94f75dc0512def7fbfdfe100eea2dab3352d61f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sun, 10 Apr 2022 19:12:41 -0600 Subject: refactor!: rename nvim_add_user_command to nvim_create_user_command --- test/functional/api/command_spec.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 94176fc2ce..ad162473ec 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -92,11 +92,11 @@ describe('nvim_get_commands', function() end) end) -describe('nvim_add_user_command', function() +describe('nvim_create_user_command', function() before_each(clear) it('works with strings', function() - meths.add_user_command('SomeCommand', 'let g:command_fired = ', {nargs = 1}) + meths.create_user_command('SomeCommand', 'let g:command_fired = ', {nargs = 1}) meths.command('SomeCommand 42') eq(42, meths.eval('g:command_fired')) end) @@ -104,7 +104,7 @@ describe('nvim_add_user_command', function() it('works with Lua functions', function() exec_lua [[ result = {} - vim.api.nvim_add_user_command('CommandWithLuaCallback', function(opts) + vim.api.nvim_create_user_command('CommandWithLuaCallback', function(opts) result = opts end, { nargs = "*", @@ -176,7 +176,7 @@ describe('nvim_add_user_command', function() -- f-args doesn't split when command nargs is 1 or "?" exec_lua [[ result = {} - vim.api.nvim_add_user_command('CommandWithOneArg', function(opts) + vim.api.nvim_create_user_command('CommandWithOneArg', function(opts) result = opts end, { nargs = "?", @@ -204,7 +204,7 @@ describe('nvim_add_user_command', function() it('can define buffer-local commands', function() local bufnr = meths.create_buf(false, false) - bufmeths.add_user_command(bufnr, "Hello", "", {}) + bufmeths.create_user_command(bufnr, "Hello", "", {}) matches("Not an editor command: Hello", pcall_err(meths.command, "Hello")) meths.set_current_buf(bufnr) meths.command("Hello") @@ -213,7 +213,7 @@ describe('nvim_add_user_command', function() it('can use a Lua complete function', function() exec_lua [[ - vim.api.nvim_add_user_command('Test', '', { + vim.api.nvim_create_user_command('Test', '', { nargs = "*", complete = function(arg, cmdline, pos) local options = {"aaa", "bbb", "ccc"} @@ -236,23 +236,23 @@ describe('nvim_add_user_command', function() it('does not allow invalid command names', function() matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[ - vim.api.nvim_add_user_command('test', 'echo "hi"', {}) + vim.api.nvim_create_user_command('test', 'echo "hi"', {}) ]])) matches('Invalid command name', pcall_err(exec_lua, [[ - vim.api.nvim_add_user_command('t@', 'echo "hi"', {}) + vim.api.nvim_create_user_command('t@', 'echo "hi"', {}) ]])) matches('Invalid command name', pcall_err(exec_lua, [[ - vim.api.nvim_add_user_command('T@st', 'echo "hi"', {}) + vim.api.nvim_create_user_command('T@st', 'echo "hi"', {}) ]])) matches('Invalid command name', pcall_err(exec_lua, [[ - vim.api.nvim_add_user_command('Test!', 'echo "hi"', {}) + vim.api.nvim_create_user_command('Test!', 'echo "hi"', {}) ]])) matches('Invalid command name', pcall_err(exec_lua, [[ - vim.api.nvim_add_user_command('💩', 'echo "hi"', {}) + vim.api.nvim_create_user_command('💩', 'echo "hi"', {}) ]])) end) end) @@ -261,14 +261,14 @@ describe('nvim_del_user_command', function() before_each(clear) it('can delete global commands', function() - meths.add_user_command('Hello', 'echo "Hi"', {}) + meths.create_user_command('Hello', 'echo "Hi"', {}) meths.command('Hello') meths.del_user_command('Hello') matches("Not an editor command: Hello", pcall_err(meths.command, "Hello")) end) it('can delete buffer-local commands', function() - bufmeths.add_user_command(0, 'Hello', 'echo "Hi"', {}) + bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {}) meths.command('Hello') bufmeths.del_user_command(0, 'Hello') matches("Not an editor command: Hello", pcall_err(meths.command, "Hello")) -- cgit From e463eb81465978b5de77e207af9ee1b416ca0053 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Wed, 13 Apr 2022 08:04:56 -0600 Subject: fix(api): correctly pass f-args for nvim_create_user_command (#18098) Skip runs of whitespace and do not include `\` characters when followed by another `\` or whitespace. This matches the behavior of when used with `:command`. --- test/functional/api/command_spec.lua | 48 +++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index ad162473ec..e4963e8a65 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -114,8 +114,8 @@ describe('nvim_create_user_command', function() ]] eq({ - args = [[hello my\ friend how\ are\ you?]], - fargs = {[[hello]], [[my\ friend]], [[how\ are\ you?]]}, + args = [[this is a\ test]], + fargs = {"this", "is", "a test"}, bang = false, line1 = 1, line2 = 1, @@ -124,12 +124,42 @@ describe('nvim_create_user_command', function() count = 2, reg = "", }, exec_lua [=[ - vim.api.nvim_command([[CommandWithLuaCallback hello my\ friend how\ are\ you?]]) + vim.api.nvim_command([[CommandWithLuaCallback this is a\ test]]) return result ]=]) eq({ - args = 'h\tey', + args = [[this includes\ a backslash: \\]], + fargs = {"this", "includes a", "backslash:", "\\"}, + bang = false, + line1 = 1, + line2 = 1, + mods = "", + range = 0, + count = 2, + reg = "", + }, exec_lua [=[ + vim.api.nvim_command([[CommandWithLuaCallback this includes\ a backslash: \\]]) + return result + ]=]) + + eq({ + args = "a\\b", + fargs = {"a\\b"}, + bang = false, + line1 = 1, + line2 = 1, + mods = "", + range = 0, + count = 2, + reg = "", + }, exec_lua [=[ + vim.api.nvim_command('CommandWithLuaCallback a\\b') + return result + ]=]) + + eq({ + args = 'h\tey ', fargs = {[[h]], [[ey]]}, bang = true, line1 = 10, @@ -139,7 +169,7 @@ describe('nvim_create_user_command', function() count = 10, reg = "", }, exec_lua [=[ - vim.api.nvim_command('botright 10CommandWithLuaCallback! h\tey') + vim.api.nvim_command('botright 10CommandWithLuaCallback! h\tey ') return result ]=]) @@ -160,7 +190,7 @@ describe('nvim_create_user_command', function() eq({ args = "", - fargs = {""}, -- fargs works without args + fargs = {}, -- fargs works without args bang = false, line1 = 1, line2 = 1, @@ -186,8 +216,8 @@ describe('nvim_create_user_command', function() ]] eq({ - args = "hello I'm one argmuent", - fargs = {"hello I'm one argmuent"}, -- Doesn't split args + args = "hello I'm one argument", + fargs = {"hello I'm one argument"}, -- Doesn't split args bang = false, line1 = 1, line2 = 1, @@ -196,7 +226,7 @@ describe('nvim_create_user_command', function() count = 2, reg = "", }, exec_lua [[ - vim.api.nvim_command('CommandWithOneArg hello I\'m one argmuent') + vim.api.nvim_command('CommandWithOneArg hello I\'m one argument') return result ]]) -- cgit From e63e5d1dbd3dd4711efa0ecf9e844ff308b370a6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 15 Apr 2022 12:35:06 +0200 Subject: docs: typo fixes (#17859) Co-authored-by: Elias Alves Moura Co-authored-by: venkatesh Co-authored-by: zeertzjq Co-authored-by: Vikas Raj <24727447+numToStr@users.noreply.github.com> Co-authored-by: Steve Vermeulen Co-authored-by: Evgeni Chasnovski Co-authored-by: rwxd Co-authored-by: casswedson <58050969+casswedson@users.noreply.github.com> --- test/functional/api/extmark_spec.lua | 2 +- test/functional/api/highlight_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 3f96efd4ef..e298eb3582 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -924,7 +924,7 @@ describe('API/extmarks', function() eq(3, set_extmark(ns, 3, positions[2][1], positions[2][2])) eq(4, set_extmark(ns, 0, positions[1][1], positions[1][2])) - -- mixing manual and allocated id:s are not recommened, but it should + -- mixing manual and allocated id:s are not recommended, but it should -- do something reasonable eq(6, set_extmark(ns, 6, positions[2][1], positions[2][2])) eq(7, set_extmark(ns, 0, positions[1][1], positions[1][2])) diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 06cdb0bc19..a2f8353868 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -251,7 +251,7 @@ describe("API: set highlight", function() eq(highlight2_result, meths.get_hl_by_name('Test_hl', false)) end) - it ("can set emtpy cterm attr", function() + it ("can set empty cterm attr", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', { cterm = {} }) eq({}, meths.get_hl_by_name('Test_hl', false)) -- cgit From 813ecdac795405565aab5cb61cb83b9ca1581b60 Mon Sep 17 00:00:00 2001 From: Eden Zhang <53964412+VelocityDv@users.noreply.github.com> Date: Sun, 17 Apr 2022 12:11:53 +1200 Subject: fix(paste): ignore mappings in Cmdline mode (#18114) --- test/functional/api/vim_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e6ed0f939b..04b79a7157 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1085,6 +1085,12 @@ describe('API', function() eq('aabbccdd', funcs.getcmdline()) expect('') end) + it('mappings are disabled in Cmdline mode', function() + command('cnoremap a b') + feed(':') + nvim('paste', 'a', true, -1) + eq('a', funcs.getcmdline()) + end) it('pasting with empty last chunk in Cmdline mode', function() local screen = Screen.new(20, 4) screen:attach() -- cgit From 519e4c44720be9b0c8584cb53a902bc1e5bfe3a3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 26 Apr 2022 11:35:05 +0800 Subject: test: correct order of arguments to eq() and neq() --- test/functional/api/autocmd_spec.lua | 10 +++++----- test/functional/api/proc_spec.lua | 6 +++--- test/functional/api/vim_spec.lua | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 377b4fecf0..a30af63ba1 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -727,7 +727,7 @@ describe('autocmd api', function() set_ft("txt") set_ft("python") - eq(get_executed_count(), 2) + eq(2, get_executed_count()) end) it('works getting called multiple times', function() @@ -736,7 +736,7 @@ describe('autocmd api', function() set_ft() set_ft() - eq(get_executed_count(), 3) + eq(3, get_executed_count()) end) it('handles ++once', function() @@ -746,7 +746,7 @@ describe('autocmd api', function() set_ft('txt') set_ft('help') - eq(get_executed_count(), 1) + eq(1, get_executed_count()) end) it('errors on unexpected keys', function() @@ -874,7 +874,7 @@ describe('autocmd api', function() set_ft("txt") set_ft("python") - eq(get_executed_count(), 1) + eq(1, get_executed_count()) end) it('autocmds can be registered multiple times.', function() @@ -888,7 +888,7 @@ describe('autocmd api', function() set_ft("txt") set_ft("python") - eq(get_executed_count(), 3 * 2) + eq(3 * 2, get_executed_count()) end) it('can be deleted', function() diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index d828bdf948..0fbf58a8e7 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -63,9 +63,9 @@ describe('API', function() local pid = funcs.getpid() local pinfo = request('nvim_get_proc', pid) eq((iswin() and 'nvim.exe' or 'nvim'), pinfo.name) - eq(pinfo.pid, pid) - eq(type(pinfo.ppid), 'number') - neq(pinfo.ppid, pid) + eq(pid, pinfo.pid) + eq('number', type(pinfo.ppid)) + neq(pid, pinfo.ppid) end) it('validates input', function() diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 04b79a7157..f4b1a7fd59 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -122,9 +122,9 @@ describe('API', function() -- Functions nvim('exec', 'function Foo()\ncall setline(1,["xxx"])\nendfunction', false) - eq(nvim('get_current_line'), '') + eq('', nvim('get_current_line')) nvim('exec', 'call Foo()', false) - eq(nvim('get_current_line'), 'xxx') + eq('xxx', nvim('get_current_line')) -- Autocmds nvim('exec','autocmd BufAdd * :let x1 = "Hello"', false) @@ -1841,10 +1841,10 @@ describe('API', function() -- spin the loop a bit helpers.run(nil, nil, on_setup) - eq(nvim('get_var', 'x1'), '…') + eq('…', nvim('get_var', 'x1')) -- Because of the double escaping this is neq - neq(nvim('get_var', 'x2'), '…') - eq(nvim('get_var', 'x3'), '…') + neq('…', nvim('get_var', 'x2')) + eq('…', nvim('get_var', 'x3')) end) end) -- cgit From dde4f09f51ffaf8df5cc2a81eed935e31e1f94ba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 31 Mar 2022 15:47:53 +0800 Subject: vim-patch:8.1.2145: cannot map when modifyOtherKeys is enabled Problem: Cannot map when modifyOtherKeys is enabled. Solution: Add the mapping twice, both with modifier and as 0x08. Use only the first one when modifyOtherKeys has been detected. https://github.com/vim/vim/commit/459fd785e4a8d044147a3f83a5fca8748528aa84 Add REPTERM_NO_SPECIAL instead of REPTERM_SPECIAL because the meaning of "special" is different between Vim and Nvim. Omit seenModifyOtherKeys as Nvim supports attaching multiple UIs. Omit tests as they send terminal codes. Keep the behavior of API functions. --- test/functional/api/keymap_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index c0edcde476..a11b5306f4 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -582,7 +582,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can set mappings containing literal keycodes', function() meths.set_keymap('n', '\n\r\n', 'rhs', {}) local expected = generate_mapargs('n', '', 'rhs') - eq(expected, get_mapargs('n', '')) + eq(expected, get_mapargs('n', '')) end) it('can set mappings whose RHS is a ', function() -- cgit From c8e45366b9d0914eb17f759e0bfa7829fd419857 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 29 Apr 2022 17:30:45 +0800 Subject: fix(mappings): fix double-free when unmapping simplifiable Lua mapping --- test/functional/api/keymap_spec.lua | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index a11b5306f4..4fb2d55a76 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -874,6 +874,27 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) + it('no double-free when unmapping simplifiable lua mappings', function() + eq(0, exec_lua [[ + GlobalCount = 0 + vim.api.nvim_set_keymap('n', '', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + return GlobalCount + ]]) + + feed('\n') + + eq(1, exec_lua[[return GlobalCount]]) + + exec_lua [[ + vim.api.nvim_del_keymap('n', '') + ]] + + feed('\n') + + eq(1, exec_lua[[return GlobalCount]]) + eq('\nNo mapping found', helpers.exec_capture('nmap ')) + end) + it('can set descriptions on keymaps', function() meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"}) eq(generate_mapargs('n', 'lhs', 'rhs', {desc="map description"}), get_mapargs('n', 'lhs')) @@ -1040,4 +1061,25 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) + + it('no double-free when unmapping simplifiable lua mappings', function() + eq(0, exec_lua [[ + GlobalCount = 0 + vim.api.nvim_buf_set_keymap(0, 'n', '', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + return GlobalCount + ]]) + + feed('\n') + + eq(1, exec_lua[[return GlobalCount]]) + + exec_lua [[ + vim.api.nvim_buf_del_keymap(0, 'n', '') + ]] + + feed('\n') + + eq(1, exec_lua[[return GlobalCount]]) + eq('\nNo mapping found', helpers.exec_capture('nmap ')) + end) end) -- cgit From 8dbb11ebf633e40cb57568e77c7168deffc8bd7f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 23 Apr 2022 10:21:59 +0600 Subject: feat(api): add `nvim_parse_cmdline` Adds an API function to parse a command line string and get command information from it. --- test/functional/api/vim_spec.lua | 292 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index f4b1a7fd59..e138e2cc38 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3098,4 +3098,296 @@ describe('API', function() end) end) end) + describe('nvim_parse_cmd', function() + it('works', function() + eq({ + cmd = 'echo', + args = { 'foo' }, + bang = false, + line1 = 1, + line2 = 1, + addr = 'none', + magic = { + file = false, + bar = false + }, + nargs = '*', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + } + }, meths.parse_cmd('echo foo', {})) + end) + it('works with ranges', function() + eq({ + cmd = 'substitute', + args = { '/math.random/math.max/' }, + bang = false, + line1 = 4, + line2 = 6, + addr = 'line', + magic = { + file = false, + bar = false + }, + nargs = '*', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + } + }, meths.parse_cmd('4,6s/math.random/math.max/', {})) + end) + it('works with bang', function() + eq({ + cmd = 'write', + args = {}, + bang = true, + line1 = 1, + line2 = 1, + addr = 'line', + magic = { + file = true, + bar = true + }, + nargs = '?', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + }, + }, meths.parse_cmd('w!', {})) + end) + it('works with modifiers', function() + eq({ + cmd = 'split', + args = { 'foo.txt' }, + bang = false, + line1 = 1, + line2 = 1, + addr = '?', + magic = { + file = true, + bar = true + }, + nargs = '?', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = true, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = true, + vertical = false, + split = "topleft", + tab = 2, + verbose = 15 + }, + }, meths.parse_cmd('15verbose silent! aboveleft topleft tab split foo.txt', {})) + end) + it('works with user commands', function() + command('command -bang -nargs=+ -range -addr=lines MyCommand echo foo') + eq({ + cmd = 'MyCommand', + args = { 'test', 'it' }, + bang = true, + line1 = 4, + line2 = 6, + addr = 'line', + magic = { + file = false, + bar = false + }, + nargs = '+', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + } + }, meths.parse_cmd('4,6MyCommand! test it', {})) + end) + it('works for commands separated by bar', function() + eq({ + cmd = 'argadd', + args = { 'a.txt' }, + bang = false, + line1 = 0, + line2 = 0, + addr = 'arg', + magic = { + file = true, + bar = true + }, + nargs = '*', + nextcmd = 'argadd b.txt', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + } + }, meths.parse_cmd('argadd a.txt | argadd b.txt', {})) + end) + it('works for nargs=1', function() + command('command -nargs=1 MyCommand echo ') + eq({ + cmd = 'MyCommand', + args = { 'test it' }, + bang = false, + line1 = 1, + line2 = 1, + addr = 'none', + magic = { + file = false, + bar = false + }, + nargs = '1', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + } + }, meths.parse_cmd('MyCommand test it', {})) + end) + it('sets correct default range', function() + command('command -range=% -addr=buffers MyCommand echo foo') + command('new') + eq({ + cmd = 'MyCommand', + args = {}, + bang = false, + line1 = 1, + line2 = 2, + addr = 'buf', + magic = { + file = false, + bar = false + }, + nargs = '0', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = 0 + } + }, meths.parse_cmd('MyCommand', {})) + end) + it('errors for invalid command', function() + eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar', {})) + command('command! Fubar echo foo') + eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar!', {})) + eq('Error while parsing command line', pcall_err(meths.parse_cmd, '4,6Fubar', {})) + end) + end) end) -- cgit From b2c92f36e1c1079ec37bfdab88e1d2cf556f4d6c Mon Sep 17 00:00:00 2001 From: ii14 Date: Tue, 3 May 2022 11:28:13 +0200 Subject: feat: add "prerelease" to version dict --- test/functional/api/version_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index bf67d4788b..daac862ec8 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -33,9 +33,11 @@ describe("api_info()['version']", function() local major = version['major'] local minor = version['minor'] local patch = version['patch'] + local prerelease = version['prerelease'] eq("number", type(major)) eq("number", type(minor)) eq("number", type(patch)) + eq("boolean", type(prerelease)) eq(1, funcs.has("nvim-"..major.."."..minor.."."..patch)) eq(0, funcs.has("nvim-"..major.."."..minor.."."..(patch + 1))) eq(0, funcs.has("nvim-"..major.."."..(minor + 1).."."..patch)) -- cgit From 29a6cda3ffe981b09d4c59d49d6c97a4ea13ca8b Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Thu, 16 Sep 2021 07:53:56 +0800 Subject: feat(api/ui): win_extmarks --- test/functional/api/extmark_spec.lua | 206 +++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index e298eb3582..bc8d811c6d 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1606,3 +1606,209 @@ describe('Extmarks buffer api with many marks', function() eq({}, get_marks(ns2)) end) end) + +describe('API/win_extmark', function() + local screen + local marks, line1, line2 + local ns + + before_each(function() + -- Initialize some namespaces and insert text into a buffer + marks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} + + line1 = "non ui-watched line" + line2 = "ui-watched line" + + clear() + + insert(line1) + feed("o") + insert(line2) + ns = request('nvim_create_namespace', "extmark-ui") + end) + + it('sends and only sends ui-watched marks to ui', function() + screen = Screen.new(20, 4) + screen:attach() + -- should send this + set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) + -- should not send this + set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) + screen:expect({ + grid = [[ + non ui-watched line | + ui-watched lin^e | + ~ | + | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + } + }, + }) + end) + + it('sends multiple ui-watched marks to ui', function() + screen = Screen.new(20, 4) + screen:attach() + -- should send all of these + set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[5], 1, 8, { ui_watched = true }) + screen:expect({ + grid = [[ + non ui-watched line | + ui-watched lin^e | + ~ | + | + ]], + extmarks = { + [2] = { + -- earlier notifications + { {id = 1000}, 1, 1, 1, 0 }, + { {id = 1000}, 1, 1, 1, 0 }, { {id = 1000}, 1, 2, 1, 2 }, + { {id = 1000}, 1, 1, 1, 0 }, { {id = 1000}, 1, 2, 1, 2 }, { {id = 1000}, 1, 3, 1, 4 }, + { {id = 1000}, 1, 1, 1, 0 }, { {id = 1000}, 1, 2, 1, 2 }, { {id = 1000}, 1, 3, 1, 4 }, { {id = 1000}, 1, 4, 1, 6 }, + -- final + -- overlay + { {id = 1000}, 1, 1, 1, 0 }, + { {id = 1000}, 1, 2, 1, 2 }, + { {id = 1000}, 1, 3, 1, 4 }, + { {id = 1000}, 1, 4, 1, 6 }, + -- eol + { {id = 1000}, 1, 5, 1, 16 }, + } + }, + }) + end) + + it('updates ui-watched marks', function() + screen = Screen.new(20, 4) + screen:attach() + -- should send this + set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) + -- should not send this + set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) + -- make some changes + insert(" update") + screen:expect({ + grid = [[ + non ui-watched line | + ui-watched linupdat^e| + e | + | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated and wrapped to 3rd line + { {id = 1000}, 1, 1, 2, 2 }, + } + } + }) + feed("") + screen:expect({ + grid = [[ + ui-watched linupdat^e| + e | + ~ | + | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated and wrapped to 3rd line + { {id = 1000}, 1, 1, 2, 2 }, + -- scrolled up one line, should be handled by grid scroll + } + } + }) + end) + + it('sends ui-watched to splits', function() + screen = Screen.new(20, 8) + screen:attach({ext_multigrid=true}) + -- should send this + set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) + -- should not send this + set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) + command('split') + screen:expect({ + grid = [[ + ## grid 1 + [4:--------------------]| + [4:--------------------]| + [4:--------------------]| + [No Name] [+] | + [2:--------------------]| + [2:--------------------]| + [No Name] [+] | + [3:--------------------]| + ## grid 2 + non ui-watched line | + ui-watched line | + ## grid 3 + | + ## grid 4 + non ui-watched line | + ui-watched lin^e | + ~ | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated after split + { {id = 1000}, 1, 1, 1, 16 }, + }, + [4] = { + -- only after split + { {id = 1001}, 1, 1, 1, 16 }, + } + } + }) + -- make some changes + insert(" update") + screen:expect({ + grid = [[ + ## grid 1 + [4:--------------------]| + [4:--------------------]| + [4:--------------------]| + [No Name] [+] | + [2:--------------------]| + [2:--------------------]| + [No Name] [+] | + [3:--------------------]| + ## grid 2 + non ui-watched line | + ui-watched linupd@@@| + ## grid 3 + | + ## grid 4 + non ui-watched line | + ui-watched linupdat^e| + e | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated after split + { {id = 1000}, 1, 1, 1, 16 }, + }, + [4] = { + { {id = 1001}, 1, 1, 1, 16 }, + -- updated + { {id = 1001}, 1, 1, 2, 2 }, + } + } + }) + end) +end) -- cgit From 3ec93ca92cb08faed342586e86a6f21b35264376 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 4 May 2022 18:04:01 +0600 Subject: feat(nvim_parse_cmd): add range, count, reg #18383 Adds range, count and reg to the return values of nvim_parse_cmd. Also makes line1 and line2 be -1 if the command does not take a range. Also moves nvim_parse_cmd to vimscript.c because it fits better there. --- test/functional/api/vim_spec.lua | 122 +++++++++++++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 11 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e138e2cc38..7e54ae0248 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3104,8 +3104,11 @@ describe('API', function() cmd = 'echo', args = { 'foo' }, bang = false, - line1 = 1, - line2 = 1, + line1 = -1, + line2 = -1, + range = 0, + count = -1, + reg = '', addr = 'none', magic = { file = false, @@ -3130,7 +3133,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('echo foo', {})) end) @@ -3141,6 +3144,9 @@ describe('API', function() bang = false, line1 = 4, line2 = 6, + range = 2, + count = -1, + reg = '', addr = 'line', magic = { file = false, @@ -3165,10 +3171,86 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('4,6s/math.random/math.max/', {})) end) + it('works with count', function() + eq({ + cmd = 'buffer', + args = {}, + bang = false, + line1 = 1, + line2 = 1, + range = 1, + count = 1, + reg = '', + addr = 'buf', + magic = { + file = false, + bar = true + }, + nargs = '*', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = -1 + } + }, meths.parse_cmd('buffer 1', {})) + end) + it('works with register', function() + eq({ + cmd = 'put', + args = {}, + bang = false, + line1 = 1, + line2 = 1, + range = 0, + count = -1, + reg = '+', + addr = 'line', + magic = { + file = false, + bar = true + }, + nargs = '0', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = -1 + } + }, meths.parse_cmd('put +', {})) + end) it('works with bang', function() eq({ cmd = 'write', @@ -3176,6 +3258,9 @@ describe('API', function() bang = true, line1 = 1, line2 = 1, + range = 0, + count = -1, + reg = '', addr = 'line', magic = { file = true, @@ -3200,7 +3285,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 }, }, meths.parse_cmd('w!', {})) end) @@ -3211,6 +3296,9 @@ describe('API', function() bang = false, line1 = 1, line2 = 1, + range = 0, + count = -1, + reg = '', addr = '?', magic = { file = true, @@ -3247,6 +3335,9 @@ describe('API', function() bang = true, line1 = 4, line2 = 6, + range = 2, + count = -1, + reg = '', addr = 'line', magic = { file = false, @@ -3271,7 +3362,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('4,6MyCommand! test it', {})) end) @@ -3282,6 +3373,9 @@ describe('API', function() bang = false, line1 = 0, line2 = 0, + range = 0, + count = -1, + reg = '', addr = 'arg', magic = { file = true, @@ -3306,7 +3400,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('argadd a.txt | argadd b.txt', {})) end) @@ -3316,8 +3410,11 @@ describe('API', function() cmd = 'MyCommand', args = { 'test it' }, bang = false, - line1 = 1, - line2 = 1, + line1 = -1, + line2 = -1, + range = 0, + count = -1, + reg = '', addr = 'none', magic = { file = false, @@ -3342,7 +3439,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('MyCommand test it', {})) end) @@ -3355,6 +3452,9 @@ describe('API', function() bang = false, line1 = 1, line2 = 2, + range = 0, + count = -1, + reg = '', addr = 'buf', magic = { file = false, @@ -3379,7 +3479,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('MyCommand', {})) end) -- cgit From 7aedcd8febaf74403851f8482529302e3ab30922 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 5 May 2022 01:49:29 +0600 Subject: refactor(api): make `range` in `nvim_parse_cmd` an array Changes the `range` value in `nvim_parse_cmd` into an array to describe range information more concisely. Also makes `range` and `count` be mutually exclusive by making count `-1` when command takes a range instead of a count. Additionally corrects the behavior of `count` for built-in commands by making the default count `0`. --- test/functional/api/vim_spec.lua | 76 +++++----------------------------------- 1 file changed, 9 insertions(+), 67 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 7e54ae0248..610036f484 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3104,9 +3104,7 @@ describe('API', function() cmd = 'echo', args = { 'foo' }, bang = false, - line1 = -1, - line2 = -1, - range = 0, + range = {}, count = -1, reg = '', addr = 'none', @@ -3142,9 +3140,7 @@ describe('API', function() cmd = 'substitute', args = { '/math.random/math.max/' }, bang = false, - line1 = 4, - line2 = 6, - range = 2, + range = { 4, 6 }, count = -1, reg = '', addr = 'line', @@ -3180,9 +3176,7 @@ describe('API', function() cmd = 'buffer', args = {}, bang = false, - line1 = 1, - line2 = 1, - range = 1, + range = {}, count = 1, reg = '', addr = 'buf', @@ -3218,9 +3212,7 @@ describe('API', function() cmd = 'put', args = {}, bang = false, - line1 = 1, - line2 = 1, - range = 0, + range = {}, count = -1, reg = '+', addr = 'line', @@ -3256,9 +3248,7 @@ describe('API', function() cmd = 'write', args = {}, bang = true, - line1 = 1, - line2 = 1, - range = 0, + range = {}, count = -1, reg = '', addr = 'line', @@ -3294,9 +3284,7 @@ describe('API', function() cmd = 'split', args = { 'foo.txt' }, bang = false, - line1 = 1, - line2 = 1, - range = 0, + range = {}, count = -1, reg = '', addr = '?', @@ -3333,9 +3321,7 @@ describe('API', function() cmd = 'MyCommand', args = { 'test', 'it' }, bang = true, - line1 = 4, - line2 = 6, - range = 2, + range = { 4, 6 }, count = -1, reg = '', addr = 'line', @@ -3371,9 +3357,7 @@ describe('API', function() cmd = 'argadd', args = { 'a.txt' }, bang = false, - line1 = 0, - line2 = 0, - range = 0, + range = {}, count = -1, reg = '', addr = 'arg', @@ -3410,9 +3394,7 @@ describe('API', function() cmd = 'MyCommand', args = { 'test it' }, bang = false, - line1 = -1, - line2 = -1, - range = 0, + range = {}, count = -1, reg = '', addr = 'none', @@ -3443,46 +3425,6 @@ describe('API', function() } }, meths.parse_cmd('MyCommand test it', {})) end) - it('sets correct default range', function() - command('command -range=% -addr=buffers MyCommand echo foo') - command('new') - eq({ - cmd = 'MyCommand', - args = {}, - bang = false, - line1 = 1, - line2 = 2, - range = 0, - count = -1, - reg = '', - addr = 'buf', - magic = { - file = false, - bar = false - }, - nargs = '0', - nextcmd = '', - mods = { - browse = false, - confirm = false, - emsg_silent = false, - hide = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - vertical = false, - split = "", - tab = 0, - verbose = -1 - } - }, meths.parse_cmd('MyCommand', {})) - end) it('errors for invalid command', function() eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar', {})) command('command! Fubar echo foo') -- cgit From 511f06a56e77f612f7bc8ca563ebecb7239a9914 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 5 May 2022 23:11:57 +0600 Subject: fix(api): make `nvim_parse_cmd` propagate errors Makes `nvim_parse_cmd` propagate any errors that occur while parsing to give the user a better idea of what's wrong with the command. --- test/functional/api/vim_spec.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 610036f484..11c1fc6c2c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3426,10 +3426,15 @@ describe('API', function() }, meths.parse_cmd('MyCommand test it', {})) end) it('errors for invalid command', function() - eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar', {})) + eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {})) + eq('Error while parsing command line', pcall_err(meths.parse_cmd, '" foo', {})) + eq('Error while parsing command line: E492: Not an editor command: Fubar', + pcall_err(meths.parse_cmd, 'Fubar', {})) command('command! Fubar echo foo') - eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar!', {})) - eq('Error while parsing command line', pcall_err(meths.parse_cmd, '4,6Fubar', {})) + eq('Error while parsing command line: E477: No ! allowed', + pcall_err(meths.parse_cmd, 'Fubar!', {})) + eq('Error while parsing command line: E481: No range allowed', + pcall_err(meths.parse_cmd, '4,6Fubar', {})) end) end) end) -- cgit From 96289f24169281da419e8ce1078705258db3229b Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 5 May 2022 21:00:47 +0600 Subject: feat(api): add `group_name` to `nvim_get_autocmds` --- test/functional/api/autocmd_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index a30af63ba1..41de308a2c 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -444,6 +444,7 @@ describe('autocmd api', function() eq(1, #aus) eq([[:echo "GroupOne:1"]], aus[1].command) + eq("GroupOne", aus[1].group_name) end) it('should return only the group specified, multiple values', function() @@ -454,7 +455,9 @@ describe('autocmd api', function() eq(2, #aus) eq([[:echo "GroupTwo:2"]], aus[1].command) + eq("GroupTwo", aus[1].group_name) eq([[:echo "GroupTwo:3"]], aus[2].command) + eq("GroupTwo", aus[2].group_name) end) end) -- cgit From 14f3383c0da1413a5ae82feb19ac89f01d4b9aad Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 7 May 2022 08:57:21 +0600 Subject: fix(api): make `nvim_parse_cmd` work correctly with both range and count It seems range and count can be used together in commands. This PR fixes the behavior of `nvim_parse_cmd` for those cases by removing the mutual exclusivity of "range" and "count". It also removes range line number validation for `nvim_parse_cmd` as it's not its job to validate the command. --- test/functional/api/vim_spec.lua | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 11c1fc6c2c..d68f299277 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3176,7 +3176,7 @@ describe('API', function() cmd = 'buffer', args = {}, bang = false, - range = {}, + range = { 1 }, count = 1, reg = '', addr = 'buf', @@ -3243,6 +3243,42 @@ describe('API', function() } }, meths.parse_cmd('put +', {})) end) + it('works with range, count and register', function() + eq({ + cmd = 'delete', + args = {}, + bang = false, + range = { 3, 7 }, + count = 7, + reg = '*', + addr = 'line', + magic = { + file = false, + bar = true + }, + nargs = '0', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = -1 + } + }, meths.parse_cmd('1,3delete * 5', {})) + end) it('works with bang', function() eq({ cmd = 'write', -- cgit From dfcc58466505f7fb5f62d636a67facaeea143285 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sun, 8 May 2022 17:39:45 +0600 Subject: feat(api): add `nvim_cmd` Adds the API function `nvim_cmd` which allows executing an Ex-command through a Dictionary which can have the same values as the return value of `nvim_parse_cmd()`. This makes it much easier to do things like passing arguments with a space to commands that otherwise may not allow it, or to make commands interpret certain characters literally when they otherwise would not. --- test/functional/api/vim_spec.lua | 143 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d68f299277..e07202c46f 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1,5 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') +local lfs = require('lfs') local fmt = string.format local assert_alive = helpers.assert_alive @@ -25,6 +26,7 @@ local tmpname = helpers.tmpname local write_file = helpers.write_file local exec_lua = helpers.exec_lua local exc_exec = helpers.exc_exec +local insert = helpers.insert local pcall_err = helpers.pcall_err local format_string = helpers.format_string @@ -3473,4 +3475,145 @@ describe('API', function() pcall_err(meths.parse_cmd, '4,6Fubar', {})) end) end) + describe('nvim_cmd', function() + it('works', function () + meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) + eq(true, meths.get_option_value("cursorline", {})) + end) + it('captures output', function() + eq("foo", meths.cmd({ cmd = "echo", args = { '"foo"' } }, { output = true })) + end) + it('sets correct script context', function() + meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) + local str = meths.exec([[verbose set cursorline?]], true) + neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)")) + end) + it('works with range', function() + insert [[ + line1 + line2 + line3 + line4 + you didn't expect this + line5 + line6 + ]] + meths.cmd({ cmd = "del", range = {2, 4} }, {}) + expect [[ + line1 + you didn't expect this + line5 + line6 + ]] + end) + it('works with count', function() + insert [[ + line1 + line2 + line3 + line4 + you didn't expect this + line5 + line6 + ]] + meths.cmd({ cmd = "del", range = { 2 }, count = 4 }, {}) + expect [[ + line1 + line5 + line6 + ]] + end) + it('works with register', function() + insert [[ + line1 + line2 + line3 + line4 + you didn't expect this + line5 + line6 + ]] + meths.cmd({ cmd = "del", range = { 2, 4 }, reg = 'a' }, {}) + meths.exec("1put a", false) + expect [[ + line1 + line2 + line3 + line4 + you didn't expect this + line5 + line6 + ]] + end) + it('works with bang', function () + meths.create_user_command("Foo", 'echo ""', { bang = true }) + eq("!", meths.cmd({ cmd = "Foo", bang = true }, { output = true })) + eq("", meths.cmd({ cmd = "Foo", bang = false }, { output = true })) + end) + it('works with modifiers', function() + meths.create_user_command("Foo", 'set verbose', {}) + eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true })) + eq(0, meths.get_option_value("verbose", {})) + end) + it('works with magic.file', function() + exec_lua([[ + vim.api.nvim_create_user_command("Foo", function(opts) + vim.api.nvim_echo({{ opts.fargs[1] }}, false, {}) + end, { nargs = 1 }) + ]]) + eq(lfs.currentdir(), + meths.cmd({ cmd = "Foo", args = { '%:p:h' }, magic = { file = true } }, + { output = true })) + end) + it('splits arguments correctly', function() + meths.exec([[ + function! FooFunc(...) + echo a:000 + endfunction + ]], false) + meths.create_user_command("Foo", "call FooFunc()", { nargs = '+' }) + eq([=[['a quick', 'brown fox', 'jumps over the', 'lazy dog']]=], + meths.cmd({ cmd = "Foo", args = { "a quick", "brown fox", "jumps over the", "lazy dog"}}, + { output = true })) + eq([=[['test \ \\ \"""\', 'more\ tests\" ']]=], + meths.cmd({ cmd = "Foo", args = { [[test \ \\ \"""\]], [[more\ tests\" ]] } }, + { output = true })) + end) + it('splits arguments correctly for Lua callback', function() + meths.exec_lua([[ + local function FooFunc(opts) + vim.pretty_print(opts.fargs) + end + + vim.api.nvim_create_user_command("Foo", FooFunc, { nargs = '+' }) + ]], {}) + eq([[{ "a quick", "brown fox", "jumps over the", "lazy dog" }]], + meths.cmd({ cmd = "Foo", args = { "a quick", "brown fox", "jumps over the", "lazy dog"}}, + { output = true })) + eq([[{ 'test \\ \\\\ \\"""\\', 'more\\ tests\\" ' }]], + meths.cmd({ cmd = "Foo", args = { [[test \ \\ \"""\]], [[more\ tests\" ]] } }, + { output = true })) + end) + it('works with buffer names', function() + command("edit foo.txt | edit bar.txt") + meths.cmd({ cmd = "buffer", args = { "foo.txt" } }, {}) + eq("foo.txt", funcs.fnamemodify(meths.buf_get_name(0), ":t")) + meths.cmd({ cmd = "buffer", args = { "bar.txt" } }, {}) + eq("bar.txt", funcs.fnamemodify(meths.buf_get_name(0), ":t")) + end) + it('triggers CmdUndefined event if command is not found', function() + meths.exec_lua([[ + vim.api.nvim_create_autocmd("CmdUndefined", + { pattern = "Foo", + callback = function() + vim.api.nvim_create_user_command("Foo", "echo 'foo'", {}) + end + }) + ]], {}) + eq("foo", meths.cmd({ cmd = "Foo" }, { output = true })) + end) + it('errors if command is not implemented', function() + eq("Command not implemented: popup", pcall_err(meths.cmd, { cmd = "popup" }, {})) + end) + end) end) -- cgit From cf68f0a51202342163825015602bdf78b783c777 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 11 May 2022 22:51:53 +0600 Subject: fix(api): make `nvim_cmd` work correctly with empty arguments list (#18527) Closes #18526. --- test/functional/api/vim_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e07202c46f..f39aa2f20b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3615,5 +3615,9 @@ describe('API', function() it('errors if command is not implemented', function() eq("Command not implemented: popup", pcall_err(meths.cmd, { cmd = "popup" }, {})) end) + it('works with empty arguments list', function() + meths.cmd({ cmd = "update" }, {}) + meths.cmd({ cmd = "buffer", count = 0 }, {}) + end) end) end) -- cgit From bbf58e6bbcc107e92d84730a33bd5a32440f5428 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sun, 15 May 2022 22:34:44 +0600 Subject: refactor(ui)!: link `VertSplit` to `Normal` by default Avoids using `gui=reverse` on `VertSplit` and makes window separators look much nicer by default. --- test/functional/api/window_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index c31ab2060a..9aacac37bf 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -166,23 +166,23 @@ describe('API/win', function() local oldwin = curwin() command('vsplit') screen:expect([[ - aaa {4:│}aaa | - bbb {4:│}bbb | - ccc {4:│}ccc | - {2:dd^d }{4:│}{2:ddd }| - {1:~ }{4:│}{1:~ }| - {1:~ }{4:│}{1:~ }| + aaa │aaa | + bbb │bbb | + ccc │ccc | + {2:dd^d }│{2:ddd }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}| | ]]) window('set_cursor', oldwin, {1, 0}) screen:expect([[ - aaa {4:│}{2:aaa }| - bbb {4:│}bbb | - ccc {4:│}ccc | - {2:dd^d }{4:│}ddd | - {1:~ }{4:│}{1:~ }| - {1:~ }{4:│}{1:~ }| + aaa │{2:aaa }| + bbb │bbb | + ccc │ccc | + {2:dd^d }│ddd | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 1,1 All}| | ]]) -- cgit From 0a3d615b1ca17cda978b89d66acef39b90ee7c81 Mon Sep 17 00:00:00 2001 From: deforde <7503504+deforde@users.noreply.github.com> Date: Sun, 15 May 2022 22:06:23 +0200 Subject: fix(api): nvim_eval_statusline should validate input #18347 Fix #18112 Make an exception for strings starting with "%!". --- test/functional/api/vim_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index f39aa2f20b..ba170ba8c5 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3044,6 +3044,10 @@ describe('API', function() eq('fillchar must be a single character', pcall_err(meths.eval_statusline, '', { fillchar = 1 })) end) + it('rejects invalid string', function() + eq('E539: Illegal character <}>', + pcall_err(meths.eval_statusline, '%{%}', {})) + end) describe('highlight parsing', function() it('works', function() eq({ -- cgit From f49699737c9b24e1af52719974cf3bc770539ef9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 May 2022 21:09:28 +0800 Subject: fix(terminal): do not trim whitespace that is actually in the terminal (#16423) --- test/functional/api/buffer_updates_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index fc09e4cde0..097757f53d 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -785,7 +785,8 @@ describe('API: buffer events:', function() local function lines_subset(first, second) for i = 1,#first do - if first[i] ~= second[i] then + -- need to ignore trailing spaces + if first[i]:gsub(' +$', '') ~= second[i]:gsub(' +$', '') then return false end end -- cgit From 6219331c4d333e5a76129746021f972c21a040db Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 11 May 2022 13:49:43 +0100 Subject: feat(api): add win and buf to nvim_set_option_value Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com> --- test/functional/api/vim_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ba170ba8c5..8c4048132c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1439,6 +1439,24 @@ describe('API', function() nvim('set_option_value', 'autoread', NIL, {scope = 'local'}) eq(NIL, nvim('get_option_value', 'autoread', {scope = 'local'})) end) + + it('set window options', function() + -- Same as to nvim_win_set_option + nvim('set_option_value', 'colorcolumn', '4,3', {win=0}) + eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) + command("set modified hidden") + command("enew") -- edit new buffer, window option is preserved + eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) + end) + + it('set local window options', function() + -- Different to nvim_win_set_option + nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'}) + eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) + command("set modified hidden") + command("enew") -- edit new buffer, window option is reset + eq('', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) + end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() -- cgit From e1bdb2a258cbe6c5cb981acc6bac82cd9e7706fb Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 13 May 2022 20:47:11 +0600 Subject: feat(ui): add `'winbar'` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support for a bar at the top of each window, enabled through the `'winbar'` option. Co-authored-by: Björn Linse --- test/functional/api/vim_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ba170ba8c5..c4748cc00d 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3102,6 +3102,19 @@ describe('API', function() 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', { use_tabline = true, highlights = true })) end) + it('works with winbar', function() + eq({ + str = 'TextWithNoHighlightTextWithWarningHighlight', + width = 43, + highlights = { + { start = 0, group = 'WinBar' }, + { start = 19, group = 'WarningMsg' } + } + }, + meths.eval_statusline( + 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', + { use_winbar = true, highlights = true })) + end) end) end) describe('nvim_parse_cmd', function() -- cgit From 6e414b698cbcc4f1e42564febad030d1a0a52230 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 18 May 2022 12:57:04 +0800 Subject: test: unskip tests on Windows (#18600) Remove the command('qall!') from mksession_spec.lua because it prevents helpers.rmdir() from retrying. Allow extra trailing spaces when matching terminal lines. --- test/functional/api/buffer_updates_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 097757f53d..2728dcf74c 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -828,7 +828,6 @@ describe('API: buffer events:', function() end it('when :terminal lines change', function() - if helpers.pending_win32(pending) then return end local buffer_lines = {} local expected_lines = {} command('terminal "'..nvim_prog..'" -u NONE -i NONE -n -c "set shortmess+=A"') -- cgit From 8a9ab88945cdabcbd23f23406353ec6110fefa83 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Wed, 18 May 2022 09:51:26 -0600 Subject: feat(api): enable nvim_exec_autocmds to pass arbitrary data (#18613) Add a "data" key to nvim_exec_autocmds that passes arbitrary data (API objects) to autocommand callbacks. --- test/functional/api/autocmd_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 41de308a2c..c08c411de1 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -230,6 +230,34 @@ describe('autocmd api', function() }, meths.get_var("autocmd_args")) end) + + it('can receive arbitrary data', function() + local function test(data) + eq(data, exec_lua([[ + local input = ... + local output + vim.api.nvim_create_autocmd("User", { + pattern = "Test", + callback = function(args) + output = args.data + end, + }) + + vim.api.nvim_exec_autocmds("User", { + pattern = "Test", + data = input, + }) + + return output + ]], data)) + end + + test("Hello") + test(42) + test(true) + test({ "list" }) + test({ foo = "bar" }) + end) end) describe('nvim_get_autocmds', function() -- cgit From fb8fa004d8c91b7b591509539a228e97ebc57d9d Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 19 May 2022 21:49:12 +0600 Subject: fix: make `nvim_cmd` not suppress errors inside key mapping Closes #18632 --- test/functional/api/vim_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c4748cc00d..c5e8cfee23 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3636,5 +3636,13 @@ describe('API', function() meths.cmd({ cmd = "update" }, {}) meths.cmd({ cmd = "buffer", count = 0 }, {}) end) + it('doesn\'t suppress errors when used in keymapping', function() + meths.exec_lua([[ + vim.keymap.set("n", "[l", + function() vim.api.nvim_cmd({ cmd = "echo", args = {"foo"} }, {}) end) + ]], {}) + feed("[l") + neq(nil, string.find(eval("v:errmsg"), "E5108:")) + end) end) end) -- cgit From 55246d44f92beb17898d006e5324bf2d44f44c31 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 21 May 2022 15:55:48 +0200 Subject: fix(autocmds): separate command from desc (#18617) --- test/functional/api/autocmd_spec.lua | 52 +++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index c08c411de1..491dac9f35 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -119,13 +119,45 @@ describe('autocmd api', function() describe('desc', function() it('can add description to one autocmd', function() + local cmd = "echo 'Should Not Have Errored'" + local desc = "Can show description" meths.create_autocmd("BufReadPost", { pattern = "*.py", - command = "echo 'Should Not Have Errored'", - desc = "Can show description", + command = cmd, + desc = desc, }) - eq("Can show description", meths.get_autocmds { event = "BufReadPost" }[1].desc) + eq(desc, meths.get_autocmds { event = "BufReadPost" }[1].desc) + eq(cmd, meths.get_autocmds { event = "BufReadPost" }[1].command) + end) + + it('can add description to one autocmd that uses a callback', function() + local desc = 'Can show description' + meths.set_var('desc', desc) + + exec_lua([[ + local callback = function() print 'Should Not Have Errored' end + vim.api.nvim_create_autocmd("BufReadPost", { + pattern = "*.py", + callback = callback, + desc = vim.g.desc, + }) + ]]) + + eq(desc, meths.get_autocmds({ event = 'BufReadPost' })[1].desc) + matches('', meths.get_autocmds({ event = 'BufReadPost' })[1].command) + end) + + it('will not add a description unless it was provided', function() + exec_lua([[ + local callback = function() print 'Should Not Have Errored' end + vim.api.nvim_create_autocmd("BufReadPost", { + pattern = "*.py", + callback = callback, + }) + ]]) + + eq(nil, meths.get_autocmds({ event = 'BufReadPost' })[1].desc) end) it('can add description to multiple autocmd', function() @@ -169,15 +201,11 @@ describe('autocmd api', function() ]] meths.exec_autocmds("User", {pattern = "Test"}) - eq({{ - buflocal = false, - command = 'A test autocommand', - desc = 'A test autocommand', - event = 'User', - id = 1, - once = false, - pattern = 'Test', - }}, meths.get_autocmds({event = "User", pattern = "Test"})) + + local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' }) + local first = aus[1] + eq(first.id, 1) + meths.set_var("some_condition", true) meths.exec_autocmds("User", {pattern = "Test"}) eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) -- cgit From 9988d2f214963b3cac70026d6ad4bb058837afd9 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sun, 29 May 2022 10:42:00 +0600 Subject: feat(nvim_create_user_command): pass structured modifiers to commands Adds an `smods` key to `nvim_create_user_command` Lua command callbacks, which has command modifiers but in a structured format. This removes the need to manually parse command modifiers. It also reduces friction in using `nvim_cmd` inside a Lua command callback. --- test/functional/api/command_spec.lua | 133 +++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index e4963e8a65..d6d75e93e4 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -120,6 +120,25 @@ describe('nvim_create_user_command', function() line1 = 1, line2 = 1, mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = 0, + verbose = 0, + vertical = false, + }, range = 0, count = 2, reg = "", @@ -135,6 +154,25 @@ describe('nvim_create_user_command', function() line1 = 1, line2 = 1, mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = 0, + verbose = 0, + vertical = false, + }, range = 0, count = 2, reg = "", @@ -150,6 +188,25 @@ describe('nvim_create_user_command', function() line1 = 1, line2 = 1, mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = 0, + verbose = 0, + vertical = false, + }, range = 0, count = 2, reg = "", @@ -165,6 +222,25 @@ describe('nvim_create_user_command', function() line1 = 10, line2 = 10, mods = "botright", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "botright", + tab = 0, + verbose = 0, + vertical = false, + }, range = 1, count = 10, reg = "", @@ -180,6 +256,25 @@ describe('nvim_create_user_command', function() line1 = 1, line2 = 42, mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = 0, + verbose = 0, + vertical = false, + }, range = 1, count = 42, reg = "", @@ -195,6 +290,25 @@ describe('nvim_create_user_command', function() line1 = 1, line2 = 1, mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = 0, + verbose = 0, + vertical = false, + }, range = 0, count = 2, reg = "", @@ -222,6 +336,25 @@ describe('nvim_create_user_command', function() line1 = 1, line2 = 1, mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = 0, + verbose = 0, + vertical = false, + }, range = 0, count = 2, reg = "", -- cgit From 46536f53e82967dcac8d030ee3394cdb156f9603 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 20 Apr 2022 17:02:18 +0600 Subject: feat: add preview functionality to user commands Adds a Lua-only `preview` flag to user commands which allows the command to be incrementally previewed like `:substitute` when 'inccommand' is set. --- test/functional/api/command_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index d6d75e93e4..253371557a 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -16,8 +16,8 @@ local feed = helpers.feed local funcs = helpers.funcs describe('nvim_get_commands', function() - local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', range=NIL, register=false, keepscript=false, script_id=0, } - local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', range=NIL, register=false, keepscript=false, script_id=0, } + local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', preview=false, range=NIL, register=false, keepscript=false, script_id=0, } + local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', preview=false, range=NIL, register=false, keepscript=false, script_id=0, } before_each(clear) it('gets empty list if no commands were defined', function() @@ -59,11 +59,11 @@ describe('nvim_get_commands', function() end) it('gets various command attributes', function() - local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd ', name='TestCmd', nargs='1', range='10', register=false, keepscript=false, script_id=0, } - local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger ', name='Finger', nargs='+', range=NIL, register=false, keepscript=false, script_id=1, } - local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R2_foo()', name='Cmd2', nargs='*', range=NIL, register=false, keepscript=false, script_id=2, } - local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R3_ohyeah()', name='Cmd3', nargs='0', range=NIL, register=false, keepscript=false, script_id=3, } - local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R4_just_great()', name='Cmd4', nargs='0', range=NIL, register=true, keepscript=false, script_id=4, } + local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd ', name='TestCmd', nargs='1', preview=false, range='10', register=false, keepscript=false, script_id=0, } + local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger ', name='Finger', nargs='+', preview=false, range=NIL, register=false, keepscript=false, script_id=1, } + local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R2_foo()', name='Cmd2', nargs='*', preview=false, range=NIL, register=false, keepscript=false, script_id=2, } + local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R3_ohyeah()', name='Cmd3', nargs='0', preview=false, range=NIL, register=false, keepscript=false, script_id=3, } + local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253R4_just_great()', name='Cmd4', nargs='0', preview=false, range=NIL, register=true, keepscript=false, script_id=4, } source([[ let s:foo = 1 command -complete=custom,ListUsers -nargs=+ Finger !finger -- cgit From 96c494dec345f9a3dd2676048292267552e3f5f8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Jun 2022 21:37:01 +0800 Subject: refactor: correct comments and assertions about mapping rhs (#18821) Also avoid referring to mappings as "keymaps" in commands and docs. *map_empty_rhs* *map-empty-rhs* You can create an empty {rhs} by typing nothing after a single CTRL-V (you have to type CTRL-V two times). Unfortunately, you cannot do this in a vimrc file. --- test/functional/api/keymap_spec.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 4fb2d55a76..4bee10a006 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -321,7 +321,7 @@ describe('nvim_get_keymap', function() eq({space_table}, meths.get_keymap('n')) end) - it('can handle lua keymaps', function() + it('can handle lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) @@ -606,6 +606,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq({''}, curbufmeths.get_lines(0, -1, 0)) eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) + + -- a single ^V in RHS is also (see :h map-empty-rhs) + meths.set_keymap('i', 'lhs', '\022', {}) + command('normal ilhs') + eq({''}, curbufmeths.get_lines(0, -1, 0)) + eq(generate_mapargs('i', 'lhs', '\022', {}), + get_mapargs('i', 'lhs')) end) it('treats an empty RHS in a mapping like a ', function() @@ -785,7 +792,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) - it (':map command shows lua keymap correctly', function() + it (':map command shows lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -793,7 +800,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() "^\nn asdf ")) end) - it ('mapcheck() returns lua keymap correctly', function() + it ('mapcheck() returns lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -801,7 +808,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() "^")) end) - it ('maparg() returns lua keymap correctly', function() + it ('maparg() returns lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -895,7 +902,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('\nNo mapping found', helpers.exec_capture('nmap ')) end) - it('can set descriptions on keymaps', function() + it('can set descriptions on mappings', function() meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"}) eq(generate_mapargs('n', 'lhs', 'rhs', {desc="map description"}), get_mapargs('n', 'lhs')) eq("\nn lhs rhs\n map description", -- cgit From 9aba2043351c79cd9bc8fa7b229ee7629ba178f0 Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Sat, 4 Jun 2022 01:29:49 +1000 Subject: fix(hl): set Normal hl group sg_attr value #18820 fix #18024 --- test/functional/api/highlight_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a2f8353868..785f72b3db 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -337,4 +337,10 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl3')) end) + + it ("correctly sets 'Normal' internal properties", function() + -- Normal has some special handling internally. #18024 + meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'}) + eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true)) + end) end) -- cgit From ff20d40321399fa187bd350f9619cf6418d7eb6e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Jun 2022 05:56:36 +0200 Subject: docs: fix typos (#18269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zeertzjq Co-authored-by: Dan Sully Co-authored-by: saher Co-authored-by: Stephan Seitz Co-authored-by: Benedikt Müller Co-authored-by: Andrey Mishchenko Co-authored-by: Famiu Haque Co-authored-by: Oliver Marriott --- test/functional/api/window_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 9aacac37bf..901d24327c 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -153,7 +153,7 @@ describe('API/win', function() [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText [2] = {background = Screen.colors.Grey90}, -- CursorLine [3] = {bold = true, reverse = true}, -- StatusLine - [4] = {reverse = true}, -- VertSplit, StatusLineNC + [4] = {reverse = true}, -- StatusLineNC }) screen:attach() command('set ruler') -- cgit From c84bd9e21fb1e5c55c9c5370b07271a6ae96f19c Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 8 Jun 2022 09:06:36 +0600 Subject: fix(nvim_create_user_command): make `smods` work with `nvim_cmd` Closes #18876. --- test/functional/api/command_spec.lua | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 253371557a..a9ec2b6541 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -136,7 +136,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 0, @@ -170,7 +170,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 0, @@ -204,7 +204,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 0, @@ -238,7 +238,7 @@ describe('nvim_create_user_command', function() silent = false, split = "botright", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 1, @@ -272,7 +272,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 1, @@ -306,7 +306,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 0, @@ -352,7 +352,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, - verbose = 0, + verbose = -1, vertical = false, }, range = 0, @@ -418,6 +418,16 @@ describe('nvim_create_user_command', function() vim.api.nvim_create_user_command('💩', 'echo "hi"', {}) ]])) end) + + it('smods can be used with nvim_cmd', function() + exec_lua[[ + vim.api.nvim_create_user_command('MyEcho', function(opts) + vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {}) + end, {}) + ]] + + eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) + end) end) describe('nvim_del_user_command', function() -- cgit From 3da3cfc864e89a2dca6917183915683373c85af8 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:18:56 +0200 Subject: feat(autocmds): retrieve lua callback (#18642) add a new `callback` field to `nvim_get_autocmds` --- test/functional/api/autocmd_spec.lua | 54 ++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 491dac9f35..5dfcd09438 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -135,17 +135,22 @@ describe('autocmd api', function() local desc = 'Can show description' meths.set_var('desc', desc) - exec_lua([[ + local result = exec_lua([[ local callback = function() print 'Should Not Have Errored' end vim.api.nvim_create_autocmd("BufReadPost", { pattern = "*.py", callback = callback, desc = vim.g.desc, }) + local aus = vim.api.nvim_get_autocmds({ event = 'BufReadPost' }) + local first = aus[1] + return { + desc = first.desc, + cbtype = type(first.callback) + } ]]) - eq(desc, meths.get_autocmds({ event = 'BufReadPost' })[1].desc) - matches('', meths.get_autocmds({ event = 'BufReadPost' })[1].command) + eq({ desc = desc, cbtype = 'function' }, result) end) it('will not add a description unless it was provided', function() @@ -465,6 +470,49 @@ describe('autocmd api', function() -- 3-7 for the 5 we make in the autocmd eq({1, 2, 3, 4, 5, 6, 7}, bufs) end) + + it('can retrieve a callback from an autocmd', function() + local content = 'I Am A Callback' + meths.set_var('content', content) + + local result = exec_lua([[ + local cb = function() return vim.g.content end + vim.api.nvim_create_autocmd("User", { + pattern = "TestTrigger", + desc = "A test autocommand with a callback", + callback = cb, + }) + local aus = vim.api.nvim_get_autocmds({ event = 'User', pattern = 'TestTrigger'}) + local first = aus[1] + return { + cb = { + type = type(first.callback), + can_retrieve = first.callback() == vim.g.content + } + } + ]]) + + eq("function", result.cb.type) + eq(true, result.cb.can_retrieve) + end) + + it('will return an empty string as the command for an autocmd that uses a callback', function() + local result = exec_lua([[ + local callback = function() print 'I Am A Callback' end + vim.api.nvim_create_autocmd("BufWritePost", { + pattern = "*.py", + callback = callback, + }) + local aus = vim.api.nvim_get_autocmds({ event = 'BufWritePost' }) + local first = aus[1] + return { + command = first.command, + cbtype = type(first.callback) + } + ]]) + + eq({ command = "", cbtype = 'function' }, result) + end) end) describe('groups', function() -- cgit From e3281d992e1b9366d67a4b4399e3b5e11bb6c1cc Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 8 Jun 2022 23:22:50 +0200 Subject: fix(tests): check for EOF on exit of nvim properly --- test/functional/api/vim_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 55535a92e5..ea5725d836 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -27,6 +27,7 @@ local write_file = helpers.write_file local exec_lua = helpers.exec_lua local exc_exec = helpers.exc_exec local insert = helpers.insert +local expect_exit = helpers.expect_exit local pcall_err = helpers.pcall_err local format_string = helpers.format_string @@ -2617,7 +2618,7 @@ describe('API', function() it('does not cause heap-use-after-free on exit while setting options', function() command('au OptionSet * q') - command('silent! call nvim_create_buf(0, 1)') + expect_exit(command, 'silent! call nvim_create_buf(0, 1)') end) end) -- cgit From 837360868b557dcb897690178d891c87e91fc27f Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Jun 2022 13:05:17 +0200 Subject: fix(tests): missing clear() #18927 This was caught in #18674 since it allows test isolation --- test/functional/api/buffer_updates_spec.lua | 2 ++ test/functional/api/version_spec.lua | 1 + 2 files changed, 3 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 2728dcf74c..3d257e9477 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -96,6 +96,8 @@ local function reopenwithfolds(b) end describe('API: buffer events:', function() + before_each(clear) + it('when lines are added', function() local b, tick = editoriginal(true) diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index daac862ec8..771192e9ab 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -93,6 +93,7 @@ describe("api metadata", function() local api, compat, stable, api_level local old_api = {} setup(function() + clear() -- Ensure a session before requesting api_info. api = meths.get_api_info()[2] compat = api.version.api_compatible api_level = api.version.api_level -- cgit From 8f065205946844d87f00d6c55517521e3809f821 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 May 2022 21:44:15 -0700 Subject: feat(logging): include test-id in log messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: 1. Log messages (especially in CI) are hard to correlate with tests. 2. Since b353a5c05f02 #11886, dumplog() prints the logs next to test failures. This is noisy and gets in the way of the test results. Solution: 1. Associate an incrementing id with each test and include it in log messages. - FUTURE: add v:name so Nvim instances can be formally "named"? 2. Mention "child" in log messages if the current Nvim is a child (based on the presence of $NVIM). BEFORE: DBG … 12345 UI: event DBG … 12345 log_server_msg:722: RPC ->ch 1: … DBG … 12345 UI: flush DBG … 12345 inbuf_poll:444: blocking... events_enabled=1 events_pending=0 DBG … 23454 UI: stop INF … 23454 os_exit:594: Nvim exit: 0 AFTER: DBG … T57 UI: event DBG … T57 log_server_msg:722: RPC ->ch 1: … DBG … T57 UI: flush DBG … T57 inbuf_poll:444: blocking... events_enabled=1 events_pending=0 DBG … T57/child UI: stop INF … T57/child os_exit:594: Nvim exit: 0 --- test/functional/api/keymap_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 4bee10a006..6bc6651e04 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -336,7 +336,7 @@ describe('nvim_get_keymap', function() return GlobalCount ]]) local mapargs = meths.get_keymap('n') - assert.Truthy(type(mapargs[1].callback) == 'number', 'callback is not luaref number') + assert(type(mapargs[1].callback) == 'number', 'callback is not luaref number') mapargs[1].callback = nil eq({ lhs='asdf', @@ -815,7 +815,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() assert.truthy(string.match(funcs.maparg('asdf', 'n'), "^")) local mapargs = funcs.maparg('asdf', 'n', false, true) - assert.Truthy(type(mapargs.callback) == 'number', 'callback is not luaref number') + assert(type(mapargs.callback) == 'number', 'callback is not luaref number') mapargs.callback = nil eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs) end) -- cgit From 98e2da7d50b8f22edb20cdb744788ef0085d0cb6 Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Fri, 17 Jun 2022 11:33:58 +1000 Subject: fix(hl): return cterm fg/bg even if they match Normal #18981 Fixes #18980 - 831fa45ad84e is related but this doesn't regress that - The `cterm_normal_fg_color != ae.cterm_fg_color` comparison is originally carried from patch to patch starting all the way back in 29bc6dfabde2 where it was avoiding setting a HL attr. But `hlattrs2dict()` now is just informational. --- test/functional/api/highlight_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 785f72b3db..8235374f22 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -133,6 +133,13 @@ describe('API: highlight',function() eq({ underline = true, standout = true, }, meths.get_hl_by_name('cursorline', 0)); + -- Test cterm & Normal values. #18024 (tail) & #18980 + -- Ensure Normal, and groups that match Normal return their fg & bg cterm values + meths.set_hl(0, 'Normal', {ctermfg = 17, ctermbg = 213}) + meths.set_hl(0, 'NotNormal', {ctermfg = 17, ctermbg = 213}) + -- Note colors are "cterm" values, not rgb-as-ints + eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'Normal', false)) + eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'NotNormal', false)) end) it('nvim_get_hl_id_by_name', function() -- cgit From 58d028f64bb0ddc80b6201906880182d14ad9a3c Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 20 Jun 2022 08:20:06 -0600 Subject: feat(api): add "buf" and "win" to nvim_get_option_value These mirror their counterparts in nvim_set_option_value. --- test/functional/api/vim_spec.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ea5725d836..ef6798dea3 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1453,10 +1453,21 @@ describe('API', function() it('set local window options', function() -- Different to nvim_win_set_option nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'}) - eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) + eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0, scope = 'local'})) command("set modified hidden") command("enew") -- edit new buffer, window option is reset - eq('', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) + eq('', nvim('get_option_value', 'colorcolumn', {win = 0, scope = 'local'})) + end) + + it('get buffer or window-local options', function() + nvim('command', 'new') + local buf = nvim('get_current_buf').id + nvim('buf_set_option', buf, 'tagfunc', 'foobar') + eq('foobar', nvim('get_option_value', 'tagfunc', {buf = buf})) + + local win = nvim('get_current_win').id + nvim('win_set_option', win, 'number', true) + eq(true, nvim('get_option_value', 'number', {win = win})) end) end) -- cgit From 374e0b6678b21105bd5a26265e483cc4d9dbcaad Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 21 Jun 2022 12:29:49 +0200 Subject: perf(highlight): don't allocate duplicates for color names --- test/functional/api/highlight_spec.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 8235374f22..c57c1b12dc 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -293,19 +293,20 @@ describe("API: set highlight", function() eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,underlineline,undercurl,underdot,underdash,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2')) - -- Colors are stored exactly as they are defined. + -- Colors are stored with the name they are defined, but + -- with canonical casing meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue'}) - eq('Test_hl3 xxx guifg=bLue guibg=reD', + eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) end) it ("can modify a highlight in the global namespace", function() meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue'}) - eq('Test_hl3 xxx guifg=blue guibg=red', + eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) meths.set_hl(0, 'Test_hl3', { bg = 'red' }) - eq('Test_hl3 xxx guibg=red', + eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12}) @@ -327,7 +328,7 @@ describe("API: set highlight", function() pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'})) meths.set_hl(0, 'Test_hl3', {fg='#FF00FF'}) - eq('Test_hl3 xxx guifg=#FF00FF', + eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) eq("'#FF00FF' is not a valid color", @@ -340,7 +341,7 @@ describe("API: set highlight", function() end meths.set_hl(0, 'Test_hl3', {fg='#FF00FF', blend=50}) - eq('Test_hl3 xxx guifg=#FF00FF blend=50', + eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) end) -- cgit From 3c85fd817ee57793503b29202ce07166f0a48480 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Jun 2022 21:38:00 +0800 Subject: fix(api): check for inclusive buffer line index out of bounds correctly (#19056) --- test/functional/api/buffer_spec.lua | 75 +++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 23 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index dd3af8c28f..dc668e7201 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -227,8 +227,8 @@ describe('api/buf', function() it('can get a single line with strict indexing', function() set_lines(0, 1, true, {'line1.a'}) eq(1, line_count()) -- sanity - eq(false, pcall(get_lines, 1, 2, true)) - eq(false, pcall(get_lines, -3, -2, true)) + eq('Index out of bounds', pcall_err(get_lines, 1, 2, true)) + eq('Index out of bounds', pcall_err(get_lines, -3, -2, true)) end) it('can get a single line with non-strict indexing', function() @@ -240,11 +240,11 @@ describe('api/buf', function() it('can set and delete a single line with strict indexing', function() set_lines(0, 1, true, {'line1.a'}) - eq(false, pcall(set_lines, 1, 2, true, {'line1.b'})) - eq(false, pcall(set_lines, -3, -2, true, {'line1.c'})) + eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, {'line1.b'})) + eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, {'line1.c'})) eq({'line1.a'}, get_lines(0, -1, true)) - eq(false, pcall(set_lines, 1, 2, true, {})) - eq(false, pcall(set_lines, -3, -2, true, {})) + eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, {})) + eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, {})) eq({'line1.a'}, get_lines(0, -1, true)) end) @@ -302,9 +302,9 @@ describe('api/buf', function() set_lines(0, -1, true, {'a', 'b', 'c'}) eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity - eq(false, pcall(get_lines, 3, 4, true)) - eq(false, pcall(get_lines, 3, 10, true)) - eq(false, pcall(get_lines, -5, -5, true)) + eq('Index out of bounds', pcall_err(get_lines, 3, 4, true)) + eq('Index out of bounds', pcall_err(get_lines, 3, 10, true)) + eq('Index out of bounds', pcall_err(get_lines, -5, -5, true)) -- empty or inverted ranges are not errors eq({}, get_lines(3, -1, true)) eq({}, get_lines(-3, -4, true)) @@ -316,10 +316,10 @@ describe('api/buf', function() eq({'c'}, get_lines(-2, 5, false)) eq({'a', 'b', 'c'}, get_lines(0, 6, false)) - eq(false, pcall(set_lines, 4, 6, true, {'d'})) + eq('Index out of bounds', pcall_err(set_lines, 4, 6, true, {'d'})) set_lines(4, 6, false, {'d'}) eq({'a', 'b', 'c', 'd'}, get_lines(0, -1, true)) - eq(false, pcall(set_lines, -6, -6, true, {'e'})) + eq('Index out of bounds', pcall_err(set_lines, -6, -6, true, {'e'})) set_lines(-6, -6, false, {'e'}) eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true)) end) @@ -392,7 +392,7 @@ describe('api/buf', function() end) end) - describe('nvim_buf_get_lines, nvim_buf_set_text', function() + describe('nvim_buf_set_text', function() local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text it('works', function() @@ -430,6 +430,10 @@ describe('api/buf', function() set_text(-1, 0, -1, 0, {'text'}) eq({'goodbye bar', 'text'}, get_lines(0, 2, true)) + + -- can append to a line + set_text(1, 4, -1, 4, {' and', 'more'}) + eq({'goodbye bar', 'text and', 'more'}, get_lines(0, 3, true)) end) it('works with undo', function() @@ -513,12 +517,12 @@ describe('api/buf', function() eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {})) eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {})) - -- marks should be shifted over by the correct number of bytes for multibyte - -- chars - set_text(0, 0, 0, 0, {'Ø'}) - eq({0, 3}, curbufmeths.get_extmark_by_id(ns, id1, {})) - eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id2, {})) - eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id3, {})) + -- marks should be shifted over by the correct number of bytes for multibyte + -- chars + set_text(0, 0, 0, 0, {'Ø'}) + eq({0, 3}, curbufmeths.get_extmark_by_id(ns, id1, {})) + eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id2, {})) + eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id3, {})) end) it("correctly marks changed region for redraw #13890", function() @@ -540,18 +544,39 @@ describe('api/buf', function() | ]]) + end) + it('errors on out-of-range', function() + insert([[ + hello foo! + text]]) + eq('start_row out of bounds', pcall_err(set_text, 2, 0, 3, 0, {})) + eq('start_row out of bounds', pcall_err(set_text, -3, 0, 0, 0, {})) + eq('end_row out of bounds', pcall_err(set_text, 0, 0, 2, 0, {})) + eq('end_row out of bounds', pcall_err(set_text, 0, 0, -3, 0, {})) + eq('start_col out of bounds', pcall_err(set_text, 1, 5, 1, 5, {})) + eq('end_col out of bounds', pcall_err(set_text, 1, 0, 1, 5, {})) + end) + + it('errors when start is greater than end', function() + insert([[ + hello foo! + text]]) + eq('start is higher than end', pcall_err(set_text, 1, 0, 0, 0, {})) + eq('start is higher than end', pcall_err(set_text, 0, 1, 0, 0, {})) end) end) describe('nvim_buf_get_text', function() local get_text = curbufmeths.get_text - it('works', function() + before_each(function() insert([[ hello foo! text]]) + end) + it('works', function() eq({'hello'}, get_text(0, 0, 0, 5, {})) eq({'hello foo!'}, get_text(0, 0, 0, 42, {})) eq({'foo!'}, get_text(0, 6, 0, 10, {})) @@ -562,13 +587,17 @@ describe('api/buf', function() end) it('errors on out-of-range', function() - eq(false, pcall(get_text, 2, 0, 3, 0, {})) - eq(false, pcall(get_text, 0, 0, 4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 2, 0, 3, 0, {})) + eq('Index out of bounds', pcall_err(get_text, -3, 0, 0, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 2, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, -3, 0, {})) + -- no ml_get errors should happen #19017 + eq('', meths.get_vvar('errmsg')) end) it('errors when start is greater than end', function() - eq(false, pcall(get_text, 1, 0, 0, 0, {})) - eq(false, pcall(get_text, 0, 1, 0, 0, {})) + eq('start is higher than end', pcall_err(get_text, 1, 0, 0, 0, {})) + eq('start_col must be less than end_col', pcall_err(get_text, 0, 1, 0, 0, {})) end) end) -- cgit From da358d452186277ba2feb26f1a90a9f5ccc31539 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 25 Jun 2022 19:50:06 +0200 Subject: feat(api): support pattern array for exec_autocmds --- test/functional/api/autocmd_spec.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 5dfcd09438..a923f5df0e 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -686,6 +686,26 @@ describe('autocmd api', function() eq(true, meths.get_var("autocmd_executed")) end) + it("can trigger multiple patterns", function() + meths.set_var("autocmd_executed", 0) + + meths.create_autocmd("BufReadPost", { + pattern = "*", + command = "let g:autocmd_executed += 1", + }) + + meths.exec_autocmds("BufReadPost", { pattern = { "*.lua", "*.vim" } }) + eq(2, meths.get_var("autocmd_executed")) + + meths.create_autocmd("BufReadPre", { + pattern = { "bar", "foo" }, + command = "let g:autocmd_executed += 10", + }) + + meths.exec_autocmds("BufReadPre", { pattern = { "foo", "bar", "baz", "frederick" }}) + eq(22, meths.get_var("autocmd_executed")) + end) + it("can pass the buffer", function() meths.set_var("buffer_executed", -1) eq(-1, meths.get_var("buffer_executed")) @@ -742,7 +762,7 @@ describe('autocmd api', function() meths.exec_autocmds("CursorHoldI", { buffer = 1 }) eq('none', meths.get_var("filename_executed")) - meths.exec_autocmds("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) + meths.exec_autocmds("CursorHoldI", { buffer = meths.get_current_buf() }) eq('__init__.py', meths.get_var("filename_executed")) -- Reset filename -- cgit From cf23695dd748281daaf68e69ac48bf9eb27f2425 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Jun 2022 14:10:13 +0800 Subject: fix(api): nvim_parse_cmd check for ambiguous user command (#19116) --- test/functional/api/vim_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ef6798dea3..c05345dd4c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3520,6 +3520,9 @@ describe('API', function() pcall_err(meths.parse_cmd, 'Fubar!', {})) eq('Error while parsing command line: E481: No range allowed', pcall_err(meths.parse_cmd, '4,6Fubar', {})) + command('command! Foobar echo foo') + eq('Error while parsing command line: E464: Ambiguous use of user-defined command', + pcall_err(meths.parse_cmd, 'F', {})) end) end) describe('nvim_cmd', function() -- cgit From 606ec8b70874095a62289f1df3934eca78625742 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 28 Jun 2022 16:22:29 +0600 Subject: feat(api): make `nvim_parse_cmd` and `nvim_cmd` support :filter Also fixes a memory leak in `parse_cmdline`. Closes #18954. --- test/functional/api/vim_spec.lua | 87 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c05345dd4c..858463efbd 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3167,6 +3167,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3203,6 +3207,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3239,6 +3247,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3275,6 +3287,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3311,6 +3327,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3347,6 +3367,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3383,6 +3407,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = true, + filter = { + pattern = "foo", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3398,7 +3426,45 @@ describe('API', function() tab = 2, verbose = 15 }, - }, meths.parse_cmd('15verbose silent! aboveleft topleft tab split foo.txt', {})) + }, meths.parse_cmd('15verbose silent! aboveleft topleft tab filter /foo/ split foo.txt', {})) + eq({ + cmd = 'split', + args = { 'foo.txt' }, + bang = false, + range = {}, + count = -1, + reg = '', + addr = '?', + magic = { + file = true, + bar = true + }, + nargs = '?', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + filter = { + pattern = "foo", + force = true + }, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = -1 + }, + }, meths.parse_cmd('filter! /foo/ split foo.txt', {})) end) it('works with user commands', function() command('command -bang -nargs=+ -range -addr=lines MyCommand echo foo') @@ -3420,6 +3486,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3456,6 +3526,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3493,6 +3567,10 @@ describe('API', function() browse = false, confirm = false, emsg_silent = false, + filter = { + pattern = "", + force = false + }, hide = false, keepalt = false, keepjumps = false, @@ -3604,6 +3682,13 @@ describe('API', function() meths.create_user_command("Foo", 'set verbose', {}) eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true })) eq(0, meths.get_option_value("verbose", {})) + command('edit foo.txt | edit bar.txt') + eq(' 1 #h "foo.txt" line 1', + meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = false } } }, + { output = true })) + eq(' 2 %a "bar.txt" line 1', + meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = true } } }, + { output = true })) end) it('works with magic.file', function() exec_lua([[ -- cgit From 995e4879153d0f4ea72dff446c175754a1873425 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Jun 2022 16:57:44 +0800 Subject: refactor(highlight)!: rename attributes to match Vim (#19159) Ref: https://github.com/vim/vim/commit/84f546363068e4ddfe14a8a2a2322bb8d3a25417 Rename: - `underlineline` to `underdouble` - `underdot` to `underdotted` - `underdash` to `underdashed` `underdouble` also now takes higher precedence than `undercurl`. --- test/functional/api/highlight_spec.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index c57c1b12dc..933103046c 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -29,10 +29,10 @@ describe('API: highlight',function() italic = true, reverse = true, underline = true, - underlineline = true, undercurl = true, - underdot = true, - underdash = true, + underdouble = true, + underdotted = true, + underdashed = true, strikethrough = true, } @@ -55,7 +55,7 @@ describe('API: highlight',function() eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*')) -- Test all highlight properties. - command('hi NewHighlight gui=underline,bold,underlineline,undercurl,underdot,underdash,italic,reverse,strikethrough') + command('hi NewHighlight gui=underline,bold,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough') eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true)) -- Test nil argument. @@ -205,9 +205,9 @@ describe("API: set highlight", function() reverse = true, undercurl = true, underline = true, - underdash = true, - underdot = true, - underlineline = true, + underdashed = true, + underdotted = true, + underdouble = true, strikethrough = true, cterm = { italic = true, @@ -224,9 +224,9 @@ describe("API: set highlight", function() reverse = true, undercurl = true, underline = true, - underdash = true, - underdot = true, - underlineline = true, + underdashed = true, + underdotted = true, + underdouble = true, strikethrough = true, } local highlight3_result_cterm = { @@ -290,7 +290,7 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl')) meths.set_hl(0, 'Test_hl2', highlight3_config) - eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,underlineline,undercurl,underdot,underdash,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa', + eq('Test_hl2 xxx cterm=undercurl,italic,reverse,strikethrough ctermfg=8 ctermbg=15 gui=bold,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2')) -- Colors are stored with the name they are defined, but -- cgit From f50135a32e11c535e1dc3a8e9460c5b4e640ee86 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 30 Jun 2022 13:16:46 +0200 Subject: feat: stdpath('run'), /tmp/nvim.user/ #18993 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Since c57f6b28d71d #8519, sockets are created in ~/.local/… but XDG spec says: "XDG_RUNTIME_DIR: Must be on the local filesystem", which implies that XDG_STATE_DIR is potentially non-local. - Not easy to inspect Nvim-created temp files (for debugging etc). Solution: - Store sockets in stdpath('run') ($XDG_RUNTIME_DIR). - Establish "/tmp/nvim.user/" as the tempdir root shared by all Nvims. - Make ok() actually useful. - Introduce assert_nolog(). closes #3517 closes #17093 --- test/functional/api/server_requests_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index cdcf08c348..00a4dd041d 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -170,7 +170,7 @@ describe('server -> client', function() if method == "notification" then eq('done!', eval('rpcrequest('..cid..', "nested")')) elseif method == "nested_done" then - ok(false, 'this should never have been sent') + ok(false, 'never sent', 'sent') end end -- cgit From 610cf9f95032bd219cb5695d169fe2cd698ec307 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Jun 2022 15:30:54 +0800 Subject: vim-patch:8.0.1570: can't use :popup for a menu in the terminal Problem: Can't use :popup for a menu in the terminal. (Wei Zhang) Solution: Make :popup work in the terminal. Also fix that entries were included that don't work in the current state. https://github.com/vim/vim/commit/29a2c08d792e4458a0af8371f5341394829fce29 --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 858463efbd..002bcd92a4 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3748,7 +3748,7 @@ describe('API', function() eq("foo", meths.cmd({ cmd = "Foo" }, { output = true })) end) it('errors if command is not implemented', function() - eq("Command not implemented: popup", pcall_err(meths.cmd, { cmd = "popup" }, {})) + eq("Command not implemented: winpos", pcall_err(meths.cmd, { cmd = "winpos" }, {})) end) it('works with empty arguments list', function() meths.cmd({ cmd = "update" }, {}) -- cgit From 7a907c3314f939a3d2983ac07edc5c9672957352 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 2 Jul 2022 19:35:11 +0800 Subject: feat(api): add `unsilent` to command APIs --- test/functional/api/command_spec.lua | 13 ++++++-- test/functional/api/vim_spec.lua | 61 +++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 28 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index a9ec2b6541..7eb7ee73f9 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -136,6 +136,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, + unsilent = false, verbose = -1, vertical = false, }, @@ -170,6 +171,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, + unsilent = false, verbose = -1, vertical = false, }, @@ -204,6 +206,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, + unsilent = false, verbose = -1, vertical = false, }, @@ -221,10 +224,10 @@ describe('nvim_create_user_command', function() bang = true, line1 = 10, line2 = 10, - mods = "botright", + mods = "confirm unsilent botright", smods = { browse = false, - confirm = false, + confirm = true, emsg_silent = false, hide = false, keepalt = false, @@ -238,6 +241,7 @@ describe('nvim_create_user_command', function() silent = false, split = "botright", tab = 0, + unsilent = true, verbose = -1, vertical = false, }, @@ -245,7 +249,7 @@ describe('nvim_create_user_command', function() count = 10, reg = "", }, exec_lua [=[ - vim.api.nvim_command('botright 10CommandWithLuaCallback! h\tey ') + vim.api.nvim_command('unsilent botright confirm 10CommandWithLuaCallback! h\tey ') return result ]=]) @@ -272,6 +276,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, + unsilent = false, verbose = -1, vertical = false, }, @@ -306,6 +311,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, + unsilent = false, verbose = -1, vertical = false, }, @@ -352,6 +358,7 @@ describe('nvim_create_user_command', function() silent = false, split = "", tab = 0, + unsilent = false, verbose = -1, vertical = false, }, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 002bcd92a4..989ed27e16 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3181,10 +3181,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('echo foo', {})) end) @@ -3221,10 +3222,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('4,6s/math.random/math.max/', {})) end) @@ -3261,10 +3263,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('buffer 1', {})) end) @@ -3301,10 +3304,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('put +', {})) end) @@ -3341,10 +3345,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('1,3delete * 5', {})) end) @@ -3381,10 +3386,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, }, }, meths.parse_cmd('w!', {})) end) @@ -3421,10 +3427,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = true, - vertical = false, split = "topleft", tab = 2, - verbose = 15 + unsilent = false, + verbose = 15, + vertical = false, }, }, meths.parse_cmd('15verbose silent! aboveleft topleft tab filter /foo/ split foo.txt', {})) eq({ @@ -3443,7 +3450,7 @@ describe('API', function() nextcmd = '', mods = { browse = false, - confirm = false, + confirm = true, emsg_silent = false, filter = { pattern = "foo", @@ -3459,12 +3466,13 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, - split = "", + split = "botright", tab = 0, - verbose = -1 + unsilent = true, + verbose = 0, + vertical = false, }, - }, meths.parse_cmd('filter! /foo/ split foo.txt', {})) + }, meths.parse_cmd('0verbose unsilent botright confirm filter! /foo/ split foo.txt', {})) end) it('works with user commands', function() command('command -bang -nargs=+ -range -addr=lines MyCommand echo foo') @@ -3500,10 +3508,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('4,6MyCommand! test it', {})) end) @@ -3540,10 +3549,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('argadd a.txt | argadd b.txt', {})) end) @@ -3581,10 +3591,11 @@ describe('API', function() noswapfile = false, sandbox = false, silent = false, - vertical = false, split = "", tab = 0, - verbose = -1 + unsilent = false, + verbose = -1, + vertical = false, } }, meths.parse_cmd('MyCommand test it', {})) end) -- cgit From 73526abbbdf08e68e572b8e54c583de5a0323484 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Jul 2022 09:31:05 +0800 Subject: fix(api): do not switch win/buf if getting option in current win/buf (#19383) --- test/functional/api/vim_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 989ed27e16..63a4e9a39c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1469,6 +1469,17 @@ describe('API', function() nvim('win_set_option', win, 'number', true) eq(true, nvim('get_option_value', 'number', {win = win})) end) + + it('getting current buffer option does not adjust cursor #19381', function() + nvim('command', 'new') + local buf = nvim('get_current_buf').id + local win = nvim('get_current_win').id + insert('some text') + feed('0v$') + eq({1, 9}, nvim('win_get_cursor', win)) + nvim('get_option_value', 'filetype', {buf = buf}) + eq({1, 9}, nvim('win_get_cursor', win)) + end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() -- cgit From 9f837a5dcf61e0b27778dd7127036e12d694d92c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Jul 2022 09:59:32 +0800 Subject: fix(api): fix nvim_parse_cmd interfere with printing line in Ex mode (#19400) --- test/functional/api/vim_spec.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 63a4e9a39c..3724dbf820 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3624,6 +3624,38 @@ describe('API', function() eq('Error while parsing command line: E464: Ambiguous use of user-defined command', pcall_err(meths.parse_cmd, 'F', {})) end) + it('does not interfere with printing line in Ex mode #19400', function() + local screen = Screen.new(60, 7) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, reverse = true}, -- MsgSeparator + }) + screen:attach() + insert([[ + foo + bar]]) + feed('gQ1') + screen:expect([[ + foo | + bar | + {0:~ }| + {0:~ }| + {1: }| + Entering Ex mode. Type "visual" to go to Normal mode. | + :1^ | + ]]) + eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {})) + feed('') + screen:expect([[ + foo | + bar | + {1: }| + Entering Ex mode. Type "visual" to go to Normal mode. | + :1 | + foo | + :^ | + ]]) + end) end) describe('nvim_cmd', function() it('works', function () -- cgit