aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/core/job_spec.lua26
-rw-r--r--test/functional/lua/vim_spec.lua16
-rw-r--r--test/functional/plugin/lsp_spec.lua151
3 files changed, 69 insertions, 124 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index 9de0d08e79..34ab90d760 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -118,6 +118,32 @@ describe('jobs', function()
end
end)
+ it('handles case-insensitively matching #env vars', function()
+ nvim('command', "let $TOTO = 'abc'")
+ -- Since $Toto is being set in the job, it should take precedence over the
+ -- global $TOTO on Windows
+ nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}")
+ if iswin() then
+ nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]])
+ else
+ nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]])
+ end
+ nvim('command', "call jobwait([j])")
+ nvim('command', "let g:output = Normalize(g:job_opts.stdout)")
+ local actual = eval('g:output')
+ local expected
+ if iswin() then
+ -- Toto is normalized to TOTO so we can detect duplicates, and because
+ -- Windows doesn't care about case
+ expected = {'TOTO=def', ''}
+ else
+ expected = {'TOTO=abc', 'Toto=def', ''}
+ end
+ table.sort(actual)
+ table.sort(expected)
+ eq(expected, actual)
+ end)
+
it('uses &shell and &shellcmdflag if passed a string', function()
nvim('command', "let $VAR = 'abc'")
if iswin() then
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 9bf00b594b..6566da4807 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -945,12 +945,20 @@ describe('lua stdlib', function()
exec_lua [[
vim.api.nvim_set_var("testing", "hi")
vim.api.nvim_set_var("other", 123)
+ vim.api.nvim_set_var("floaty", 5120.1)
+ vim.api.nvim_set_var("nullvar", vim.NIL)
vim.api.nvim_set_var("to_delete", {hello="world"})
]]
eq('hi', funcs.luaeval "vim.g.testing")
eq(123, funcs.luaeval "vim.g.other")
+ eq(5120.1, funcs.luaeval "vim.g.floaty")
eq(NIL, funcs.luaeval "vim.g.nonexistant")
+ eq(NIL, funcs.luaeval "vim.g.nullvar")
+ -- lost over RPC, so test locally:
+ eq({false, true}, exec_lua [[
+ return {vim.g.nonexistant == vim.NIL, vim.g.nullvar == vim.NIL}
+ ]])
eq({hello="world"}, funcs.luaeval "vim.g.to_delete")
exec_lua [[
@@ -963,12 +971,20 @@ describe('lua stdlib', function()
exec_lua [[
vim.api.nvim_buf_set_var(0, "testing", "hi")
vim.api.nvim_buf_set_var(0, "other", 123)
+ vim.api.nvim_buf_set_var(0, "floaty", 5120.1)
+ vim.api.nvim_buf_set_var(0, "nullvar", vim.NIL)
vim.api.nvim_buf_set_var(0, "to_delete", {hello="world"})
]]
eq('hi', funcs.luaeval "vim.b.testing")
eq(123, funcs.luaeval "vim.b.other")
+ eq(5120.1, funcs.luaeval "vim.b.floaty")
eq(NIL, funcs.luaeval "vim.b.nonexistant")
+ eq(NIL, funcs.luaeval "vim.b.nullvar")
+ -- lost over RPC, so test locally:
+ eq({false, true}, exec_lua [[
+ return {vim.b.nonexistant == vim.NIL, vim.b.nullvar == vim.NIL}
+ ]])
eq({hello="world"}, funcs.luaeval "vim.b.to_delete")
exec_lua [[
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 2b7198bf63..663271deab 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -9,6 +9,7 @@ local eq = helpers.eq
local pcall_err = helpers.pcall_err
local pesc = helpers.pesc
local insert = helpers.insert
+local funcs = helpers.funcs
local retry = helpers.retry
local NIL = helpers.NIL
local read_file = require('test.helpers').read_file
@@ -1392,10 +1393,10 @@ describe('LSP', function()
{ label='foocar', sortText="e", insertText='foodar', textEdit={newText='foobar'} },
{ label='foocar', sortText="f", textEdit={newText='foobar'} },
-- real-world snippet text
- { label='foocar', sortText="g", insertText='foodar', textEdit={newText='foobar(${1:place holder}, ${2:more ...holder{\\}})'} },
- { label='foocar', sortText="h", insertText='foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}', textEdit={} },
+ { label='foocar', sortText="g", insertText='foodar', insertTextFormat=2, textEdit={newText='foobar(${1:place holder}, ${2:more ...holder{\\}})'} },
+ { label='foocar', sortText="h", insertText='foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}', insertTextFormat=2, textEdit={} },
-- nested snippet tokens
- { label='foocar', sortText="i", insertText='foodar(${1:var1 ${2|typ2,typ3|} ${3:tail}}) {$0\\}', textEdit={} },
+ { label='foocar', sortText="i", insertText='foodar(${1:var1 ${2|typ2,typ3|} ${3:tail}}) {$0\\}', insertTextFormat=2, textEdit={} },
-- plain text
{ label='foocar', sortText="j", insertText='foodar(${1:var1})', insertTextFormat=1, textEdit={} },
}
@@ -1407,9 +1408,9 @@ describe('LSP', function()
{ abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="d", insertText='foobar', textEdit={} } } } } },
{ abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="e", insertText='foodar', textEdit={newText='foobar'} } } } } },
{ abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="f", textEdit={newText='foobar'} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar(place holder, more ...holder{})', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="g", insertText='foodar', textEdit={newText='foobar(${1:place holder}, ${2:more ...holder{\\}})'} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(var1 typ1, var2 *typ2) {}', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="h", insertText='foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}', textEdit={} } } } } },
- { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(var1 typ2,typ3 tail) {}', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="i", insertText='foodar(${1:var1 ${2|typ2,typ3|} ${3:tail}}) {$0\\}', textEdit={} } } } } },
+ { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foobar(place holder, more ...holder{})', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="g", insertText='foodar', insertTextFormat=2, textEdit={newText='foobar(${1:place holder}, ${2:more ...holder{\\}})'} } } } } },
+ { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(var1 typ1, var2 *typ2) {}', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="h", insertText='foodar(${1:var1} typ1, ${2:var2} *typ2) {$0\\}', insertTextFormat=2, textEdit={} } } } } },
+ { abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(var1 typ2,typ3 tail) {}', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="i", insertText='foodar(${1:var1 ${2|typ2,typ3|} ${3:tail}}) {$0\\}', insertTextFormat=2, textEdit={} } } } } },
{ abbr = 'foocar', dup = 1, empty = 1, icase = 1, info = ' ', kind = 'Unknown', menu = '', word = 'foodar(${1:var1})', user_data = { nvim = { lsp = { completion_item = { label='foocar', sortText="j", insertText='foodar(${1:var1})', insertTextFormat=1, textEdit={} } } } } },
}
@@ -1820,36 +1821,20 @@ describe('LSP', function()
end)
describe('lsp.util.jump_to_location', function()
- local default_target_bufnr
- local default_target_uri = 'file://fake/uri'
-
- local create_buf = function(uri, lines)
- for i, line in ipairs(lines) do
- lines[i] = '"' .. line .. '"'
- end
- lines = table.concat(lines, ", ")
-
- -- Let's set "hidden" to true in order to avoid errors when switching
- -- between buffers in test.
- local code = string.format([[
- vim.api.nvim_set_option('hidden', true)
+ local target_bufnr
- local bufnr = vim.uri_to_bufnr("%s")
- local lines = {%s}
+ before_each(function()
+ target_bufnr = exec_lua [[
+ local bufnr = vim.uri_to_bufnr("file://fake/uri")
+ local lines = {"1st line of text", "å å ɧ 汉语 ↥ 🤦 🦄"}
vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
return bufnr
- ]], uri, lines)
-
- return exec_lua(code)
- end
-
- before_each(function()
- default_target_bufnr = create_buf(default_target_uri, {'1st line of text', 'å å ɧ 汉语 ↥ 🤦 🦄'})
+ ]]
end)
- local location = function(uri, start_line, start_char, end_line, end_char)
+ local location = function(start_line, start_char, end_line, end_char)
return {
- uri = uri,
+ uri = "file://fake/uri",
range = {
start = { line = start_line, character = start_char },
["end"] = { line = end_line, character = end_char },
@@ -1857,9 +1842,9 @@ describe('LSP', function()
}
end
- local jump = function(bufnr, msg)
+ local jump = function(msg)
eq(true, exec_lua('return vim.lsp.util.jump_to_location(...)', msg))
- eq(bufnr, exec_lua[[return vim.fn.bufnr('%')]])
+ eq(target_bufnr, exec_lua[[return vim.fn.bufnr('%')]])
return {
line = exec_lua[[return vim.fn.line('.')]],
col = exec_lua[[return vim.fn.col('.')]],
@@ -1867,13 +1852,13 @@ describe('LSP', function()
end
it('jumps to a Location', function()
- local pos = jump(default_target_bufnr, location(default_target_uri, 0, 9, 0, 9))
+ local pos = jump(location(0, 9, 0, 9))
eq(1, pos.line)
eq(10, pos.col)
end)
it('jumps to a LocationLink', function()
- local pos = jump(default_target_bufnr, {
+ local pos = jump({
targetUri = "file://fake/uri",
targetSelectionRange = {
start = { line = 0, character = 4 },
@@ -1889,104 +1874,22 @@ describe('LSP', function()
end)
it('jumps to the correct multibyte column', function()
- local pos = jump(default_target_bufnr, location(default_target_uri, 1, 2, 1, 2))
+ local pos = jump(location(1, 2, 1, 2))
eq(2, pos.line)
eq(4, pos.col)
eq('å', exec_lua[[return vim.fn.expand('<cword>')]])
end)
it('adds current position to jumplist before jumping', function()
- exec_lua([[
- vim.api.nvim_win_set_buf(0, ...)
- vim.api.nvim_win_set_cursor(0, {2, 0})
- ]], default_target_bufnr)
- jump(default_target_bufnr, location(default_target_uri, 0, 9, 0, 9))
-
- local mark = exec_lua([[return vim.inspect(vim.api.nvim_buf_get_mark(..., "'"))]], default_target_bufnr)
- eq('{ 2, 0 }', mark)
- end)
-
- it('should not push item to tagstack if destination is the same as source', function()
- -- Set cursor at the 2nd line, 1st character. This is the source position
- -- for the test, and will also be the destination one, making the cursor
- -- "motionless", thus not triggering a push to the tagstack.
- exec_lua(string.format([[
- vim.api.nvim_win_set_buf(0, %d)
- vim.api.nvim_win_set_cursor(0, {2, 0})
- ]], default_target_bufnr))
-
- -- Jump to 'f' in 'foobar', at the 2nd line.
- jump(default_target_bufnr, location(default_target_uri, 1, 0, 1, 0))
+ funcs.nvim_win_set_buf(0, target_bufnr)
+ local mark = funcs.nvim_buf_get_mark(target_bufnr, "'")
+ eq({ 1, 0 }, mark)
- local stack = exec_lua[[return vim.fn.gettagstack()]]
- eq(0, stack.length)
- end)
-
- it('should not push the same item from same buffer twice to tagstack', function()
- -- Set cursor at the 2nd line, 5th character.
- exec_lua(string.format([[
- vim.api.nvim_win_set_buf(0, %d)
- vim.api.nvim_win_set_cursor(0, {2, 4})
- ]], default_target_bufnr))
-
- local stack
-
- -- Jump to 1st line, 1st column.
- jump(default_target_bufnr, location(default_target_uri, 0, 0, 0, 0))
-
- stack = exec_lua[[return vim.fn.gettagstack()]]
- eq({default_target_bufnr, 2, 5, 0}, stack.items[1].from)
-
- -- Go back to 5th character at 2nd line, which is currently at the top of
- -- the tagstack.
- exec_lua(string.format([[
- vim.api.nvim_win_set_cursor(0, {2, 4})
- ]], default_target_bufnr))
-
- -- Jump again to 1st line, 1st column. Since we're jumping from the same
- -- position we have just jumped from, this jump shouldn't be pushed to
- -- the tagstack.
- jump(default_target_bufnr, location(default_target_uri, 0, 0, 0, 0))
+ funcs.nvim_win_set_cursor(0, {2, 3})
+ jump(location(0, 9, 0, 9))
- stack = exec_lua[[return vim.fn.gettagstack()]]
- eq({default_target_bufnr, 2, 5, 0}, stack.items[1].from)
- eq(1, stack.length)
- end)
-
- it('should not push the same item from another buffer twice to tagstack', function()
- local target_uri = 'file://foo/bar'
- local target_bufnr = create_buf(target_uri, {'this is a line', 'foobar'})
-
- -- Set cursor at the 1st line, 3rd character of the default test buffer.
- exec_lua(string.format([[
- vim.api.nvim_win_set_buf(0, %d)
- vim.api.nvim_win_set_cursor(0, {1, 2})
- ]], default_target_bufnr))
-
- local stack
-
- -- Jump to 1st line, 1st column of a different buffer from the source
- -- position.
- jump(target_bufnr, location(target_uri, 0, 0, 0, 0))
-
- stack = exec_lua[[return vim.fn.gettagstack()]]
- eq({default_target_bufnr, 1, 3, 0}, stack.items[1].from)
-
- -- Go back to 3rd character at 1st line of the default test buffer, which
- -- is currently at the top of the tagstack.
- exec_lua(string.format([[
- vim.api.nvim_win_set_buf(0, %d)
- vim.api.nvim_win_set_cursor(0, {1, 2})
- ]], default_target_bufnr))
-
- -- Jump again to 1st line, 1st column of the different buffer. Since
- -- we're jumping from the same position we have just jumped from, this
- -- jump shouldn't be pushed to the tagstack.
- jump(target_bufnr, location(target_uri, 0, 0, 0, 0))
-
- stack = exec_lua[[return vim.fn.gettagstack()]]
- eq({default_target_bufnr, 1, 3, 0}, stack.items[1].from)
- eq(1, stack.length)
+ mark = funcs.nvim_buf_get_mark(target_bufnr, "'")
+ eq({ 2, 3 }, mark)
end)
end)