mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 09:12:07 +00:00
api/ui: add tests for popupmenu_external events
update screen.lua to use new style nvim_ui_attach
This commit is contained in:
@@ -12,7 +12,7 @@ describe('TermClose event', function()
|
||||
nvim('set_option', 'shell', nvim_dir .. '/shell-test')
|
||||
nvim('set_option', 'shellcmdflag', 'EXE')
|
||||
screen = Screen.new(20, 4)
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
end)
|
||||
|
||||
it('works as expected', function()
|
||||
|
@@ -306,6 +306,10 @@ local function nvim(method, ...)
|
||||
return request('vim_'..method, ...)
|
||||
end
|
||||
|
||||
local function ui(method, ...)
|
||||
return request('nvim_ui_'..method, ...)
|
||||
end
|
||||
|
||||
local function nvim_async(method, ...)
|
||||
session:notify('vim_'..method, ...)
|
||||
end
|
||||
@@ -432,6 +436,7 @@ end
|
||||
|
||||
local funcs = create_callindex(nvim_call)
|
||||
local meths = create_callindex(nvim)
|
||||
local uimeths = create_callindex(ui)
|
||||
local bufmeths = create_callindex(buffer)
|
||||
local winmeths = create_callindex(window)
|
||||
local tabmeths = create_callindex(tabpage)
|
||||
@@ -490,6 +495,7 @@ return function(after_each)
|
||||
bufmeths = bufmeths,
|
||||
winmeths = winmeths,
|
||||
tabmeths = tabmeths,
|
||||
uimeths = uimeths,
|
||||
curbufmeths = curbufmeths,
|
||||
curwinmeths = curwinmeths,
|
||||
curtabmeths = curtabmeths,
|
||||
|
@@ -135,7 +135,7 @@ describe('cursor with customized highlighting', function()
|
||||
[2] = {foreground = 55, background = 56},
|
||||
[3] = {bold = true},
|
||||
})
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
execute('call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||
end)
|
||||
|
||||
|
@@ -12,7 +12,7 @@ local eq = helpers.eq
|
||||
describe(':edit term://*', function()
|
||||
local get_screen = function(columns, lines)
|
||||
local scr = screen.new(columns, lines)
|
||||
scr:attach(false)
|
||||
scr:attach({rgb=false})
|
||||
return scr
|
||||
end
|
||||
|
||||
|
@@ -10,7 +10,7 @@ describe(':terminal', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new(50, 4)
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
nvim('set_option', 'shell', nvim_dir..'/shell-test')
|
||||
nvim('set_option', 'shellcmdflag', 'EXE')
|
||||
|
||||
|
@@ -53,7 +53,7 @@ local function screen_setup(extra_height, command)
|
||||
[9] = {foreground = 4},
|
||||
})
|
||||
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
-- tty-test puts the terminal into raw mode and echoes all input. tests are
|
||||
-- done by feeding it with terminfo codes to control the display and
|
||||
-- verifying output with screen:expect.
|
||||
|
@@ -25,7 +25,7 @@ describe('terminal window highlighting', function()
|
||||
[10] = {reverse = true},
|
||||
[11] = {background = 11},
|
||||
})
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||
screen:expect([[
|
||||
tty ready |
|
||||
@@ -127,7 +127,7 @@ describe('terminal window highlighting with custom palette', function()
|
||||
[8] = {background = 11},
|
||||
[9] = {bold = true},
|
||||
})
|
||||
screen:attach(true)
|
||||
screen:attach({rgb=true})
|
||||
nvim('set_var', 'terminal_color_3', '#123456')
|
||||
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||
screen:expect([[
|
||||
@@ -185,7 +185,7 @@ describe('synIDattr()', function()
|
||||
end)
|
||||
|
||||
it('returns gui-color if RGB-capable UI is attached', function()
|
||||
screen:attach(true)
|
||||
screen:attach({rgb=true})
|
||||
eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")'))
|
||||
eq('Black', eval('synIDattr(hlID("Normal"), "bg")'))
|
||||
eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")'))
|
||||
@@ -193,7 +193,7 @@ describe('synIDattr()', function()
|
||||
end)
|
||||
|
||||
it('returns #RRGGBB value for fg#/bg#/sp#', function()
|
||||
screen:attach(true)
|
||||
screen:attach({rgb=true})
|
||||
eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")'))
|
||||
eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")'))
|
||||
eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")'))
|
||||
@@ -201,7 +201,7 @@ describe('synIDattr()', function()
|
||||
end)
|
||||
|
||||
it('returns color number if non-GUI', function()
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
|
||||
eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
|
||||
end)
|
||||
|
@@ -331,7 +331,7 @@ describe('terminal prints more lines than the screen height and exits', function
|
||||
it('will push extra lines to scrollback', function()
|
||||
clear()
|
||||
local screen = Screen.new(50, 7)
|
||||
screen:attach(false)
|
||||
screen:attach({rgb=false})
|
||||
execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
|
||||
wait()
|
||||
screen:expect([[
|
||||
|
@@ -106,7 +106,7 @@
|
||||
-- use `screen:snapshot_util({},true)`
|
||||
|
||||
local helpers = require('test.functional.helpers')(nil)
|
||||
local request, run = helpers.request, helpers.run
|
||||
local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths
|
||||
local dedent = helpers.dedent
|
||||
|
||||
local Screen = {}
|
||||
@@ -192,22 +192,22 @@ function Screen:set_default_attr_ignore(attr_ignore)
|
||||
self._default_attr_ignore = attr_ignore
|
||||
end
|
||||
|
||||
function Screen:attach(rgb)
|
||||
if rgb == nil then
|
||||
rgb = true
|
||||
function Screen:attach(options)
|
||||
if options == nil then
|
||||
options = {rgb=true}
|
||||
end
|
||||
request('ui_attach', self._width, self._height, rgb)
|
||||
uimeths.attach(self._width, self._height, options)
|
||||
end
|
||||
|
||||
function Screen:detach()
|
||||
request('ui_detach')
|
||||
uimeths.detach()
|
||||
end
|
||||
|
||||
function Screen:try_resize(columns, rows)
|
||||
request('ui_try_resize', columns, rows)
|
||||
uimeths.try_resize(columns, rows)
|
||||
end
|
||||
|
||||
function Screen:expect(expected, attr_ids, attr_ignore)
|
||||
function Screen:expect(expected, attr_ids, attr_ignore, condition)
|
||||
-- remove the last line and dedent
|
||||
expected = dedent(expected:gsub('\n[ ]+$', ''))
|
||||
local expected_rows = {}
|
||||
@@ -219,6 +219,12 @@ function Screen:expect(expected, attr_ids, attr_ignore)
|
||||
local ids = attr_ids or self._default_attr_ids
|
||||
local ignore = attr_ignore or self._default_attr_ignore
|
||||
self:wait(function()
|
||||
if condition ~= nil then
|
||||
local status, res = pcall(condition)
|
||||
if not status then
|
||||
return tostring(res)
|
||||
end
|
||||
end
|
||||
local actual_rows = {}
|
||||
for i = 1, self._height do
|
||||
actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore)
|
||||
@@ -303,12 +309,20 @@ function Screen:_redraw(updates)
|
||||
local method = update[1]
|
||||
for i = 2, #update do
|
||||
local handler = self['_handle_'..method]
|
||||
handler(self, unpack(update[i]))
|
||||
if handler ~= nil then
|
||||
handler(self, unpack(update[i]))
|
||||
else
|
||||
self._on_event(method, update[i])
|
||||
end
|
||||
end
|
||||
-- print(self:_current_screen())
|
||||
end
|
||||
end
|
||||
|
||||
function Screen:set_on_event_handler(callback)
|
||||
self._on_event = callback
|
||||
end
|
||||
|
||||
function Screen:_handle_resize(width, height)
|
||||
local rows = {}
|
||||
for _ = 1, height do
|
||||
|
@@ -755,4 +755,106 @@ describe('completion', function()
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('External completion popupmenu', function()
|
||||
local screen
|
||||
local items, selected, anchor
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new(60, 8)
|
||||
screen:attach({rgb=true, popupmenu_external=true})
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold=true, foreground=Screen.colors.Blue},
|
||||
[2] = {bold = true},
|
||||
})
|
||||
screen:set_on_event_handler(function(name, data)
|
||||
if name == "popupmenu_show" then
|
||||
local row, col
|
||||
items, selected, row, col = unpack(data)
|
||||
anchor = {row, col}
|
||||
elseif name == "popupmenu_select" then
|
||||
selected = data[1]
|
||||
elseif name == "popupmenu_hide" then
|
||||
items = nil
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
it('works', function()
|
||||
source([[
|
||||
function! TestComplete() abort
|
||||
call complete(1, ['foo', 'bar', 'spam'])
|
||||
return ''
|
||||
endfunction
|
||||
]])
|
||||
local expected = {
|
||||
{'foo', '', '', ''},
|
||||
{'bar', '', '', ''},
|
||||
{'spam', '', '', ''},
|
||||
}
|
||||
feed('o<C-r>=TestComplete()<CR>')
|
||||
screen:expect([[
|
||||
|
|
||||
foo^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- INSERT --} |
|
||||
]], nil, nil, function()
|
||||
eq(expected, items)
|
||||
eq(0, selected)
|
||||
eq({1,0}, anchor)
|
||||
end)
|
||||
|
||||
feed('<c-p>')
|
||||
screen:expect([[
|
||||
|
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- INSERT --} |
|
||||
]], nil, nil, function()
|
||||
eq(expected, items)
|
||||
eq(-1, selected)
|
||||
eq({1,0}, anchor)
|
||||
end)
|
||||
|
||||
-- down moves the selection in the menu, but does not insert anything
|
||||
feed('<down><down>')
|
||||
screen:expect([[
|
||||
|
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- INSERT --} |
|
||||
]], nil, nil, function()
|
||||
eq(expected, items)
|
||||
eq(1, selected)
|
||||
eq({1,0}, anchor)
|
||||
end)
|
||||
|
||||
feed('<cr>')
|
||||
screen:expect([[
|
||||
|
|
||||
bar^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- INSERT --} |
|
||||
]], nil, nil, function()
|
||||
eq(nil, items) -- popupmenu was hidden
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user