aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/command_spec.lua97
-rw-r--r--test/functional/api/extmark_spec.lua22
-rw-r--r--test/functional/api/highlight_spec.lua5
-rw-r--r--test/functional/api/keymap_spec.lua44
-rw-r--r--test/functional/api/server_notifications_spec.lua4
-rw-r--r--test/functional/api/vim_spec.lua224
-rw-r--r--test/functional/api/window_spec.lua106
7 files changed, 392 insertions, 110 deletions
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index 890710b6e6..f19d7a362b 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 = [[this is a\ test]],
- fargs = {"this", "is", "a test"},
+ args = [[this\ is a\ test]],
+ fargs = {"this ", "is", "a test"},
bang = false,
line1 = 1,
line2 = 1,
@@ -125,6 +125,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -135,7 +136,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -144,7 +145,7 @@ describe('nvim_create_user_command', function()
count = 2,
reg = "",
}, exec_lua [=[
- vim.api.nvim_command([[CommandWithLuaCallback this is a\ test]])
+ vim.api.nvim_command([[CommandWithLuaCallback this\ is a\ test]])
return result
]=])
@@ -160,6 +161,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -170,7 +172,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -195,6 +197,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -205,7 +208,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -224,12 +227,13 @@ describe('nvim_create_user_command', function()
bang = true,
line1 = 10,
line2 = 10,
- mods = "confirm unsilent botright",
+ mods = "confirm unsilent botright horizontal",
smods = {
browse = false,
confirm = true,
emsg_silent = false,
hide = false,
+ horizontal = true,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -240,7 +244,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "botright",
- tab = 0,
+ tab = -1,
unsilent = true,
verbose = -1,
vertical = false,
@@ -249,7 +253,7 @@ describe('nvim_create_user_command', function()
count = 10,
reg = "",
}, exec_lua [=[
- vim.api.nvim_command('unsilent botright confirm 10CommandWithLuaCallback! h\tey ')
+ vim.api.nvim_command('unsilent horizontal botright confirm 10CommandWithLuaCallback! h\tey ')
return result
]=])
@@ -265,6 +269,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -275,7 +280,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -300,6 +305,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -310,7 +316,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -347,6 +353,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -357,7 +364,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -383,6 +390,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -393,7 +401,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -415,6 +423,7 @@ describe('nvim_create_user_command', function()
nargs = 0,
bang = true,
count = 2,
+ register = true,
})
]]
eq({
@@ -429,6 +438,7 @@ describe('nvim_create_user_command', function()
confirm = false,
emsg_silent = false,
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -439,7 +449,7 @@ describe('nvim_create_user_command', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -451,6 +461,42 @@ describe('nvim_create_user_command', function()
vim.cmd('CommandWithNoArgs')
return result
]])
+ -- register can be specified
+ eq({
+ args = "",
+ fargs = {},
+ bang = false,
+ line1 = 1,
+ line2 = 1,
+ mods = "",
+ smods = {
+ browse = false,
+ confirm = false,
+ emsg_silent = false,
+ hide = false,
+ horizontal = false,
+ keepalt = false,
+ keepjumps = false,
+ keepmarks = false,
+ keeppatterns = false,
+ lockmarks = false,
+ noautocmd = false,
+ noswapfile = false,
+ sandbox = false,
+ silent = false,
+ split = "",
+ tab = -1,
+ unsilent = false,
+ verbose = -1,
+ vertical = false,
+ },
+ range = 0,
+ count = 2,
+ reg = "+",
+ }, exec_lua [[
+ vim.cmd('CommandWithNoArgs +')
+ return result
+ ]])
end)
@@ -514,8 +560,29 @@ describe('nvim_create_user_command', function()
vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {})
end, {})
]]
-
eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
+
+ eq(1, #meths.list_tabpages())
+ exec_lua[[
+ vim.api.nvim_create_user_command('MySplit', function(opts)
+ vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {})
+ end, {})
+ ]]
+ meths.cmd({ cmd = 'MySplit' }, {})
+ eq(1, #meths.list_tabpages())
+ eq(2, #meths.list_wins())
+ meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
+ eq(2, #meths.list_tabpages())
+ eq(2, funcs.tabpagenr())
+ meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
+ eq(3, #meths.list_tabpages())
+ eq(2, funcs.tabpagenr())
+ meths.cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
+ eq(4, #meths.list_tabpages())
+ eq(4, funcs.tabpagenr())
+ meths.cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
+ eq(5, #meths.list_tabpages())
+ eq(1, funcs.tabpagenr())
end)
end)
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index bc8d811c6d..00f5b25b8a 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -1046,7 +1046,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[3], 0, 4, 0, 8)
end)
- it('substitions over multiple lines with newline in pattern', function()
+ it('substitutes over multiple lines with newline in pattern', function()
feed('A<cr>67890<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 3)
set_extmark(ns, marks[2], 0, 4)
@@ -1078,7 +1078,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[6], 1, 2, 0, 5)
end)
- it('substitions with multiple newlines in pattern', function()
+ it('substitutes with multiple newlines in pattern', function()
feed('A<cr>67890<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 4)
set_extmark(ns, marks[2], 0, 5)
@@ -1093,7 +1093,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[5], 2, 0, 0, 6)
end)
- it('substitions over multiple lines with replace in substition', function()
+ it('substitutes over multiple lines with replace in substitution', function()
feed('A<cr>67890<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 1)
set_extmark(ns, marks[2], 0, 2)
@@ -1111,7 +1111,7 @@ describe('API/extmarks', function()
eq({1, 3}, get_extmark_by_id(ns, marks[3]))
end)
- it('substitions over multiple lines with replace in substition', function()
+ it('substitutes over multiple lines with replace in substitution', function()
feed('A<cr>x3<cr>xx<esc>')
set_extmark(ns, marks[1], 1, 0)
set_extmark(ns, marks[2], 1, 1)
@@ -1122,7 +1122,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[3], 1, 2, 2, 0)
end)
- it('substitions over multiple lines with replace in substition', function()
+ it('substitutes over multiple lines with replace in substitution', function()
feed('A<cr>x3<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 1)
set_extmark(ns, marks[2], 0, 2)
@@ -1140,7 +1140,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[3], 0, 4, 1, 3)
end)
- it('substitions with newline in match and sub, delta is 0', function()
+ it('substitutes with newline in match and sub, delta is 0', function()
feed('A<cr>67890<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 3)
set_extmark(ns, marks[2], 0, 4)
@@ -1157,7 +1157,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[6], 2, 0, 2, 0)
end)
- it('substitions with newline in match and sub, delta > 0', function()
+ it('substitutes with newline in match and sub, delta > 0', function()
feed('A<cr>67890<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 3)
set_extmark(ns, marks[2], 0, 4)
@@ -1174,7 +1174,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[6], 2, 0, 3, 0)
end)
- it('substitions with newline in match and sub, delta < 0', function()
+ it('substitutes with newline in match and sub, delta < 0', function()
feed('A<cr>67890<cr>xx<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 3)
set_extmark(ns, marks[2], 0, 4)
@@ -1193,7 +1193,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[7], 3, 0, 2, 0)
end)
- it('substitions with backrefs, newline inserted into sub', function()
+ it('substitutes with backrefs, newline inserted into sub', function()
feed('A<cr>67890<cr>xx<cr>xx<esc>')
set_extmark(ns, marks[1], 0, 3)
set_extmark(ns, marks[2], 0, 4)
@@ -1210,7 +1210,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[6], 2, 0, 3, 0)
end)
- it('substitions a ^', function()
+ it('substitutes a ^', function()
set_extmark(ns, marks[1], 0, 0)
set_extmark(ns, marks[2], 0, 1)
feed([[:s:^:x<cr>]])
@@ -1397,7 +1397,7 @@ describe('API/extmarks', function()
eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
end)
- it('does not crash with append/delete/undo seqence', function()
+ it('does not crash with append/delete/undo sequence', function()
meths.exec([[
let ns = nvim_create_namespace('myplugin')
call nvim_buf_set_extmark(0, ns, 0, 0, {})
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index 2730f7e23d..3b36563d21 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -354,4 +354,9 @@ describe("API: set highlight", function()
meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'})
eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true))
end)
+
+ it('does not segfault on invalid group name #20009', function()
+ eq('Invalid highlight name: foo bar', pcall_err(meths.set_hl, 0, 'foo bar', {bold = true}))
+ assert_alive()
+ end)
end)
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index a93a4544ff..30c351b26a 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -6,6 +6,7 @@ local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq, neq = helpers.eq, helpers.neq
local exec_lua = helpers.exec_lua
+local exec = helpers.exec
local feed = helpers.feed
local funcs = helpers.funcs
local meths = helpers.meths
@@ -336,21 +337,26 @@ describe('nvim_get_keymap', function()
end)
it('can handle lua mappings', function()
- eq(0, exec_lua [[
+ eq(0, exec_lua([[
GlobalCount = 0
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
- ]])
+ ]]))
feed('asdf\n')
- eq(1, exec_lua[[return GlobalCount]])
+ eq(1, exec_lua([[return GlobalCount]]))
- eq(2, exec_lua[[
+ eq(2, exec_lua([[
vim.api.nvim_get_keymap('n')[1].callback()
return GlobalCount
+ ]]))
+
+ exec([[
+ call nvim_get_keymap('n')[0].callback()
]])
+ eq(3, exec_lua([[return GlobalCount]]))
+
local mapargs = meths.get_keymap('n')
- assert(type(mapargs[1].callback) == 'number', 'callback is not luaref number')
mapargs[1].callback = nil
eq({
lhs='asdf',
@@ -834,17 +840,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
it ('maparg() returns lua mapping correctly', function()
- exec_lua [[
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
- ]]
- assert.truthy(string.match(funcs.maparg('asdf', 'n'),
- "^<Lua %d+>"))
+ eq(0, exec_lua([[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ return GlobalCount
+ ]]))
+
+ assert.truthy(string.match(funcs.maparg('asdf', 'n'), "^<Lua %d+>"))
+
local mapargs = funcs.maparg('asdf', 'n', false, true)
- assert(type(mapargs.callback) == 'number', 'callback is not luaref number')
mapargs.callback = nil
mapargs.lhsraw = nil
mapargs.lhsrawalt = nil
eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs)
+
+ eq(1, exec_lua([[
+ vim.fn.maparg('asdf', 'n', false, true).callback()
+ return GlobalCount
+ ]]))
+
+ exec([[
+ call maparg('asdf', 'n', v:false, v:true).callback()
+ ]])
+ eq(2, exec_lua([[return GlobalCount]]))
end)
it('can make lua expr mappings replacing keycodes', function()
@@ -867,7 +885,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq({'<space>'}, meths.buf_get_lines(0, 0, -1, false))
end)
- it('lua expr mapping returning nil is equivalent to returnig an empty string', function()
+ it('lua expr mapping returning nil is equivalent to returning an empty string', function()
exec_lua [[
vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return nil end, expr = true })
]]
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua
index 1c00f001ff..1c554b05a3 100644
--- a/test/functional/api/server_notifications_spec.lua
+++ b/test/functional/api/server_notifications_spec.lua
@@ -7,6 +7,7 @@ local exec_lua = helpers.exec_lua
local retry = helpers.retry
local isCI = helpers.isCI
local assert_alive = helpers.assert_alive
+local uname = helpers.uname
describe('notify', function()
local channel
@@ -78,6 +79,9 @@ describe('notify', function()
end)
it('cancels stale events on channel close', function()
+ if uname() == 'freebsd' then
+ pending('Failing FreeBSD test')
+ end
if isCI() then
pending('hangs on CI #14083 #15251')
return
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 72a03c409a..af6cee7e90 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local lfs = require('lfs')
+local luv = require('luv')
local fmt = string.format
local assert_alive = helpers.assert_alive
@@ -14,6 +15,7 @@ local funcs = helpers.funcs
local iswin = helpers.iswin
local meths = helpers.meths
local matches = helpers.matches
+local pesc = helpers.pesc
local mkdir_p = helpers.mkdir_p
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
local is_os = helpers.is_os
@@ -1903,11 +1905,32 @@ describe('API', function()
end)
end)
+ describe('nvim_out_write', function()
+ it('prints long messages correctly #20534', function()
+ exec([[
+ set more
+ redir => g:out
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write("\n")
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write(repeat('a', 5000) .. "\n")
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write('a')
+ silent! call nvim_out_write("\n")
+ redir END
+ ]])
+ eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out'))
+ end)
+ end)
+
describe('nvim_err_write', function()
local screen
before_each(function()
- clear()
screen = Screen.new(40, 8)
screen:attach()
screen:set_default_attr_ids({
@@ -2254,7 +2277,7 @@ 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
+ -- 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,,')
@@ -2732,8 +2755,8 @@ describe('API', function()
it('should have information about window options', function()
eq({
- allows_duplicates = true,
- commalist = false;
+ allows_duplicates = false,
+ commalist = true;
default = "";
flaglist = false;
global_local = false;
@@ -3176,9 +3199,6 @@ describe('API', function()
cmd = 'echo',
args = { 'foo' },
bang = false,
- range = {},
- count = -1,
- reg = '',
addr = 'none',
magic = {
file = false,
@@ -3195,6 +3215,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3205,7 +3226,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3218,8 +3239,6 @@ describe('API', function()
args = { '/math.random/math.max/' },
bang = false,
range = { 4, 6 },
- count = -1,
- reg = '',
addr = 'line',
magic = {
file = false,
@@ -3236,6 +3255,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3246,7 +3266,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3260,7 +3280,6 @@ describe('API', function()
bang = false,
range = { 1 },
count = 1,
- reg = '',
addr = 'buf',
magic = {
file = false,
@@ -3277,6 +3296,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3287,7 +3307,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3300,7 +3320,6 @@ describe('API', function()
args = {},
bang = false,
range = {},
- count = -1,
reg = '+',
addr = 'line',
magic = {
@@ -3318,6 +3337,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3328,12 +3348,51 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
}
}, meths.parse_cmd('put +', {}))
+ eq({
+ cmd = 'put',
+ args = {},
+ bang = false,
+ range = {},
+ reg = '',
+ addr = 'line',
+ magic = {
+ file = false,
+ bar = true
+ },
+ nargs = '0',
+ nextcmd = '',
+ mods = {
+ browse = false,
+ confirm = false,
+ emsg_silent = false,
+ filter = {
+ pattern = "",
+ force = false
+ },
+ hide = false,
+ horizontal = false,
+ keepalt = false,
+ keepjumps = false,
+ keepmarks = false,
+ keeppatterns = false,
+ lockmarks = false,
+ noautocmd = false,
+ noswapfile = false,
+ sandbox = false,
+ silent = false,
+ split = "",
+ tab = -1,
+ unsilent = false,
+ verbose = -1,
+ vertical = false,
+ }
+ }, meths.parse_cmd('put', {}))
end)
it('works with range, count and register', function()
eq({
@@ -3359,6 +3418,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3369,7 +3429,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3382,8 +3442,6 @@ describe('API', function()
args = {},
bang = true,
range = {},
- count = -1,
- reg = '',
addr = 'line',
magic = {
file = true,
@@ -3400,6 +3458,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3410,7 +3469,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3423,8 +3482,6 @@ describe('API', function()
args = { 'foo.txt' },
bang = false,
range = {},
- count = -1,
- reg = '',
addr = '?',
magic = {
file = true,
@@ -3441,6 +3498,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = true,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3451,19 +3509,17 @@ describe('API', function()
sandbox = false,
silent = true,
split = "topleft",
- tab = 2,
+ tab = 1,
unsilent = false,
verbose = 15,
vertical = false,
},
- }, meths.parse_cmd('15verbose silent! aboveleft topleft tab filter /foo/ split foo.txt', {}))
+ }, meths.parse_cmd('15verbose silent! horizontal topleft tab filter /foo/ split foo.txt', {}))
eq({
cmd = 'split',
args = { 'foo.txt' },
bang = false,
range = {},
- count = -1,
- reg = '',
addr = '?',
magic = {
file = true,
@@ -3480,6 +3536,7 @@ describe('API', function()
force = true
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3495,7 +3552,7 @@ describe('API', function()
verbose = 0,
vertical = false,
},
- }, meths.parse_cmd('0verbose unsilent botright confirm filter! /foo/ split foo.txt', {}))
+ }, meths.parse_cmd('0verbose unsilent botright 0tab confirm filter! /foo/ split foo.txt', {}))
end)
it('works with user commands', function()
command('command -bang -nargs=+ -range -addr=lines MyCommand echo foo')
@@ -3504,8 +3561,6 @@ describe('API', function()
args = { 'test', 'it' },
bang = true,
range = { 4, 6 },
- count = -1,
- reg = '',
addr = 'line',
magic = {
file = false,
@@ -3522,6 +3577,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3532,7 +3588,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3545,8 +3601,6 @@ describe('API', function()
args = { 'a.txt' },
bang = false,
range = {},
- count = -1,
- reg = '',
addr = 'arg',
magic = {
file = true,
@@ -3563,6 +3617,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3573,7 +3628,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3586,9 +3641,6 @@ describe('API', function()
cmd = 'MyCommand',
args = { 'test it' },
bang = false,
- range = {},
- count = -1,
- reg = '',
addr = 'none',
magic = {
file = false,
@@ -3605,6 +3657,7 @@ describe('API', function()
force = false
},
hide = false,
+ horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
@@ -3615,7 +3668,7 @@ describe('API', function()
sandbox = false,
silent = false,
split = "",
- tab = 0,
+ tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
@@ -3668,6 +3721,59 @@ describe('API', function()
:^ |
]])
end)
+ it('does not move cursor or change search history/pattern #19878 #19890', function()
+ meths.buf_set_lines(0, 0, -1, true, {'foo', 'bar', 'foo', 'bar'})
+ eq({1, 0}, meths.win_get_cursor(0))
+ eq('', funcs.getreg('/'))
+ eq('', funcs.histget('search'))
+ feed(':') -- call the API in cmdline mode to test whether it changes search history
+ eq({
+ cmd = 'normal',
+ args = {'x'},
+ bang = true,
+ range = {3, 4},
+ addr = 'line',
+ magic = {
+ file = false,
+ bar = false,
+ },
+ nargs = '+',
+ nextcmd = '',
+ mods = {
+ browse = false,
+ confirm = false,
+ emsg_silent = false,
+ filter = {
+ pattern = "",
+ force = false,
+ },
+ hide = false,
+ horizontal = false,
+ keepalt = false,
+ keepjumps = false,
+ keepmarks = false,
+ keeppatterns = false,
+ lockmarks = false,
+ noautocmd = false,
+ noswapfile = false,
+ sandbox = false,
+ silent = false,
+ split = "",
+ tab = -1,
+ unsilent = false,
+ verbose = -1,
+ vertical = false,
+ }
+ }, meths.parse_cmd('+2;/bar/normal! x', {}))
+ eq({1, 0}, meths.win_get_cursor(0))
+ eq('', funcs.getreg('/'))
+ eq('', funcs.histget('search'))
+ end)
+ it('result can be used directly by nvim_cmd #20051', function()
+ eq("foo", meths.cmd(meths.parse_cmd('echo "foo"', {}), { output = true }))
+ meths.cmd(meths.parse_cmd("set cursorline", {}), {})
+ eq(true, meths.get_option_value("cursorline", {}))
+ end)
end)
describe('nvim_cmd', function()
it('works', function ()
@@ -3749,10 +3855,20 @@ describe('API', function()
eq('1',
meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } },
{ output = true }))
- -- with :silent message isn't added to message history
+ -- but message isn't added to message history
eq('', meths.cmd({ cmd = 'messages' }, { output = true }))
meths.create_user_command("Foo", 'set verbose', {})
eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true }))
+ meths.create_user_command("Mods", "echo '<mods>'", {})
+ eq('keepmarks keeppatterns silent 3verbose aboveleft horizontal',
+ meths.cmd({ cmd = "Mods", mods = {
+ horizontal = true,
+ keepmarks = true,
+ keeppatterns = true,
+ silent = true,
+ split = 'aboveleft',
+ verbose = 3,
+ } }, { output = true }))
eq(0, meths.get_option_value("verbose", {}))
command('edit foo.txt | edit bar.txt')
eq(' 1 #h "foo.txt" line 1',
@@ -3841,11 +3957,23 @@ describe('API', function()
eq({'aa'}, meths.buf_get_lines(0, 0, 1, false))
assert_alive()
end)
+ it('supports filename expansion', function()
+ meths.cmd({ cmd = 'argadd', args = { '%:p:h:t', '%:p:h:t' } }, {})
+ local arg = funcs.expand('%:p:h:t')
+ eq({ arg, arg }, funcs.argv())
+ end)
it("'make' command works when argument count isn't 1 #19696", function()
command('set makeprg=echo')
- meths.cmd({ cmd = 'make' }, {})
+ command('set shellquote=')
+ matches('^:!echo ',
+ meths.cmd({ cmd = 'make' }, { output = true }))
+ assert_alive()
+ matches('^:!echo foo bar',
+ meths.cmd({ cmd = 'make', args = { 'foo', 'bar' } }, { output = true }))
assert_alive()
- meths.cmd({ cmd = 'make', args = { 'foo', 'bar' } }, {})
+ local arg_pesc = pesc(funcs.expand('%:p:h:t'))
+ matches(('^:!echo %s %s'):format(arg_pesc, arg_pesc),
+ meths.cmd({ cmd = 'make', args = { '%:p:h:t', '%:p:h:t' } }, { output = true }))
assert_alive()
end)
it('doesn\'t display messages when output=true', function()
@@ -3878,5 +4006,23 @@ describe('API', function()
15 |
]]}
end)
+ it('works with non-String args', function()
+ eq('2', meths.cmd({cmd = 'echo', args = {2}}, {output = true}))
+ eq('1', meths.cmd({cmd = 'echo', args = {true}}, {output = true}))
+ end)
+ describe('first argument as count', function()
+ before_each(clear)
+
+ it('works', function()
+ command('vsplit | enew')
+ meths.cmd({cmd = 'bdelete', args = {meths.get_current_buf()}}, {})
+ eq(1, meths.get_current_buf().id)
+ end)
+ it('works with :sleep using milliseconds', function()
+ local start = luv.now()
+ meths.cmd({cmd = 'sleep', args = {'100m'}}, {})
+ ok(luv.now() - start <= 300)
+ end)
+ end)
end)
end)
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 901d24327c..7c65cf9c37 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -15,25 +15,6 @@ 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)
- local slen = string.len(str)
- local nlines = eval("&lines")
- for i = 1,nlines do
- local iseq = true
- for j = 1,slen do
- if string.byte(str,j) ~= eval("screenchar("..i..","..j..")") then
- iseq = false
- break
- end
- end
- if iseq then
- return true
- end
- end
- return false
-end
-
describe('API/win', function()
before_each(clear)
@@ -79,27 +60,61 @@ describe('API/win', function()
end)
it('updates the screen, and also when the window is unfocused', function()
+ local screen = Screen.new(30, 9)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue},
+ [2] = {bold = true, reverse = true};
+ [3] = {reverse = true};
+ })
+ screen:attach()
+
insert("prologue")
feed('100o<esc>')
insert("epilogue")
local win = curwin()
feed('gg')
- poke_eventloop() -- let nvim process the 'gg' command
+ screen:expect{grid=[[
+ ^prologue |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ ]]}
-- cursor position is at beginning
eq({1, 0}, window('get_cursor', win))
- eq(true, is_visible("prologue"))
- eq(false, is_visible("epilogue"))
-- move cursor to end
window('set_cursor', win, {101, 0})
- eq(false, is_visible("prologue"))
- eq(true, is_visible("epilogue"))
+ screen:expect{grid=[[
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ ^epilogue |
+ |
+ ]]}
-- move cursor to the beginning again
window('set_cursor', win, {1, 0})
- eq(true, is_visible("prologue"))
- eq(false, is_visible("epilogue"))
+ screen:expect{grid=[[
+ ^prologue |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ ]]}
-- move focus to new window
nvim('command',"new")
@@ -107,18 +122,45 @@ describe('API/win', function()
-- sanity check, cursor position is kept
eq({1, 0}, window('get_cursor', win))
- eq(true, is_visible("prologue"))
- eq(false, is_visible("epilogue"))
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ prologue |
+ |
+ |
+ {3:[No Name] [+] }|
+ |
+ ]]}
-- move cursor to end
window('set_cursor', win, {101, 0})
- eq(false, is_visible("prologue"))
- eq(true, is_visible("epilogue"))
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ |
+ |
+ epilogue |
+ {3:[No Name] [+] }|
+ |
+ ]]}
-- move cursor to the beginning again
window('set_cursor', win, {1, 0})
- eq(true, is_visible("prologue"))
- eq(false, is_visible("epilogue"))
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {2:[No Name] }|
+ prologue |
+ |
+ |
+ {3:[No Name] [+] }|
+ |
+ ]]}
-- curwin didn't change back
neq(win, curwin())