aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua9
-rw-r--r--test/functional/lua/vim_spec.lua5
-rw-r--r--test/functional/plugin/lsp_spec.lua20
-rw-r--r--test/functional/ui/decorations_spec.lua243
-rw-r--r--test/functional/ui/input_spec.lua38
5 files changed, 232 insertions, 83 deletions
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index 3bbb4c4517..bcd5e22492 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -154,6 +154,7 @@ function tests.capabilities_for_client_supports_method()
hoverProvider = true;
definitionProvider = false;
referencesProvider = false;
+ codeLensProvider = { resolveProvider = true; };
}
}
end;
@@ -402,11 +403,11 @@ function tests.basic_check_buffer_open_and_change_incremental()
contentChanges = {
{
range = {
- start = { line = 1; character = 0; };
- ["end"] = { line = 2; character = 0; };
+ start = { line = 1; character = 3; };
+ ["end"] = { line = 1; character = 3; };
};
- rangeLength = 4;
- text = "boop\n";
+ rangeLength = 0;
+ text = "boop";
};
}
})
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index e253db5297..9bf00b594b 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -715,6 +715,11 @@ describe('lua stdlib', function()
eq({false, 'Vim:E714: List required'}, exec_lua([[return {pcall(vim.fn.add, "aa", "bb")}]]))
end)
+ it('vim.fn should error when calling API function', function()
+ eq('Error executing lua: vim.lua:0: Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead',
+ pcall_err(exec_lua, "vim.fn.nvim_get_current_line()"))
+ end)
+
it('vim.rpcrequest and vim.rpcnotify', function()
exec_lua([[
chan = vim.fn.jobstart({'cat'}, {rpc=true})
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 8ac81daeef..c62d91cb6d 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -27,10 +27,10 @@ teardown(function()
os.remove(fake_lsp_logfile)
end)
-local function fake_lsp_server_setup(test_name, timeout_ms)
+local function fake_lsp_server_setup(test_name, timeout_ms, options)
exec_lua([=[
lsp = require('vim.lsp')
- local test_name, fixture_filename, logfile, timeout = ...
+ local test_name, fixture_filename, logfile, timeout, options = ...
TEST_RPC_CLIENT_ID = lsp.start_client {
cmd_env = {
NVIM_LOG_FILE = logfile;
@@ -52,18 +52,19 @@ local function fake_lsp_server_setup(test_name, timeout_ms)
on_init = function(client, result)
TEST_RPC_CLIENT = client
vim.rpcrequest(1, "init", result)
+ client.config.flags.allow_incremental_sync = options.allow_incremental_sync or false
end;
on_exit = function(...)
vim.rpcnotify(1, "exit", ...)
end;
}
- ]=], test_name, fake_lsp_code, fake_lsp_logfile, timeout_ms or 1e3)
+ ]=], test_name, fake_lsp_code, fake_lsp_logfile, timeout_ms or 1e3, options or {})
end
local function test_rpc_server(config)
if config.test_name then
clear()
- fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3)
+ fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3, config.options)
end
local client = setmetatable({}, {
__index = function(_, name)
@@ -257,6 +258,7 @@ describe('LSP', function()
eq(0, client.resolved_capabilities().text_document_did_change)
client.request('shutdown')
client.notify('exit')
+ client.stop()
end;
on_exit = function(code, signal)
eq(0, code, "exit code", fake_lsp_logfile)
@@ -334,6 +336,8 @@ describe('LSP', function()
local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full")
eq(full_kind, client.resolved_capabilities().text_document_did_change)
eq(true, client.resolved_capabilities().text_document_save)
+ eq(false, client.resolved_capabilities().code_lens)
+ eq(false, client.resolved_capabilities().code_lens_resolve)
end;
on_exit = function(code, signal)
eq(0, code, "exit code", fake_lsp_logfile)
@@ -359,6 +363,8 @@ describe('LSP', function()
eq(true, client.resolved_capabilities().hover)
eq(false, client.resolved_capabilities().goto_definition)
eq(false, client.resolved_capabilities().rename)
+ eq(true, client.resolved_capabilities().code_lens)
+ eq(true, client.resolved_capabilities().code_lens_resolve)
-- known methods for resolved capabilities
eq(true, client.supports_method("textDocument/hover"))
@@ -680,8 +686,7 @@ describe('LSP', function()
}
end)
- -- TODO(askhan) we don't support full for now, so we can disable these tests.
- pending('should check the body and didChange incremental', function()
+ it('should check the body and didChange incremental', function()
local expected_callbacks = {
{NIL, "shutdown", {}, 1};
{NIL, "finish", {}, 1};
@@ -690,6 +695,7 @@ describe('LSP', function()
local client
test_rpc_server {
test_name = "basic_check_buffer_open_and_change_incremental";
+ options = { allow_incremental_sync = true };
on_setup = function()
exec_lua [[
BUFFER = vim.api.nvim_create_buf(false, true)
@@ -716,7 +722,7 @@ describe('LSP', function()
if method == 'start' then
exec_lua [[
vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, {
- "boop";
+ "123boop";
})
]]
client.notify('finish')
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index 7a87521a6b..6cf549909a 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -8,6 +8,7 @@ local exec_lua = helpers.exec_lua
local exec = helpers.exec
local expect_events = helpers.expect_events
local meths = helpers.meths
+local command = helpers.command
describe('decorations providers', function()
local screen
@@ -314,11 +315,30 @@ describe('extmark decorations', function()
[2] = {foreground = Screen.colors.Brown};
[3] = {bold = true, foreground = Screen.colors.SeaGreen};
[4] = {background = Screen.colors.Red1, foreground = Screen.colors.Gray100};
+ [5] = {foreground = Screen.colors.Brown, bold = true};
+ [6] = {foreground = Screen.colors.DarkCyan};
+ [7] = {foreground = Screen.colors.Grey0, background = tonumber('0xff4c4c')};
+ [8] = {foreground = tonumber('0x180606'), background = tonumber('0xff4c4c')};
+ [9] = {foreground = tonumber('0xe40c0c'), background = tonumber('0xff4c4c'), bold = true};
+ [10] = {foreground = tonumber('0xb20000'), background = tonumber('0xff4c4c')};
+ [11] = {blend = 30, background = Screen.colors.Red1};
+ [12] = {foreground = Screen.colors.Brown, blend = 30, background = Screen.colors.Red1, bold = true};
+ [13] = {foreground = Screen.colors.Fuchsia};
+ [14] = {background = Screen.colors.Red1, foreground = Screen.colors.Black};
+ [15] = {background = Screen.colors.Red1, foreground = tonumber('0xb20000')};
+ [16] = {blend = 30, background = Screen.colors.Red1, foreground = Screen.colors.Magenta1};
+ [17] = {bold = true, foreground = Screen.colors.Brown, background = Screen.colors.LightGrey};
+ [18] = {background = Screen.colors.LightGrey};
+ [19] = {foreground = Screen.colors.Cyan4, background = Screen.colors.LightGrey};
+ [20] = {foreground = tonumber('0x180606'), background = tonumber('0xf13f3f')};
+ [21] = {foreground = Screen.colors.Gray0, background = tonumber('0xf13f3f')};
+ [22] = {foreground = tonumber('0xb20000'), background = tonumber('0xf13f3f')};
+ [23] = {foreground = Screen.colors.Magenta1, background = Screen.colors.LightGrey};
+ [24] = {bold = true};
}
end)
- it('can have virtual text of overlay style', function()
- insert [[
+ local example_text = [[
for _,item in ipairs(items) do
local text, hl_id_cell, count = unpack(item)
if hl_id_cell ~= nil then
@@ -331,69 +351,164 @@ for _,item in ipairs(items) do
colpos = colpos+1
end
end]]
- feed 'gg'
- local ns = meths.create_namespace 'test'
- for i = 1,9 do
- meths.buf_set_extmark(0, ns, i, 0, { virt_text={{'|', 'LineNr'}}, virt_text_pos='overlay'})
- if i == 3 or (i >= 6 and i <= 9) then
- meths.buf_set_extmark(0, ns, i, 4, { virt_text={{'|', 'NonText'}}, virt_text_pos='overlay'})
+ it('can have virtual text of overlay position', function()
+ insert(example_text)
+ feed 'gg'
+
+ local ns = meths.create_namespace 'test'
+ for i = 1,9 do
+ meths.buf_set_extmark(0, ns, i, 0, { virt_text={{'|', 'LineNr'}}, virt_text_pos='overlay'})
+ if i == 3 or (i >= 6 and i <= 9) then
+ meths.buf_set_extmark(0, ns, i, 4, { virt_text={{'|', 'NonText'}}, virt_text_pos='overlay'})
+ end
end
- end
- meths.buf_set_extmark(0, ns, 9, 10, { virt_text={{'foo'}, {'bar', 'MoreMsg'}, {'!!', 'ErrorMsg'}}, virt_text_pos='overlay'})
-
- -- can "float" beyond end of line
- meths.buf_set_extmark(0, ns, 5, 28, { virt_text={{'loopy', 'ErrorMsg'}}, virt_text_pos='overlay'})
- -- bound check: right edge of window
- meths.buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork ' }, {'bork bork bork', 'ErrorMsg'}}, virt_text_pos='overlay'})
-
- screen:expect{grid=[[
- ^for _,item in ipairs(items) do |
- {2:|} local text, hl_id_cell, count = unpack(item) |
- {2:|} if hl_id_cell ~= nil tbork bork bork {4:bork bork}|
- {2:|} {1:|} hl_id = hl_id_cell |
- {2:|} end |
- {2:|} for _ = 1, (count or 1) {4:loopy} |
- {2:|} {1:|} local cell = line[colpos] |
- {2:|} {1:|} cell.text = text |
- {2:|} {1:|} cell.hl_id = hl_id |
- {2:|} {1:|} cofoo{3:bar}{4:!!}olpos+1 |
- end |
- end |
- {1:~ }|
- {1:~ }|
- |
- ]]}
-
-
- -- handles broken lines
- screen:try_resize(22, 25)
- screen:expect{grid=[[
- ^for _,item in ipairs(i|
- tems) do |
- {2:|} local text, hl_id_|
- cell, count = unpack(i|
- tem) |
- {2:|} if hl_id_cell ~= n|
- il tbork bork bork {4:bor}|
- {2:|} {1:|} hl_id = hl_id_|
- cell |
- {2:|} end |
- {2:|} for _ = 1, (count |
- or 1) {4:loopy} |
- {2:|} {1:|} local cell = l|
- ine[colpos] |
- {2:|} {1:|} cell.text = te|
- xt |
- {2:|} {1:|} cell.hl_id = h|
- l_id |
- {2:|} {1:|} cofoo{3:bar}{4:!!}olpo|
- s+1 |
- end |
- end |
- {1:~ }|
- {1:~ }|
- |
- ]]}
+ meths.buf_set_extmark(0, ns, 9, 10, { virt_text={{'foo'}, {'bar', 'MoreMsg'}, {'!!', 'ErrorMsg'}}, virt_text_pos='overlay'})
+
+ -- can "float" beyond end of line
+ meths.buf_set_extmark(0, ns, 5, 28, { virt_text={{'loopy', 'ErrorMsg'}}, virt_text_pos='overlay'})
+ -- bound check: right edge of window
+ meths.buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork ' }, {'bork bork bork', 'ErrorMsg'}}, virt_text_pos='overlay'})
+
+ screen:expect{grid=[[
+ ^for _,item in ipairs(items) do |
+ {2:|} local text, hl_id_cell, count = unpack(item) |
+ {2:|} if hl_id_cell ~= nil tbork bork bork {4:bork bork}|
+ {2:|} {1:|} hl_id = hl_id_cell |
+ {2:|} end |
+ {2:|} for _ = 1, (count or 1) {4:loopy} |
+ {2:|} {1:|} local cell = line[colpos] |
+ {2:|} {1:|} cell.text = text |
+ {2:|} {1:|} cell.hl_id = hl_id |
+ {2:|} {1:|} cofoo{3:bar}{4:!!}olpos+1 |
+ end |
+ end |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+
+ -- handles broken lines
+ screen:try_resize(22, 25)
+ screen:expect{grid=[[
+ ^for _,item in ipairs(i|
+ tems) do |
+ {2:|} local text, hl_id_|
+ cell, count = unpack(i|
+ tem) |
+ {2:|} if hl_id_cell ~= n|
+ il tbork bork bork {4:bor}|
+ {2:|} {1:|} hl_id = hl_id_|
+ cell |
+ {2:|} end |
+ {2:|} for _ = 1, (count |
+ or 1) {4:loopy} |
+ {2:|} {1:|} local cell = l|
+ ine[colpos] |
+ {2:|} {1:|} cell.text = te|
+ xt |
+ {2:|} {1:|} cell.hl_id = h|
+ l_id |
+ {2:|} {1:|} cofoo{3:bar}{4:!!}olpo|
+ s+1 |
+ end |
+ end |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
+ it('can have virtual text of overlay position and styling', function()
+ insert(example_text)
+ feed 'gg'
+ local ns = meths.create_namespace 'test'
+
+ command 'set ft=lua'
+ command 'syntax on'
+
+ screen:expect{grid=[[
+ {5:^for} _,item {5:in} {6:ipairs}(items) {5:do} |
+ {5:local} text, hl_id_cell, count = unpack(item) |
+ {5:if} hl_id_cell ~= {13:nil} {5:then} |
+ hl_id = hl_id_cell |
+ {5:end} |
+ {5:for} _ = {13:1}, (count {5:or} {13:1}) {5:do} |
+ {5:local} cell = line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+{13:1} |
+ {5:end} |
+ {5:end} |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ command 'hi Blendy guibg=Red blend=30'
+ meths.buf_set_extmark(0, ns, 1, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend'})
+ meths.buf_set_extmark(0, ns, 2, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine'})
+ meths.buf_set_extmark(0, ns, 3, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace'})
+
+ meths.buf_set_extmark(0, ns, 4, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend', virt_text_hide=true})
+ meths.buf_set_extmark(0, ns, 5, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine', virt_text_hide=true})
+ meths.buf_set_extmark(0, ns, 6, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace', virt_text_hide=true})
+
+ screen:expect{grid=[[
+ {5:^for} _,item {5:in} {6:ipairs}(items) {5:do} |
+ {5:l}{8:blen}{7:dy}{10:e}{7:text}{10:h}{7:-}{10:_}{7:here}ell, count = unpack(item) |
+ {5:i}{12:c}{11:ombining color} {13:nil} {5:then} |
+ {11:replacing color}d_cell |
+ {5:e}{8:bl}{14:endy}{15:i}{14:text}{15:o}{14:-}{15:o}{14:h}{7:ere} |
+ {5:f}{12:co}{11:mbini}{16:n}{11:g color}t {5:or} {13:1}) {5:do} |
+ {11:replacing color} line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+{13:1} |
+ {5:end} |
+ {5:end} |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+
+ feed 'V5G'
+ screen:expect{grid=[[
+ {17:for}{18: _,item }{17:in}{18: }{19:ipairs}{18:(items) }{17:do} |
+ {18: }{17:l}{20:blen}{21:dy}{22:e}{21:text}{22:h}{21:-}{22:_}{21:here}{18:ell, count = unpack(item)} |
+ {18: }{17:i}{12:c}{11:ombining color}{18: }{23:nil}{18: }{17:then} |
+ {18: }{11:replacing color}{18:d_cell} |
+ {18: }{5:^e}{17:nd} |
+ {5:f}{12:co}{11:mbini}{16:n}{11:g color}t {5:or} {13:1}) {5:do} |
+ {11:replacing color} line[colpos] |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+{13:1} |
+ {5:end} |
+ {5:end} |
+ {1:~ }|
+ {1:~ }|
+ {24:-- VISUAL LINE --} |
+ ]]}
+
+ feed 'jj'
+ screen:expect{grid=[[
+ {17:for}{18: _,item }{17:in}{18: }{19:ipairs}{18:(items) }{17:do} |
+ {18: }{17:l}{20:blen}{21:dy}{22:e}{21:text}{22:h}{21:-}{22:_}{21:here}{18:ell, count = unpack(item)} |
+ {18: }{17:i}{12:c}{11:ombining color}{18: }{23:nil}{18: }{17:then} |
+ {18: }{11:replacing color}{18:d_cell} |
+ {18: }{17:end} |
+ {18: }{17:for}{18: _ = }{23:1}{18:, (count }{17:or}{18: }{23:1}{18:) }{17:do} |
+ {18: }^ {18: }{17:local}{18: cell = line[colpos]} |
+ cell.text = text |
+ cell.hl_id = hl_id |
+ colpos = colpos+{13:1} |
+ {5:end} |
+ {5:end} |
+ {1:~ }|
+ {1:~ }|
+ {24:-- VISUAL LINE --} |
+ ]]}
end)
end)
diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua
index 9313a35708..ea8968a653 100644
--- a/test/functional/ui/input_spec.lua
+++ b/test/functional/ui/input_spec.lua
@@ -1,16 +1,18 @@
local helpers = require('test.functional.helpers')(after_each)
-local clear, feed_command, nvim = helpers.clear, helpers.feed_command, helpers.nvim
+local clear, feed_command = helpers.clear, helpers.feed_command
local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq
local command = helpers.command
local expect = helpers.expect
+local meths = helpers.meths
+local exec_lua = helpers.exec_lua
local write_file = helpers.write_file
local Screen = require('test.functional.ui.screen')
-describe('mappings', function()
- local cid
+before_each(clear)
+describe('mappings', function()
local add_mapping = function(mapping, send)
- local cmd = "nnoremap "..mapping.." :call rpcnotify("..cid..", 'mapped', '"
+ local cmd = "nnoremap "..mapping.." :call rpcnotify(1, 'mapped', '"
..send:gsub('<', '<lt>').."')<cr>"
feed_command(cmd)
end
@@ -21,8 +23,6 @@ describe('mappings', function()
end
before_each(function()
- clear()
- cid = nvim('get_api_info')[1]
add_mapping('<C-L>', '<C-L>')
add_mapping('<C-S-L>', '<C-S-L>')
add_mapping('<s-up>', '<s-up>')
@@ -115,7 +115,6 @@ describe('mappings', function()
end)
describe('input utf sequences that contain CSI/K_SPECIAL', function()
- before_each(clear)
it('ok', function()
feed('i…<esc>')
expect('…')
@@ -129,7 +128,6 @@ describe('input non-printable chars', function()
it("doesn't crash when echoing them back", function()
write_file("Xtest-overwrite", [[foobar]])
- clear()
local screen = Screen.new(60,8)
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1},
@@ -215,3 +213,27 @@ describe('input non-printable chars', function()
]])
end)
end)
+
+describe("event processing and input", function()
+ it('not blocked by event bursts', function()
+ meths.set_keymap('', '<f2>', "<cmd>lua vim.rpcnotify(1, 'stop') winning = true <cr>", {noremap=true})
+
+ exec_lua [[
+ winning = false
+ burst = vim.schedule_wrap(function(tell)
+ if tell then
+ vim.rpcnotify(1, 'start')
+ end
+ -- Are we winning, son?
+ if not winning then
+ burst(false)
+ end
+ end)
+ burst(true)
+ ]]
+
+ eq({'notification', 'start', {}}, next_msg())
+ feed '<f2>'
+ eq({'notification', 'stop', {}}, next_msg())
+ end)
+end)