aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua78
-rw-r--r--test/functional/autocmd/tabclose_spec.lua18
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua8
-rw-r--r--test/functional/eval/getline_spec.lua39
-rw-r--r--test/functional/eval/system_spec.lua10
-rw-r--r--test/functional/ex_cmds/map_spec.lua7
-rw-r--r--test/functional/ex_cmds/sign_spec.lua4
-rw-r--r--test/functional/helpers.lua14
-rw-r--r--test/functional/terminal/tui_spec.lua29
-rw-r--r--test/functional/ui/cmdline_highlight_spec.lua2
-rw-r--r--test/unit/eval/helpers.lua5
-rw-r--r--test/unit/eval/typval_spec.lua2
-rw-r--r--test/unit/keymap_spec.lua71
13 files changed, 254 insertions, 33 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index ff28e3d133..39db831fe3 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -37,7 +37,7 @@ describe('api', function()
os.remove(fname)
end)
- it("VimL error: fails (VimL error), does NOT update v:errmsg", function()
+ it("parse error: fails (specific error), does NOT update v:errmsg", function()
-- Most API methods return generic errors (or no error) if a VimL
-- expression fails; nvim_command returns the VimL error details.
local status, rv = pcall(nvim, "command", "bogus_command")
@@ -45,6 +45,82 @@ describe('api', function()
eq("E492:", string.match(rv, "E%d*:")) -- VimL error was returned.
eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
end)
+
+ it("runtime error: fails (specific error)", function()
+ local status, rv = pcall(nvim, "command_output", "buffer 23487")
+ eq(false, status) -- nvim_command() failed.
+ eq("E86: Buffer 23487 does not exist", string.match(rv, "E%d*:.*"))
+ eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ end)
+ end)
+
+ describe('nvim_command_output', function()
+ it('does not induce hit-enter prompt', function()
+ -- Induce a hit-enter prompt use nvim_input (non-blocking).
+ nvim('command', 'set cmdheight=1')
+ nvim('input', [[:echo "hi\nhi2"<CR>]])
+
+ -- Verify hit-enter prompt.
+ eq({mode='r', blocking=true}, nvim("get_mode"))
+ nvim('input', [[<C-c>]])
+
+ -- Verify NO hit-enter prompt.
+ nvim('command_output', [[echo "hi\nhi2"]])
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
+
+ it('captures command output', function()
+ eq('this is\nspinal tap',
+ nvim('command_output', [[echo "this is\nspinal tap"]]))
+ end)
+
+ it('captures empty command output', function()
+ eq('', nvim('command_output', 'echo'))
+ end)
+
+ it('captures single-char command output', function()
+ eq('x', nvim('command_output', 'echo "x"'))
+ end)
+
+ it('captures multiple commands', function()
+ eq('foo\n 1 %a "[No Name]" line 1',
+ nvim('command_output', 'echo "foo" | ls'))
+ end)
+
+ it('captures nested execute()', function()
+ eq('\nnested1\nnested2\n 1 %a "[No Name]" line 1',
+ nvim('command_output',
+ [[echo execute('echo "nested1\nnested2"') | ls]]))
+ end)
+
+ it('captures nested nvim_command_output()', function()
+ eq('nested1\nnested2\n 1 %a "[No Name]" line 1',
+ nvim('command_output',
+ [[echo nvim_command_output('echo "nested1\nnested2"') | ls]]))
+ end)
+
+ it('does not return shell |:!| output', function()
+ eq(':!echo "foo"\r\n', nvim('command_output', [[!echo "foo"]]))
+ end)
+
+ it("parse error: fails (specific error), does NOT update v:errmsg", function()
+ local status, rv = pcall(nvim, "command_output", "bogus commannnd")
+ eq(false, status) -- nvim_command_output() failed.
+ eq("E492: Not an editor command: bogus commannnd",
+ string.match(rv, "E%d*:.*"))
+ eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ -- Verify NO hit-enter prompt.
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
+
+ it("runtime error: fails (specific error)", function()
+ local status, rv = pcall(nvim, "command_output", "buffer 42")
+ eq(false, status) -- nvim_command_output() failed.
+ eq("E86: Buffer 42 does not exist", string.match(rv, "E%d*:.*"))
+ eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ -- Verify NO hit-enter prompt.
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
end)
describe('nvim_eval', function()
diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua
index fb777e7eea..b7c33dc3d8 100644
--- a/test/functional/autocmd/tabclose_spec.lua
+++ b/test/functional/autocmd/tabclose_spec.lua
@@ -11,10 +11,10 @@ describe('TabClosed', function()
repeat
nvim('command', 'tabnew')
until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
- eq("\ntabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
- eq("\ntabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
- eq("\ntabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
- eq("\ntabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
+ eq("tabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
+ eq("tabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
+ eq("tabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
+ eq("tabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
end)
it('is triggered when closing a window via bdelete from another tab', function()
@@ -23,7 +23,7 @@ describe('TabClosed', function()
nvim('command', '1tabedit Xtestfile')
nvim('command', 'normal! 1gt')
eq({1, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
- eq("\ntabclosed:2:2:1\ntabclosed:2:2:1", nvim('command_output', 'bdelete Xtestfile'))
+ eq("tabclosed:2:2:1\ntabclosed:2:2:1", nvim('command_output', 'bdelete Xtestfile'))
eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
end)
@@ -35,7 +35,7 @@ describe('TabClosed', function()
-- Only one tab is closed, and the alternate file is used for the other.
eq({2, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
- eq("\ntabclosed:2:2:2", nvim('command_output', 'bdelete Xtestfile2'))
+ eq("tabclosed:2:2:2", nvim('command_output', 'bdelete Xtestfile2'))
eq('Xtestfile1', nvim('eval', 'bufname("")'))
end)
end)
@@ -48,9 +48,9 @@ describe('TabClosed', function()
nvim('command', 'tabnew')
until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7
-- sanity check, we shouldn't match on tabs with numbers other than 2
- eq("\ntabclosed:7:7:6", nvim('command_output', 'tabclose'))
+ eq("tabclosed:7:7:6", nvim('command_output', 'tabclose'))
-- close tab page 2, current tab is now 5
- eq("\ntabclosed:2:2:5\ntabclosed:match", nvim('command_output', '2tabclose'))
+ eq("tabclosed:2:2:5\ntabclosed:match", nvim('command_output', '2tabclose'))
end)
end)
@@ -59,7 +59,7 @@ describe('TabClosed', function()
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
nvim('command', 'tabedit Xtestfile')
eq({2, 2}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
- eq("\ntabclosed:2:2:1", nvim('command_output', 'close'))
+ eq("tabclosed:2:2:1", nvim('command_output', 'close'))
eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
end)
end)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
index bdbe677132..59cac07b34 100644
--- a/test/functional/autocmd/tabnewentered_spec.lua
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -7,14 +7,14 @@ describe('TabNewEntered', function()
it('matches when entering any new tab', function()
clear()
nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")')
- eq("\ntabnewentered:2:2", nvim('command_output', 'tabnew'))
- eq("\n\"test.x2\" [New File]\ntabnewentered:3:3", nvim('command_output', 'tabnew test.x2'))
+ eq("tabnewentered:2:2", nvim('command_output', 'tabnew'))
+ eq("tabnewentered:3:3", nvim('command_output', 'tabnew test.x2'))
end)
end)
describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function()
nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"')
- eq('\n"Xtest-tabnewentered" [New File]\ntabnewentered:4:4\ntabnewentered:match',
+ eq('tabnewentered:4:4\ntabnewentered:match',
nvim('command_output', 'tabnew Xtest-tabnewentered'))
end)
end)
@@ -24,7 +24,7 @@ describe('TabNewEntered', function()
nvim('command', 'au! TabNewEntered * echom "entered"')
nvim('command', 'tabnew test.x2')
nvim('command', 'split')
- eq('\nentered', nvim('command_output', 'execute "normal \\<C-W>T"'))
+ eq('entered', nvim('command_output', 'execute "normal \\<C-W>T"'))
end)
end)
end)
diff --git a/test/functional/eval/getline_spec.lua b/test/functional/eval/getline_spec.lua
new file mode 100644
index 0000000000..3c56bde094
--- /dev/null
+++ b/test/functional/eval/getline_spec.lua
@@ -0,0 +1,39 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local call = helpers.call
+local clear = helpers.clear
+local eq = helpers.eq
+local expect = helpers.expect
+
+describe('getline()', function()
+ before_each(function()
+ clear()
+ call('setline', 1, {'a', 'b', 'c'})
+ expect([[
+ a
+ b
+ c]])
+ end)
+
+ it('returns empty string for invalid line', function()
+ eq('', call('getline', -1))
+ eq('', call('getline', 0))
+ eq('', call('getline', 4))
+ end)
+
+ it('returns empty list for invalid range', function()
+ eq({}, call('getline', 2, 1))
+ eq({}, call('getline', -1, 1))
+ eq({}, call('getline', 4, 4))
+ end)
+
+ it('returns value of valid line', function()
+ eq('b', call('getline', 2))
+ eq('a', call('getline', '.'))
+ end)
+
+ it('returns value of valid range', function()
+ eq({'a', 'b'}, call('getline', 1, 2))
+ eq({'a', 'b', 'c'}, call('getline', 1, 4))
+ end)
+end)
diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua
index e2b12b6bc9..4d1630042b 100644
--- a/test/functional/eval/system_spec.lua
+++ b/test/functional/eval/system_spec.lua
@@ -5,6 +5,7 @@ local eq, call, clear, eval, feed_command, feed, nvim =
helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command,
helpers.feed, helpers.nvim
local command = helpers.command
+local exc_exec = helpers.exc_exec
local iswin = helpers.iswin
local Screen = require('test.functional.ui.screen')
@@ -274,9 +275,12 @@ describe('system()', function()
end)
end)
- describe('input passed as Number', function()
- it('stringifies the input', function()
- eq('1', eval('system("cat", 1)'))
+ describe('Number input', function()
+ it('is treated as a buffer id', function()
+ command("put ='text in buffer 1'")
+ eq('\ntext in buffer 1\n', eval('system("cat", 1)'))
+ eq('Vim(echo):E86: Buffer 42 does not exist',
+ exc_exec('echo system("cat", 42)'))
end)
end)
diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua
index b46f83405e..84d5bc2335 100644
--- a/test/functional/ex_cmds/map_spec.lua
+++ b/test/functional/ex_cmds/map_spec.lua
@@ -5,6 +5,7 @@ local feed = helpers.feed
local meths = helpers.meths
local clear = helpers.clear
local command = helpers.command
+local expect = helpers.expect
describe(':*map', function()
before_each(clear)
@@ -18,4 +19,10 @@ describe(':*map', function()
feed('\24\25<C-x><C-y>')
eq(4, meths.get_var('counter'))
end)
+
+ it(':imap <M-">', function()
+ command('imap <M-"> foo')
+ feed('i-<M-">-')
+ expect('-foo-')
+ end)
end)
diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua
index b37e6e8563..df0f5db860 100644
--- a/test/functional/ex_cmds/sign_spec.lua
+++ b/test/functional/ex_cmds/sign_spec.lua
@@ -16,8 +16,8 @@ describe('sign', function()
nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf2)
-- now unplace without specifying a buffer
nvim('command', 'sign unplace 34')
- eq("\n--- Signs ---\n", nvim('command_output', 'sign place buffer='..buf1))
- eq("\n--- Signs ---\n", nvim('command_output', 'sign place buffer='..buf2))
+ eq("--- Signs ---\n", nvim('command_output', 'sign place buffer='..buf1))
+ eq("--- Signs ---\n", nvim('command_output', 'sign place buffer='..buf2))
end)
end)
end)
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 31a2c3b3ff..dfc4694272 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -644,7 +644,7 @@ local function alter_slashes(obj)
end
local function hexdump(str)
- local len = string.len( str )
+ local len = string.len(str)
local dump = ""
local hex = ""
local asc = ""
@@ -652,22 +652,20 @@ local function hexdump(str)
for i = 1, len do
if 1 == i % 8 then
dump = dump .. hex .. asc .. "\n"
- hex = string.format( "%04x: ", i - 1 )
+ hex = string.format("%04x: ", i - 1)
asc = ""
end
- local ord = string.byte( str, i )
- hex = hex .. string.format( "%02x ", ord )
+ local ord = string.byte(str, i)
+ hex = hex .. string.format("%02x ", ord)
if ord >= 32 and ord <= 126 then
- asc = asc .. string.char( ord )
+ asc = asc .. string.char(ord)
else
asc = asc .. "."
end
end
- return dump .. hex
- .. string.rep( " ", 8 - len % 8 ) .. asc
-
+ return dump .. hex .. string.rep(" ", 8 - len % 8) .. asc
end
local module = {
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 745bfeecf9..a62c03b70f 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -6,15 +6,18 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local Screen = require('test.functional.ui.screen')
local eq = helpers.eq
-local feed_data = thelpers.feed_data
local feed_command = helpers.feed_command
+local feed_data = thelpers.feed_data
local clear = helpers.clear
+local command = helpers.command
+local eval = helpers.eval
local nvim_dir = helpers.nvim_dir
local retry = helpers.retry
local nvim_prog = helpers.nvim_prog
local nvim_set = helpers.nvim_set
local ok = helpers.ok
local read_file = helpers.read_file
+local wait = helpers.wait
if helpers.pending_win32(pending) then return end
@@ -40,6 +43,28 @@ describe('tui', function()
screen:detach()
end)
+ it('rapid resize #7572 #7628', function()
+ -- Need buffer rows to provoke the behavior.
+ feed_data(":edit test/functional/fixtures/bigfile.txt:")
+ command('call jobresize(b:terminal_job_id, 58, 9)')
+ command('call jobresize(b:terminal_job_id, 62, 13)')
+ command('call jobresize(b:terminal_job_id, 100, 42)')
+ command('call jobresize(b:terminal_job_id, 37, 1000)')
+ -- Resize to <5 columns.
+ screen:try_resize(4, 44)
+ command('call jobresize(b:terminal_job_id, 4, 1000)')
+ -- Resize to 1 row, then to 1 column, then increase rows to 4.
+ screen:try_resize(44, 1)
+ command('call jobresize(b:terminal_job_id, 44, 1)')
+ screen:try_resize(1, 1)
+ command('call jobresize(b:terminal_job_id, 1, 1)')
+ screen:try_resize(1, 4)
+ command('call jobresize(b:terminal_job_id, 1, 4)')
+ screen:try_resize(57, 17)
+ command('call jobresize(b:terminal_job_id, 57, 17)')
+ eq(2, eval("1+1")) -- Still alive?
+ end)
+
it('accepts basic utf-8 input', function()
feed_data('iabc\ntest1\ntest2')
screen:expect([[
@@ -448,7 +473,7 @@ describe("tui 't_Co' (terminal colors)", function()
nvim_set))
feed_data(":echo &t_Co\n")
- helpers.wait()
+ wait()
local tline
if maxcolors == 8 or maxcolors == 16 then
tline = "~ "
diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua
index 73fe94c056..ffb6a26aef 100644
--- a/test/functional/ui/cmdline_highlight_spec.lua
+++ b/test/functional/ui/cmdline_highlight_spec.lua
@@ -849,7 +849,7 @@ describe('Ex commands coloring support', function()
{EOB:~ }|
|
]])
- eq('\nError detected while processing :\nE605: Exception not caught: 42',
+ eq('Error detected while processing :\nE605: Exception not caught: 42',
meths.command_output('messages'))
end)
it('errors out when failing to get callback', function()
diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua
index 6babd4be77..3d1c42c3a0 100644
--- a/test/unit/eval/helpers.lua
+++ b/test/unit/eval/helpers.lua
@@ -312,7 +312,7 @@ local lua2typvalt_type_tab = {
processed[l].lv_refcount = processed[l].lv_refcount + 1
return typvalt(eval.VAR_LIST, {v_list=processed[l]})
end
- local lst = populate_list(eval.tv_list_alloc(), l, processed)
+ local lst = populate_list(eval.tv_list_alloc(#l), l, processed)
return typvalt(eval.VAR_LIST, {v_list=lst})
end,
[dict_type] = function(l, processed)
@@ -433,7 +433,8 @@ local function int(n)
end
local function list(...)
- return populate_list(ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref),
+ return populate_list(ffi.gc(eval.tv_list_alloc(select('#', ...)),
+ eval.tv_list_unref),
{...}, {})
end
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index b668144175..919a42fbb9 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -2407,7 +2407,7 @@ describe('typval.c', function()
describe('list ret()', function()
itp('works', function()
local rettv = typvalt(lib.VAR_UNKNOWN)
- local l = lib.tv_list_alloc_ret(rettv)
+ local l = lib.tv_list_alloc_ret(rettv, 0)
eq(empty_list, typvalt2lua(rettv))
eq(rettv.vval.v_list, l)
end)
diff --git a/test/unit/keymap_spec.lua b/test/unit/keymap_spec.lua
new file mode 100644
index 0000000000..595a19eb17
--- /dev/null
+++ b/test/unit/keymap_spec.lua
@@ -0,0 +1,71 @@
+local helpers = require("test.unit.helpers")(after_each)
+local itp = helpers.gen_itp(it)
+
+local ffi = helpers.ffi
+local eq = helpers.eq
+local neq = helpers.neq
+
+local keymap = helpers.cimport("./src/nvim/keymap.h")
+
+describe('keymap.c', function()
+
+ describe('find_special_key()', function()
+ local srcp = ffi.new('const unsigned char *[1]')
+ local modp = ffi.new('int[1]')
+
+ itp('no keycode', function()
+ srcp[0] = 'abc'
+ eq(0, keymap.find_special_key(srcp, 3, modp, false, false, false))
+ end)
+
+ itp('keycode with multiple modifiers', function()
+ srcp[0] = '<C-M-S-A>'
+ neq(0, keymap.find_special_key(srcp, 9, modp, false, false, false))
+ neq(0, modp[0])
+ end)
+
+ itp('case-insensitive', function()
+ -- Compare other capitalizations to this.
+ srcp[0] = '<C-A>'
+ local all_caps_key =
+ keymap.find_special_key(srcp, 5, modp, false, false, false)
+ local all_caps_mod = modp[0]
+
+ srcp[0] = '<C-a>'
+ eq(all_caps_key,
+ keymap.find_special_key(srcp, 5, modp, false, false, false))
+ eq(all_caps_mod, modp[0])
+
+ srcp[0] = '<c-A>'
+ eq(all_caps_key,
+ keymap.find_special_key(srcp, 5, modp, false, false, false))
+ eq(all_caps_mod, modp[0])
+
+ srcp[0] = '<c-a>'
+ eq(all_caps_key,
+ keymap.find_special_key(srcp, 5, modp, false, false, false))
+ eq(all_caps_mod, modp[0])
+ end)
+
+ itp('double-quote in keycode #7411', function()
+ -- Unescaped with in_string=false
+ srcp[0] = '<C-">'
+ eq(string.byte('"'),
+ keymap.find_special_key(srcp, 5, modp, false, false, false))
+
+ -- Unescaped with in_string=true
+ eq(0, keymap.find_special_key(srcp, 5, modp, false, false, true))
+
+ -- Escaped with in_string=false
+ srcp[0] = '<C-\\">'
+ -- Should fail because the key is invalid
+ -- (more than 1 non-modifier character).
+ eq(0, keymap.find_special_key(srcp, 6, modp, false, false, false))
+
+ -- Escaped with in_string=true
+ eq(string.byte('"'),
+ keymap.find_special_key(srcp, 6, modp, false, false, true))
+ end)
+ end)
+
+end)