aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/buffer_updates_spec.lua10
-rw-r--r--test/functional/api/command_spec.lua4
-rw-r--r--test/functional/api/extmark_spec.lua5
-rw-r--r--test/functional/api/server_notifications_spec.lua13
-rw-r--r--test/functional/api/server_requests_spec.lua5
-rw-r--r--test/functional/api/vim_spec.lua85
-rw-r--r--test/functional/api/window_spec.lua38
7 files changed, 129 insertions, 31 deletions
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index 05ca0d5f4d..c9c9be5406 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -159,9 +159,8 @@ describe('API: buffer events:', function()
tick = tick + 1
expectn('nvim_buf_lines_event', {b, tick, 29, 29, firstfour, false})
- -- create a new empty buffer and wipe out the old one ... this will
- -- turn off buffer events
- command('enew!')
+ -- delete the current buffer to turn off buffer events
+ command('bdelete!')
expectn('nvim_buf_detach_event', {b})
-- add a line at the start of an empty file
@@ -269,7 +268,7 @@ describe('API: buffer events:', function()
'original foo'}, false})
-- type text into the first line of a blank file, one character at a time
- command('enew!')
+ command('bdelete!')
tick = 2
expectn('nvim_buf_detach_event', {b})
local bnew = nvim('get_current_buf')
@@ -666,7 +665,8 @@ describe('API: buffer events:', function()
tick = tick + 1
expectn('nvim_buf_changedtick_event', {b, tick})
- -- close our buffer by creating a new one
+ -- close our buffer and create a new one
+ command('bdelete')
command('enew')
expectn('nvim_buf_detach_event', {b})
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index e6a9e11fd9..37331d11c7 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -53,7 +53,7 @@ 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 <args>', name='TestCmd', nargs='0', range='10', register=false, script_id=0, }
+ local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd <args>', 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 <args>', 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(<q-args>)', 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, }
@@ -62,7 +62,7 @@ describe('nvim_get_commands', function()
command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
]])
eq({Finger=cmd1}, meths.get_commands({builtin=false}))
- command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
+ command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
eq({Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false}))
source([[
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index d2b555ee5b..50b4b85d2a 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -12,6 +12,7 @@ local feed = helpers.feed
local clear = helpers.clear
local command = helpers.command
local meths = helpers.meths
+local assert_alive = helpers.assert_alive
local function expect(contents)
return eq(contents, helpers.curbuf_contents())
@@ -1381,13 +1382,13 @@ describe('API/extmarks', function()
end)
it('does not crash with append/delete/undo seqence', function()
- meths.exec([[
+ meths.exec([[
let ns = nvim_create_namespace('myplugin')
call nvim_buf_set_extmark(0, ns, 0, 0, {})
call append(0, '')
%delete
undo]],false)
- eq(2, meths.eval('1+1')) -- did not crash
+ assert_alive()
end)
it('works with left and right gravity', function()
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua
index 9ee2570798..6367cc5caa 100644
--- a/test/functional/api/server_notifications_spec.lua
+++ b/test/functional/api/server_notifications_spec.lua
@@ -5,6 +5,8 @@ local eq, clear, eval, command, nvim, next_msg =
local meths = helpers.meths
local exec_lua = helpers.exec_lua
local retry = helpers.retry
+local isCI = helpers.isCI
+local assert_alive = helpers.assert_alive
describe('notify', function()
local channel
@@ -72,18 +74,23 @@ describe('notify', function()
nvim('subscribe', 'event1')
nvim('unsubscribe', 'doesnotexist')
nvim('unsubscribe', 'event1')
- eq(2, eval('1+1')) -- Still alive?
+ assert_alive()
end)
it('cancels stale events on channel close', function()
+ if isCI() then
+ pending('hangs on CI #14083 #15251')
+ return
+ end
if helpers.pending_win32(pending) then return end
local catchan = eval("jobstart(['cat'], {'rpc': v:true})")
- eq({id=catchan, stream='job', mode='rpc', client = {}}, exec_lua ([[
+ local catpath = eval('exepath("cat")')
+ eq({id=catchan, argv={catpath}, stream='job', mode='rpc', client = {}}, exec_lua ([[
vim.rpcnotify(..., "nvim_call_function", 'chanclose', {..., 'rpc'})
vim.rpcnotify(..., "nvim_subscribe", "daily_rant")
return vim.api.nvim_get_chan_info(...)
]], catchan))
- eq(2, eval('1+1')) -- Still alive?
+ assert_alive()
eq({false, 'Invalid channel: '..catchan},
exec_lua ([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan))
retry(nil, 3000, function() eq({}, meths.get_chan_info(catchan)) end) -- cat be dead :(
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index 237a4b01e4..e408890906 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -11,6 +11,7 @@ local meths = helpers.meths
local spawn, merge_args = helpers.spawn, helpers.merge_args
local set_session = helpers.set_session
local pcall_err = helpers.pcall_err
+local assert_alive = helpers.assert_alive
describe('server -> client', function()
local cid
@@ -33,7 +34,7 @@ describe('server -> client', function()
call jobstop(ch1)
]])
- eq(2, eval("1+1")) -- Still alive?
+ assert_alive()
end)
describe('simple call', function()
@@ -158,7 +159,7 @@ describe('server -> client', function()
-- do some busywork, so the first request will return
-- before this one
for _ = 1, 5 do
- eq(2, eval("1+1"))
+ assert_alive()
end
eq(1, eval('rpcnotify('..cid..', "nested_done")'))
return 'done!'
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 91d2745130..ffef6a6066 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1,6 +1,8 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
+local fmt = string.format
+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
@@ -57,7 +59,7 @@ describe('API', function()
eq({'notification', 'nvim_error_event',
{error_types.Exception.id, 'Invalid method: nvim_bogus'}}, next_msg())
-- error didn't close channel.
- eq(2, eval('1+1'))
+ assert_alive()
end)
it('failed async request emits nvim_error_event', function()
@@ -67,7 +69,7 @@ describe('API', function()
{error_types.Exception.id, 'Vim:E492: Not an editor command: bogus'}},
next_msg())
-- error didn't close channel.
- eq(2, eval('1+1'))
+ assert_alive()
end)
it('does not set CA_COMMAND_BUSY #7254', function()
@@ -115,6 +117,19 @@ describe('API', function()
nvim('exec','autocmd BufAdd * :let x1 = "Hello"', false)
nvim('command', 'new foo')
eq('Hello', request('nvim_eval', 'g:x1'))
+
+ -- Line continuations
+ nvim('exec', [[
+ let abc = #{
+ \ a: 1,
+ "\ b: 2,
+ \ c: 3
+ \ }]], false)
+ eq({a = 1, c = 3}, request('nvim_eval', 'g:abc'))
+
+ -- try no spaces before continuations to catch off-by-one error
+ nvim('exec', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', false)
+ eq({a = 98}, request('nvim_eval', 'g:ab'))
end)
it('non-ASCII input', function()
@@ -518,7 +533,7 @@ describe('API', function()
nvim("notify", "hello world", 2, {})
end)
- it('can be overriden', function()
+ it('can be overridden', function()
command("lua vim.notify = function(...) return 42 end")
eq(42, meths.exec_lua("return vim.notify('Hello world')", {}))
nvim("notify", "hello world", 4, {})
@@ -1326,10 +1341,10 @@ describe('API', function()
end)
end)
- describe('nvim_list_chans and nvim_get_chan_info', function()
+ describe('nvim_list_chans, nvim_get_chan_info', function()
before_each(function()
- command('autocmd ChanOpen * let g:opened_event = copy(v:event)')
- command('autocmd ChanInfo * let g:info_event = copy(v:event)')
+ command('autocmd ChanOpen * let g:opened_event = deepcopy(v:event)')
+ command('autocmd ChanInfo * let g:info_event = deepcopy(v:event)')
end)
local testinfo = {
stream = 'stdio',
@@ -1350,7 +1365,7 @@ describe('API', function()
eq({}, meths.get_chan_info(10))
end)
- it('works for stdio channel', function()
+ it('stream=stdio channel', function()
eq({[1]=testinfo,[2]=stderr}, meths.list_chans())
eq(testinfo, meths.get_chan_info(1))
eq(stderr, meths.get_chan_info(2))
@@ -1377,11 +1392,13 @@ describe('API', function()
eq(info, meths.get_chan_info(1))
end)
- it('works for job channel', function()
+ it('stream=job channel', function()
eq(3, eval("jobstart(['cat'], {'rpc': v:true})"))
+ local catpath = eval('exepath("cat")')
local info = {
stream='job',
id=3,
+ argv={ catpath },
mode='rpc',
client={},
}
@@ -1394,6 +1411,7 @@ describe('API', function()
info = {
stream='job',
id=3,
+ argv={ catpath },
mode='rpc',
client = {
name='amazing-cat',
@@ -1410,14 +1428,15 @@ describe('API', function()
pcall_err(eval, 'rpcrequest(3, "nvim_set_current_buf", -1)'))
end)
- it('works for :terminal channel', function()
- command(":terminal")
+ it('stream=job :terminal channel', function()
+ command(':terminal')
eq({id=1}, meths.get_current_buf())
- eq(3, meths.buf_get_option(1, "channel"))
+ eq(3, meths.buf_get_option(1, 'channel'))
local info = {
stream='job',
id=3,
+ argv={ eval('exepath(&shell)') },
mode='terminal',
buffer = 1,
pty='?',
@@ -1431,6 +1450,38 @@ describe('API', function()
info.buffer = {id=1}
eq({[1]=testinfo,[2]=stderr,[3]=info}, meths.list_chans())
eq(info, meths.get_chan_info(3))
+
+ -- :terminal with args + running process.
+ command(':exe "terminal" shellescape(v:progpath) "-u NONE -i NONE"')
+ eq(-1, eval('jobwait([&channel], 0)[0]')) -- Running?
+ local expected2 = {
+ stream = 'job',
+ id = 4,
+ argv = (
+ iswin() and {
+ eval('&shell'),
+ '/s',
+ '/c',
+ fmt('"%s -u NONE -i NONE"', eval('shellescape(v:progpath)')),
+ } or {
+ eval('&shell'),
+ eval('&shellcmdflag'),
+ fmt('%s -u NONE -i NONE', eval('shellescape(v:progpath)')),
+ }
+ ),
+ mode = 'terminal',
+ buffer = 2,
+ pty = '?',
+ }
+ local actual2 = eval('nvim_get_chan_info(&channel)')
+ expected2.pty = actual2.pty
+ eq(expected2, actual2)
+
+ -- :terminal with args + stopped process.
+ eq(1, eval('jobstop(&channel)'))
+ eval('jobwait([&channel], 1000)') -- Wait.
+ expected2.pty = (iswin() and '?' or '') -- pty stream was closed.
+ eq(expected2, eval('nvim_get_chan_info(&channel)'))
end)
end)
@@ -1540,7 +1591,10 @@ describe('API', function()
eq({'a', '', 'b'}, meths.list_runtime_paths())
meths.set_option('runtimepath', ',a,b')
eq({'', 'a', 'b'}, meths.list_runtime_paths())
+ -- trailing , is ignored, use ,, if you really really want $CWD
meths.set_option('runtimepath', 'a,b,')
+ eq({'a', 'b'}, meths.list_runtime_paths())
+ meths.set_option('runtimepath', 'a,b,,')
eq({'a', 'b', ''}, meths.list_runtime_paths())
end)
it('truncates too long paths', function()
@@ -1961,8 +2015,13 @@ describe('API', function()
ok(endswith(val[1], p"autoload/remote/define.vim")
or endswith(val[1], p"autoload/remote/host.vim"))
- eq({}, meths.get_runtime_file("lua", true))
- eq({}, meths.get_runtime_file("lua/vim", true))
+ val = meths.get_runtime_file("lua", true)
+ eq(1, #val)
+ ok(endswith(val[1], p"lua"))
+
+ val = meths.get_runtime_file("lua/vim", true)
+ eq(1, #val)
+ ok(endswith(val[1], p"lua/vim"))
end)
it('can find directories', function()
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index bb72b63b6c..11755a9d97 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -1,8 +1,9 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq,
- ok, feed, insert, eval = helpers.clear, helpers.nvim, helpers.curbuf,
+ ok, feed, insert, eval, tabpage = helpers.clear, helpers.nvim, helpers.curbuf,
helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq,
- helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval
+ helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval,
+ helpers.tabpage
local poke_eventloop = helpers.poke_eventloop
local curwinmeths = helpers.curwinmeths
local funcs = helpers.funcs
@@ -11,6 +12,7 @@ local NIL = helpers.NIL
local meths = helpers.meths
local command = helpers.command
local pcall_err = helpers.pcall_err
+local assert_alive = helpers.assert_alive
-- check if str is visible at the beginning of some line
local function is_visible(str)
@@ -206,7 +208,7 @@ describe('API/win', function()
end)
end)
- describe('{get,set}_option', function()
+ describe('nvim_win_get_option, nvim_win_set_option', function()
it('works', function()
curwin('set_option', 'colorcolumn', '4,3')
eq('4,3', curwin('get_option', 'colorcolumn'))
@@ -224,6 +226,18 @@ describe('API/win', function()
pcall_err(curwin, 'get_option', 'statusline'))
eq('', eval('&l:statusline')) -- confirm local value was not copied
end)
+
+ it('after switching windows #15390', function()
+ nvim('command', 'tabnew')
+ local tab1 = unpack(nvim('list_tabpages'))
+ local win1 = unpack(tabpage('list_wins', tab1))
+ window('set_option', win1, 'statusline', 'window-status')
+ nvim('command', 'split')
+ nvim('command', 'wincmd J')
+ nvim('command', 'wincmd j')
+ eq('window-status', window('get_option', win1, 'statusline'))
+ assert_alive()
+ end)
end)
describe('get_position', function()
@@ -311,7 +325,8 @@ describe('API/win', function()
eq({newwin}, meths.list_wins())
end)
- it('handles changed buffer', function()
+ it("handles changed buffer when 'hidden' is unset", function()
+ command('set nohidden')
local oldwin = meths.get_current_win()
insert('text')
command('new')
@@ -346,6 +361,21 @@ describe('API/win', function()
eq(2, #meths.list_wins())
eq('', funcs.getcmdwintype())
end)
+
+ it('closing current (float) window of another tabpage #15313', function()
+ command('tabedit')
+ eq(2, eval('tabpagenr()'))
+ local win = meths.open_win(0, true, {
+ relative='editor', row=10, col=10, width=50, height=10
+ })
+ local tab = eval('tabpagenr()')
+ command('tabprevious')
+ eq(1, eval('tabpagenr()'))
+ meths.win_close(win, false)
+
+ eq(1001, meths.tabpage_get_win(tab).id)
+ assert_alive()
+ end)
end)
describe('hide', function()