mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +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', 'shell', nvim_dir .. '/shell-test')
|
||||||
nvim('set_option', 'shellcmdflag', 'EXE')
|
nvim('set_option', 'shellcmdflag', 'EXE')
|
||||||
screen = Screen.new(20, 4)
|
screen = Screen.new(20, 4)
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works as expected', function()
|
it('works as expected', function()
|
||||||
|
@@ -306,6 +306,10 @@ local function nvim(method, ...)
|
|||||||
return request('vim_'..method, ...)
|
return request('vim_'..method, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function ui(method, ...)
|
||||||
|
return request('nvim_ui_'..method, ...)
|
||||||
|
end
|
||||||
|
|
||||||
local function nvim_async(method, ...)
|
local function nvim_async(method, ...)
|
||||||
session:notify('vim_'..method, ...)
|
session:notify('vim_'..method, ...)
|
||||||
end
|
end
|
||||||
@@ -432,6 +436,7 @@ end
|
|||||||
|
|
||||||
local funcs = create_callindex(nvim_call)
|
local funcs = create_callindex(nvim_call)
|
||||||
local meths = create_callindex(nvim)
|
local meths = create_callindex(nvim)
|
||||||
|
local uimeths = create_callindex(ui)
|
||||||
local bufmeths = create_callindex(buffer)
|
local bufmeths = create_callindex(buffer)
|
||||||
local winmeths = create_callindex(window)
|
local winmeths = create_callindex(window)
|
||||||
local tabmeths = create_callindex(tabpage)
|
local tabmeths = create_callindex(tabpage)
|
||||||
@@ -490,6 +495,7 @@ return function(after_each)
|
|||||||
bufmeths = bufmeths,
|
bufmeths = bufmeths,
|
||||||
winmeths = winmeths,
|
winmeths = winmeths,
|
||||||
tabmeths = tabmeths,
|
tabmeths = tabmeths,
|
||||||
|
uimeths = uimeths,
|
||||||
curbufmeths = curbufmeths,
|
curbufmeths = curbufmeths,
|
||||||
curwinmeths = curwinmeths,
|
curwinmeths = curwinmeths,
|
||||||
curtabmeths = curtabmeths,
|
curtabmeths = curtabmeths,
|
||||||
|
@@ -135,7 +135,7 @@ describe('cursor with customized highlighting', function()
|
|||||||
[2] = {foreground = 55, background = 56},
|
[2] = {foreground = 55, background = 56},
|
||||||
[3] = {bold = true},
|
[3] = {bold = true},
|
||||||
})
|
})
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
execute('call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
execute('call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@ local eq = helpers.eq
|
|||||||
describe(':edit term://*', function()
|
describe(':edit term://*', function()
|
||||||
local get_screen = function(columns, lines)
|
local get_screen = function(columns, lines)
|
||||||
local scr = screen.new(columns, lines)
|
local scr = screen.new(columns, lines)
|
||||||
scr:attach(false)
|
scr:attach({rgb=false})
|
||||||
return scr
|
return scr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ describe(':terminal', function()
|
|||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
clear()
|
||||||
screen = Screen.new(50, 4)
|
screen = Screen.new(50, 4)
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
nvim('set_option', 'shell', nvim_dir..'/shell-test')
|
nvim('set_option', 'shell', nvim_dir..'/shell-test')
|
||||||
nvim('set_option', 'shellcmdflag', 'EXE')
|
nvim('set_option', 'shellcmdflag', 'EXE')
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ local function screen_setup(extra_height, command)
|
|||||||
[9] = {foreground = 4},
|
[9] = {foreground = 4},
|
||||||
})
|
})
|
||||||
|
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
-- tty-test puts the terminal into raw mode and echoes all input. tests are
|
-- 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
|
-- done by feeding it with terminfo codes to control the display and
|
||||||
-- verifying output with screen:expect.
|
-- verifying output with screen:expect.
|
||||||
|
@@ -25,7 +25,7 @@ describe('terminal window highlighting', function()
|
|||||||
[10] = {reverse = true},
|
[10] = {reverse = true},
|
||||||
[11] = {background = 11},
|
[11] = {background = 11},
|
||||||
})
|
})
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
tty ready |
|
tty ready |
|
||||||
@@ -127,7 +127,7 @@ describe('terminal window highlighting with custom palette', function()
|
|||||||
[8] = {background = 11},
|
[8] = {background = 11},
|
||||||
[9] = {bold = true},
|
[9] = {bold = true},
|
||||||
})
|
})
|
||||||
screen:attach(true)
|
screen:attach({rgb=true})
|
||||||
nvim('set_var', 'terminal_color_3', '#123456')
|
nvim('set_var', 'terminal_color_3', '#123456')
|
||||||
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
@@ -185,7 +185,7 @@ describe('synIDattr()', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns gui-color if RGB-capable UI is attached', function()
|
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('#ff0000', eval('synIDattr(hlID("Normal"), "fg")'))
|
||||||
eq('Black', eval('synIDattr(hlID("Normal"), "bg")'))
|
eq('Black', eval('synIDattr(hlID("Normal"), "bg")'))
|
||||||
eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")'))
|
eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")'))
|
||||||
@@ -193,7 +193,7 @@ describe('synIDattr()', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns #RRGGBB value for fg#/bg#/sp#', function()
|
it('returns #RRGGBB value for fg#/bg#/sp#', function()
|
||||||
screen:attach(true)
|
screen:attach({rgb=true})
|
||||||
eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")'))
|
eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")'))
|
||||||
eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")'))
|
eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")'))
|
||||||
eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")'))
|
eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")'))
|
||||||
@@ -201,7 +201,7 @@ describe('synIDattr()', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns color number if non-GUI', function()
|
it('returns color number if non-GUI', function()
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
|
eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
|
||||||
eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
|
eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
|
||||||
end)
|
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()
|
it('will push extra lines to scrollback', function()
|
||||||
clear()
|
clear()
|
||||||
local screen = Screen.new(50, 7)
|
local screen = Screen.new(50, 7)
|
||||||
screen:attach(false)
|
screen:attach({rgb=false})
|
||||||
execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
|
execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
|
||||||
wait()
|
wait()
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
@@ -106,7 +106,7 @@
|
|||||||
-- use `screen:snapshot_util({},true)`
|
-- use `screen:snapshot_util({},true)`
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')(nil)
|
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 dedent = helpers.dedent
|
||||||
|
|
||||||
local Screen = {}
|
local Screen = {}
|
||||||
@@ -192,22 +192,22 @@ function Screen:set_default_attr_ignore(attr_ignore)
|
|||||||
self._default_attr_ignore = attr_ignore
|
self._default_attr_ignore = attr_ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:attach(rgb)
|
function Screen:attach(options)
|
||||||
if rgb == nil then
|
if options == nil then
|
||||||
rgb = true
|
options = {rgb=true}
|
||||||
end
|
end
|
||||||
request('ui_attach', self._width, self._height, rgb)
|
uimeths.attach(self._width, self._height, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:detach()
|
function Screen:detach()
|
||||||
request('ui_detach')
|
uimeths.detach()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:try_resize(columns, rows)
|
function Screen:try_resize(columns, rows)
|
||||||
request('ui_try_resize', columns, rows)
|
uimeths.try_resize(columns, rows)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:expect(expected, attr_ids, attr_ignore)
|
function Screen:expect(expected, attr_ids, attr_ignore, condition)
|
||||||
-- remove the last line and dedent
|
-- remove the last line and dedent
|
||||||
expected = dedent(expected:gsub('\n[ ]+$', ''))
|
expected = dedent(expected:gsub('\n[ ]+$', ''))
|
||||||
local expected_rows = {}
|
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 ids = attr_ids or self._default_attr_ids
|
||||||
local ignore = attr_ignore or self._default_attr_ignore
|
local ignore = attr_ignore or self._default_attr_ignore
|
||||||
self:wait(function()
|
self:wait(function()
|
||||||
|
if condition ~= nil then
|
||||||
|
local status, res = pcall(condition)
|
||||||
|
if not status then
|
||||||
|
return tostring(res)
|
||||||
|
end
|
||||||
|
end
|
||||||
local actual_rows = {}
|
local actual_rows = {}
|
||||||
for i = 1, self._height do
|
for i = 1, self._height do
|
||||||
actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore)
|
actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore)
|
||||||
@@ -303,12 +309,20 @@ function Screen:_redraw(updates)
|
|||||||
local method = update[1]
|
local method = update[1]
|
||||||
for i = 2, #update do
|
for i = 2, #update do
|
||||||
local handler = self['_handle_'..method]
|
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
|
end
|
||||||
-- print(self:_current_screen())
|
-- print(self:_current_screen())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Screen:set_on_event_handler(callback)
|
||||||
|
self._on_event = callback
|
||||||
|
end
|
||||||
|
|
||||||
function Screen:_handle_resize(width, height)
|
function Screen:_handle_resize(width, height)
|
||||||
local rows = {}
|
local rows = {}
|
||||||
for _ = 1, height do
|
for _ = 1, height do
|
||||||
|
@@ -755,4 +755,106 @@ describe('completion', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
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)
|
end)
|
||||||
|
Reference in New Issue
Block a user