mirror of
https://github.com/neovim/neovim.git
synced 2026-07-21 00:21:38 +00:00
test: use exec_capture() in more places (#22787)
Problem:
Using `meths.exec2("code", { output = true })` is too verbose.
Solution:
Use exec_capture() in more places.
This commit is contained in:
@@ -11,6 +11,7 @@ local insert = helpers.insert
|
||||
local feed = helpers.feed
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local exec = helpers.exec
|
||||
local meths = helpers.meths
|
||||
local assert_alive = helpers.assert_alive
|
||||
|
||||
@@ -1413,12 +1414,12 @@ describe('API/extmarks', function()
|
||||
end)
|
||||
|
||||
it('does not crash with append/delete/undo sequence', function()
|
||||
meths.exec2([[
|
||||
exec([[
|
||||
let ns = nvim_create_namespace('myplugin')
|
||||
call nvim_buf_set_extmark(0, ns, 0, 0, {})
|
||||
call append(0, '')
|
||||
%delete
|
||||
undo]], { output = false })
|
||||
undo]])
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
@@ -1450,7 +1451,7 @@ describe('API/extmarks', function()
|
||||
|
||||
feed('u')
|
||||
-- handles pasting
|
||||
meths.exec2([[let @a='asdfasdf']], { output = false })
|
||||
exec([[let @a='asdfasdf']])
|
||||
feed([["ap]])
|
||||
eq({ {1, 0, 0}, {2, 0, 8} },
|
||||
meths.buf_get_extmarks(0, ns, 0, -1, {}))
|
||||
|
||||
@@ -681,13 +681,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
end)
|
||||
|
||||
it('can set <expr> mappings whose RHS change dynamically', function()
|
||||
meths.exec2([[
|
||||
exec([[
|
||||
function! FlipFlop() abort
|
||||
if !exists('g:flip') | let g:flip = 0 | endif
|
||||
let g:flip = !g:flip
|
||||
return g:flip
|
||||
endfunction
|
||||
]], { output = false })
|
||||
]])
|
||||
eq(1, meths.call_function('FlipFlop', {}))
|
||||
eq(0, meths.call_function('FlipFlop', {}))
|
||||
eq(1, meths.call_function('FlipFlop', {}))
|
||||
|
||||
@@ -9,6 +9,7 @@ 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 exec_capture = helpers.exec_capture
|
||||
local eval = helpers.eval
|
||||
local expect = helpers.expect
|
||||
local funcs = helpers.funcs
|
||||
@@ -588,7 +589,7 @@ describe('API', function()
|
||||
|
||||
it('sets previous directory', function()
|
||||
meths.set_current_dir("Xtestdir")
|
||||
meths.exec2('cd -', { output = false })
|
||||
command('cd -')
|
||||
eq(funcs.getcwd(), start_dir)
|
||||
end)
|
||||
end)
|
||||
@@ -2687,7 +2688,7 @@ describe('API', function()
|
||||
eq(' 1 %a "[No Name]" line 1\n'..
|
||||
' 3 h "[Scratch]" line 0\n'..
|
||||
' 4 h "[Scratch]" line 0',
|
||||
meths.exec2('ls', { output = true }).output)
|
||||
exec_capture('ls'))
|
||||
-- current buffer didn't change
|
||||
eq({id=1}, meths.get_current_buf())
|
||||
|
||||
@@ -2954,13 +2955,13 @@ describe('API', function()
|
||||
it('can save message history', function()
|
||||
nvim('command', 'set cmdheight=2') -- suppress Press ENTER
|
||||
nvim("echo", {{"msg\nmsg"}, {"msg"}}, true, {})
|
||||
eq("msg\nmsgmsg", meths.exec2('messages', { output = true }).output)
|
||||
eq("msg\nmsgmsg", exec_capture('messages'))
|
||||
end)
|
||||
|
||||
it('can disable saving message history', function()
|
||||
nvim('command', 'set cmdheight=2') -- suppress Press ENTER
|
||||
nvim_async("echo", {{"msg\nmsg"}, {"msg"}}, false, {})
|
||||
eq("", meths.exec2("messages", { output = true }).output)
|
||||
eq("", exec_capture('messages'))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -3949,7 +3950,7 @@ describe('API', function()
|
||||
|
||||
it('sets correct script context', function()
|
||||
meths.cmd({ cmd = "set", args = { "cursorline" } }, {})
|
||||
local str = meths.exec2([[verbose set cursorline?]], { output = true }).output
|
||||
local str = exec_capture([[verbose set cursorline?]])
|
||||
neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)"))
|
||||
end)
|
||||
|
||||
@@ -3999,7 +4000,7 @@ describe('API', function()
|
||||
line6
|
||||
]]
|
||||
meths.cmd({ cmd = "del", range = { 2, 4 }, reg = 'a' }, {})
|
||||
meths.exec2("1put a", { output = false })
|
||||
command('1put a')
|
||||
expect [[
|
||||
line1
|
||||
line2
|
||||
@@ -4064,11 +4065,11 @@ describe('API', function()
|
||||
{ output = true }))
|
||||
end)
|
||||
it('splits arguments correctly', function()
|
||||
meths.exec2([[
|
||||
exec([[
|
||||
function! FooFunc(...)
|
||||
echo a:000
|
||||
endfunction
|
||||
]], { output = false })
|
||||
]])
|
||||
meths.create_user_command("Foo", "call FooFunc(<f-args>)", { 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"}},
|
||||
|
||||
Reference in New Issue
Block a user