aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/functional/autocmd/termclose_spec.lua2
-rw-r--r--test/functional/helpers.lua6
-rw-r--r--test/functional/terminal/cursor_spec.lua2
-rw-r--r--test/functional/terminal/edit_spec.lua2
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua2
-rw-r--r--test/functional/terminal/helpers.lua2
-rw-r--r--test/functional/terminal/highlight_spec.lua10
-rw-r--r--test/functional/terminal/scrollback_spec.lua2
-rw-r--r--test/functional/ui/screen.lua32
-rw-r--r--test/functional/viml/completion_spec.lua102
10 files changed, 142 insertions, 20 deletions
diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua
index 02ea0dbd95..0bc2931992 100644
--- a/test/functional/autocmd/termclose_spec.lua
+++ b/test/functional/autocmd/termclose_spec.lua
@@ -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()
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 2d54d23254..140e78aeb5 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -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,
diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua
index 1557868473..45595e0eb8 100644
--- a/test/functional/terminal/cursor_spec.lua
+++ b/test/functional/terminal/cursor_spec.lua
@@ -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)
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index c98aef70b1..1936f70b82 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -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
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 458fa02fca..135a234a23 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -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')
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index 1b8893c988..aacf109f2f 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -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.
diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua
index 95fbf2c871..3d0ff6091d 100644
--- a/test/functional/terminal/highlight_spec.lua
+++ b/test/functional/terminal/highlight_spec.lua
@@ -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)
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index 4790419bc8..60d6a6cc36 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -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([[
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index b219196866..96324bfac5 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -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
diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua
index 07544a91ab..5de3bb5da7 100644
--- a/test/functional/viml/completion_spec.lua
+++ b/test/functional/viml/completion_spec.lua
@@ -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)