mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
test(lua/snippet_spec): wait for completion menu (#27243)
This fixes the flakiness caused by typing a completion menu key when the completion menu hasn't showed up.
This commit is contained in:
@@ -5,9 +5,11 @@ local clear = helpers.clear
|
|||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
|
local fn = helpers.fn
|
||||||
local matches = helpers.matches
|
local matches = helpers.matches
|
||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
local sleep = vim.uv.sleep
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
|
local retry = helpers.retry
|
||||||
|
|
||||||
describe('vim.snippet', function()
|
describe('vim.snippet', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@@ -35,6 +37,12 @@ describe('vim.snippet', function()
|
|||||||
eq(expected, buf_lines(0))
|
eq(expected, buf_lines(0))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function wait_for_pum()
|
||||||
|
retry(nil, nil, function()
|
||||||
|
eq(1, fn.pumvisible())
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
--- @param snippet string
|
--- @param snippet string
|
||||||
--- @param err string
|
--- @param err string
|
||||||
local function test_expand_fail(snippet, err)
|
local function test_expand_fail(snippet, err)
|
||||||
@@ -185,16 +193,16 @@ describe('vim.snippet', function()
|
|||||||
|
|
||||||
it('inserts choice', function()
|
it('inserts choice', function()
|
||||||
test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' })
|
test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' })
|
||||||
sleep(100)
|
wait_for_pum()
|
||||||
feed('<Down><C-y>')
|
feed('<Down><C-y>')
|
||||||
eq({ 'console.log()' }, buf_lines(0))
|
eq({ 'console.log()' }, buf_lines(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('closes the choice completion menu when jumping', function()
|
it('closes the choice completion menu when jumping', function()
|
||||||
test_expand_success({ 'console.${1|assert,log,error|}($2)' }, { 'console.()' })
|
test_expand_success({ 'console.${1|assert,log,error|}($2)' }, { 'console.()' })
|
||||||
sleep(100)
|
wait_for_pum()
|
||||||
exec_lua('vim.snippet.jump(1)')
|
exec_lua('vim.snippet.jump(1)')
|
||||||
eq(0, exec_lua('return vim.fn.pumvisible()'))
|
eq(0, fn.pumvisible())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('jumps to next tabstop after inserting choice', function()
|
it('jumps to next tabstop after inserting choice', function()
|
||||||
@@ -202,9 +210,9 @@ describe('vim.snippet', function()
|
|||||||
{ '${1|public,protected,private|} function ${2:name}() {', '\t$0', '}' },
|
{ '${1|public,protected,private|} function ${2:name}() {', '\t$0', '}' },
|
||||||
{ ' function name() {', '\t', '}' }
|
{ ' function name() {', '\t', '}' }
|
||||||
)
|
)
|
||||||
sleep(100)
|
wait_for_pum()
|
||||||
feed('<C-y><Tab>')
|
feed('<C-y><Tab>')
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
feed('foo')
|
feed('foo')
|
||||||
eq({ 'public function foo() {', '\t', '}' }, buf_lines(0))
|
eq({ 'public function foo() {', '\t', '}' }, buf_lines(0))
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user