local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local assert_alive = n.assert_alive
local clear, feed = n.clear, n.feed
local eval, eq, ok = n.eval, t.eq, t.ok
local source, expect = n.source, n.expect
local fn = n.fn
local command = n.command
local api = n.api
local poke_eventloop = n.poke_eventloop
local exec_lua = n.exec_lua
describe('completion', function()
local screen
before_each(function()
clear()
source([[
set completeopt-=noselect
" Avoid tags completion (if running test locally).
set complete-=t
]])
screen = Screen.new(60, 8)
screen:add_extra_attr_ids {
[100] = { foreground = Screen.colors.Gray0, background = Screen.colors.Yellow },
[101] = { background = Screen.colors.Gray0 },
}
end)
describe('v:completed_item', function()
it('is empty dict until completion', function()
eq({}, eval('v:completed_item'))
end)
it('is empty dict if the candidate is not inserted', function()
feed('ifoo<ESC>o<C-x><C-n>')
screen:expect([[
foo |
foo^ |
{1:~ }|*5
{5:-- Keyword Local completion (^N^P) The only match} |
]])
feed('<C-e>')
screen:expect([[
foo |
^ |
{1:~ }|*5
{5:-- INSERT --} |
]])
feed('<ESC>')
eq({}, eval('v:completed_item'))
end)
it('returns expected dict in normal completion', function()
feed('ifoo<ESC>o<C-x><C-n>')
eq('foo', eval('getline(2)'))
eq(
{ word = 'foo', abbr = '', menu = '', info = '', kind = '', user_data = '' },
eval('v:completed_item')
)
end)
it('is readonly', function()
screen:try_resize(80, 8)
feed('ifoo<ESC>o<C-x><C-n><ESC>')
t.matches('E46%: ', t.pcall_err(command, 'let v:completed_item.word = "bar"'))
t.matches('E46%: ', t.pcall_err(command, 'let v:completed_item.abbr = "bar"'))
t.matches('E46%: ', t.pcall_err(command, 'let v:completed_item.menu = "bar"'))
t.matches('E46%: ', t.pcall_err(command, 'let v:completed_item.info = "bar"'))
t.matches('E46%: ', t.pcall_err(command, 'let v:completed_item.kind = "bar"'))
t.matches('E46%: ', t.pcall_err(command, 'let v:completed_item.user_data = "bar"'))
end)
it('returns expected dict in omni completion', function()
source([[
function! TestOmni(findstart, base) abort
return a:findstart ? 0 : [{'word': 'foo', 'abbr': 'bar',
\ 'menu': 'baz', 'info': 'foobar', 'kind': 'foobaz'},
\ {'word': 'word', 'abbr': 'abbr', 'menu': 'menu',
\ 'info': 'info', 'kind': 'kind'}]
endfunction
setlocal omnifunc=TestOmni
]])
feed('i<C-x><C-o>')
eq('foo', eval('getline(1)'))
screen:expect([[
foo^ |
{12:bar foobaz baz }{1: }|
{4:abbr kind menu }{1: }|
{1:~ }|*4
{5:-- Omni completion (^O^N^P) }{6:match 1 of 2} |
]])
eq({
word = 'foo',
abbr = 'bar',
menu = 'baz',
info = 'foobar'<
|