aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua45
-rw-r--r--test/functional/ex_cmds/source_spec.lua20
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua29
-rw-r--r--test/functional/legacy/delete_spec.lua9
-rw-r--r--test/functional/legacy/expand_spec.lua2
-rw-r--r--test/functional/legacy/file_perm_spec.lua7
-rw-r--r--test/functional/legacy/fnamemodify_spec.lua11
-rw-r--r--test/functional/lua/api_spec.lua4
-rw-r--r--test/functional/lua/buffer_updates_spec.lua96
-rw-r--r--test/functional/lua/diagnostic_spec.lua110
-rw-r--r--test/functional/lua/luaeval_spec.lua7
-rw-r--r--test/functional/lua/uri_spec.lua17
-rw-r--r--test/functional/plugin/health_spec.lua4
-rw-r--r--test/functional/plugin/lsp_spec.lua81
-rw-r--r--test/functional/terminal/buffer_spec.lua24
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua15
-rw-r--r--test/functional/terminal/mouse_spec.lua10
-rw-r--r--test/functional/terminal/window_split_tab_spec.lua2
-rw-r--r--test/functional/vimscript/json_functions_spec.lua8
19 files changed, 435 insertions, 66 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 6b644ed519..d8914a3ab7 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -91,6 +91,14 @@ describe('API', function()
nvim('exec', 'set nowrap', false)
eq('nowrap\n\tLast set from anonymous :source',
nvim('exec', 'verbose set wrap?', true))
+
+ -- Using script var to force creation of a script item
+ nvim('exec', [[
+ let s:a = 1
+ set nowrap
+ ]], false)
+ eq('nowrap\n\tLast set from anonymous :source (script id 1)',
+ nvim('exec', 'verbose set wrap?', true))
end)
it('multiline input', function()
@@ -132,6 +140,43 @@ describe('API', function()
-- try no spaces before continuations to catch off-by-one error
nvim('exec', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', false)
eq({a = 98}, request('nvim_eval', 'g:ab'))
+
+ -- Script scope (s:)
+ eq('ahoy! script-scoped varrrrr', nvim('exec', [[
+ let s:pirate = 'script-scoped varrrrr'
+ function! s:avast_ye_hades(s) abort
+ return a:s .. ' ' .. s:pirate
+ endfunction
+ echo <sid>avast_ye_hades('ahoy!')
+ ]], true))
+
+ eq('ahoy! script-scoped varrrrr', nvim('exec', [[
+ let s:pirate = 'script-scoped varrrrr'
+ function! Avast_ye_hades(s) abort
+ return a:s .. ' ' .. s:pirate
+ endfunction
+ echo nvim_exec('echo Avast_ye_hades(''ahoy!'')', 1)
+ ]], true))
+
+ eq('Vim(call):E5555: API call: Vim(echo):E121: Undefined variable: s:pirate',
+ pcall_err(request, 'nvim_exec', [[
+ let s:pirate = 'script-scoped varrrrr'
+ call nvim_exec('echo s:pirate', 1)
+ ]], false))
+
+ -- Script items are created only on script var access
+ eq('1\n0', nvim('exec', [[
+ echo expand("<SID>")->empty()
+ let s:a = 123
+ echo expand("<SID>")->empty()
+ ]], true))
+
+ eq('1\n0', nvim('exec', [[
+ echo expand("<SID>")->empty()
+ function s:a() abort
+ endfunction
+ echo expand("<SID>")->empty()
+ ]], true))
end)
it('non-ASCII input', function()
diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua
index bdf6ae76d1..fa650d611b 100644
--- a/test/functional/ex_cmds/source_spec.lua
+++ b/test/functional/ex_cmds/source_spec.lua
@@ -25,12 +25,19 @@ describe(':source', function()
let b = #{
\ k: "v"
"\ (o_o)
- \ }]])
+ \ }
+ let c = expand("<SID>")->empty()
+ let s:s = 0zbeef.cafe
+ let d = s:s]])
command('source')
eq('2', meths.exec('echo a', true))
eq("{'k': 'v'}", meths.exec('echo b', true))
+ -- Script items are created only on script var access
+ eq("1", meths.exec('echo c', true))
+ eq("0zBEEFCAFE", meths.exec('echo d', true))
+
exec('set cpoptions+=C')
eq('Vim(let):E15: Invalid expression: #{', exc_exec('source'))
end)
@@ -43,7 +50,11 @@ describe(':source', function()
let b = #{
"\ (>_<)
\ K: "V"
- \ }]])
+ \ }
+ function! s:C() abort
+ return expand("<SID>") .. "C()"
+ endfunction
+ let D = {-> s:C()}]])
-- Source the 2nd line only
feed('ggjV')
@@ -55,6 +66,11 @@ describe(':source', function()
feed_command(':source')
eq('4', meths.exec('echo a', true))
eq("{'K': 'V'}", meths.exec('echo b', true))
+ eq("<SNR>1_C()", meths.exec('echo D()', true))
+
+ -- Source last line only
+ feed_command(':$source')
+ eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()'))
exec('set cpoptions+=C')
eq('Vim(let):E15: Invalid expression: #{', exc_exec("'<,'>source"))
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index 8e03d9a46e..9abf478070 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -246,6 +246,35 @@ function tests.capabilities_for_client_supports_method()
}
end
+function tests.check_forward_request_cancelled()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ expect_request("error_code_test", function()
+ return {code = -32800}, nil, {method = "error_code_test", client_id=1}
+ end)
+ notify('finish')
+ end;
+ }
+end
+
+function tests.check_forward_content_modified()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ expect_request("error_code_test", function()
+ return {code = -32801}, nil, {method = "error_code_test", client_id=1}
+ end)
+ expect_notification('finish')
+ notify('finish')
+ end;
+ }
+end
+
function tests.basic_finish()
skeleton {
on_init = function(params)
diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua
index f2ced8942d..141d9583e6 100644
--- a/test/functional/legacy/delete_spec.lua
+++ b/test/functional/legacy/delete_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, source = helpers.clear, helpers.source
local eq, eval, command = helpers.eq, helpers.eval, helpers.command
+local exc_exec = helpers.exc_exec
describe('Test for delete()', function()
before_each(clear)
@@ -38,7 +39,7 @@ describe('Test for delete()', function()
eq(eval("['a', 'b']"), eval("readfile('Xdir1/Xfile')"))
eq(1, eval("isdirectory('Xdir1/subdir')"))
eq(eval("['a', 'b']"), eval("readfile('Xdir1/subdir/Xfile')"))
- eq(1, eval("isdirectory('Xdir1/empty')"))
+ eq(1, eval("'Xdir1/empty'->isdirectory()"))
eq(0, eval("delete('Xdir1', 'rf')"))
eq(0, eval("isdirectory('Xdir1')"))
eq(-1, eval("delete('Xdir1', 'd')"))
@@ -114,4 +115,10 @@ describe('Test for delete()', function()
eq(0, eval("delete('Xdir4/Xfile')"))
eq(0, eval("delete('Xdir4', 'd')"))
end)
+
+ it('gives correct emsgs', function()
+ eq('Vim(call):E474: Invalid argument', exc_exec("call delete('')"))
+ eq('Vim(call):E15: Invalid expression: 0',
+ exc_exec("call delete('foo', 0)"))
+ end)
end)
diff --git a/test/functional/legacy/expand_spec.lua b/test/functional/legacy/expand_spec.lua
index f238128b31..cd3713eabe 100644
--- a/test/functional/legacy/expand_spec.lua
+++ b/test/functional/legacy/expand_spec.lua
@@ -81,7 +81,7 @@ describe('expand file name', function()
call assert_equal('e Xfile1', expandcmd('e %'))
edit Xfile2
edit Xfile1
- call assert_equal('e Xfile2', expandcmd('e #'))
+ call assert_equal('e Xfile2', 'e #'->expandcmd())
edit Xfile2
edit Xfile3
edit Xfile4
diff --git a/test/functional/legacy/file_perm_spec.lua b/test/functional/legacy/file_perm_spec.lua
index 8fdee95e91..ccdbfe0534 100644
--- a/test/functional/legacy/file_perm_spec.lua
+++ b/test/functional/legacy/file_perm_spec.lua
@@ -3,7 +3,7 @@ require('os')
local helpers = require('test.functional.helpers')(after_each)
local clear, call, eq = helpers.clear, helpers.call, helpers.eq
-local neq, exc_exec = helpers.neq, helpers.exc_exec
+local neq, exc_exec, eval = helpers.neq, helpers.exc_exec, helpers.eval
describe('Test getting and setting file permissions', function()
local tempfile = helpers.tmpname()
@@ -14,11 +14,12 @@ describe('Test getting and setting file permissions', function()
end)
it('file permissions', function()
+ -- eval() is used to test VimL method syntax for setfperm() and getfperm()
eq('', call('getfperm', tempfile))
- eq(0, call('setfperm', tempfile, 'r--------'))
+ eq(0, eval("'" .. tempfile .. "'->setfperm('r--------')"))
call('writefile', {'one'}, tempfile)
- eq(9, call('len', call('getfperm', tempfile)))
+ eq(9, eval("len('" .. tempfile .. "'->getfperm())"))
eq(1, call('setfperm', tempfile, 'rwx------'))
if helpers.is_os('win') then
diff --git a/test/functional/legacy/fnamemodify_spec.lua b/test/functional/legacy/fnamemodify_spec.lua
index 7e859bf0cf..6a5538c26f 100644
--- a/test/functional/legacy/fnamemodify_spec.lua
+++ b/test/functional/legacy/fnamemodify_spec.lua
@@ -60,12 +60,6 @@ describe('filename modifiers', function()
call assert_equal("'abc\\\ndef'", fnamemodify("abc\ndef", ':S'))
endif
endfunc
-
- func Test_expand()
- new
- call assert_equal("", expand('%:S'))
- quit
- endfunc
]=])
end)
@@ -73,9 +67,4 @@ describe('filename modifiers', function()
call('Test_fnamemodify')
expected_empty()
end)
-
- it('works for :S in an unnamed buffer', function()
- call('Test_expand')
- expected_empty()
- end)
end)
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua
index fdf79d55b2..8551c3d2a0 100644
--- a/test/functional/lua/api_spec.lua
+++ b/test/functional/lua/api_spec.lua
@@ -194,6 +194,10 @@ describe('luaeval(vim.api.…)', function()
exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]]))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]]))
+
+ eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
+ exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))
+
-- TODO: check for errors with Tabpage argument
-- TODO: check for errors with Window argument
-- TODO: check for errors with Buffer argument
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 073927bf22..c83a50b78b 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -1050,6 +1050,102 @@ describe('lua: nvim_buf_attach on_bytes', function()
}
end)
+ it("sends updates on U", function()
+ feed("ggiAAA<cr>BBB")
+ feed("<esc>gg$a CCC")
+
+ local check_events = setup_eventcheck(verify, nil)
+
+ feed("ggU")
+
+ check_events {
+ { "test1", "bytes", 1, 6, 0, 7, 7, 0, 0, 0, 0, 3, 3 };
+ }
+ end)
+
+ it("delete in completely empty buffer", function()
+ local check_events = setup_eventcheck(verify, nil)
+
+ command "delete"
+ check_events { }
+ end)
+
+ it("delete the only line of a buffer", function()
+ local check_events = setup_eventcheck(verify, {"AAA"})
+
+ command "delete"
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 4, 1, 0, 1 };
+ }
+ end)
+
+ it("delete the last line of a buffer with two lines", function()
+ local check_events = setup_eventcheck(verify, {"AAA", "BBB"})
+
+ command "2delete"
+ check_events {
+ { "test1", "bytes", 1, 3, 1, 0, 4, 1, 0, 4, 0, 0, 0 };
+ }
+ end)
+
+ it(":sort lines", function()
+ local check_events = setup_eventcheck(verify, {"CCC", "BBB", "AAA"})
+
+ command "%sort"
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 3, 0, 12 };
+ }
+ end)
+
+ it("handles already sorted lines", function()
+ local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"})
+
+ command "%sort"
+ check_events { }
+ end)
+
+ local function test_lockmarks(mode)
+ local description = (mode ~= "") and mode or "(baseline)"
+ it("test_lockmarks " .. description .. " %delete _", function()
+ local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"})
+
+ command(mode .. " %delete _")
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 1, 0, 1 };
+ }
+ end)
+
+ it("test_lockmarks " .. description .. " append()", function()
+ local check_events = setup_eventcheck(verify)
+
+ command(mode .. " call append(0, 'CCC')")
+ check_events {
+ { "test1", "bytes", 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 4 };
+ }
+
+ command(mode .. " call append(1, 'BBBB')")
+ check_events {
+ { "test1", "bytes", 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 5 };
+ }
+
+ command(mode .. " call append(2, '')")
+ check_events {
+ { "test1", "bytes", 1, 4, 2, 0, 9, 0, 0, 0, 1, 0, 1 };
+ }
+
+ command(mode .. " $delete _")
+ check_events {
+ { "test1", "bytes", 1, 5, 3, 0, 10, 1, 0, 1, 0, 0, 0 };
+ }
+
+ eq("CCC|BBBB|", table.concat(meths.buf_get_lines(0, 0, -1, true), "|"))
+ end)
+ end
+
+ -- check that behavior is identical with and without "lockmarks"
+ test_lockmarks ""
+ test_lockmarks "lockmarks"
+
teardown(function()
os.remove "Xtest-reload"
os.remove "Xtest-undofile"
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index 45aa4915cd..33469597a1 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -473,6 +473,78 @@ describe('vim.diagnostic', function()
end)
describe('config()', function()
+ it('works with global, namespace, and ephemeral options', function()
+ eq(1, exec_lua [[
+ vim.diagnostic.config({
+ virtual_text = false,
+ })
+
+ vim.diagnostic.config({
+ virtual_text = true,
+ underline = false,
+ }, diagnostic_ns)
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error('Some Error', 4, 4, 4, 4),
+ })
+
+ return count_extmarks(diagnostic_bufnr, diagnostic_ns)
+ ]])
+
+ eq(1, exec_lua [[
+ vim.diagnostic.config({
+ virtual_text = false,
+ })
+
+ vim.diagnostic.config({
+ virtual_text = false,
+ underline = false,
+ }, diagnostic_ns)
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error('Some Error', 4, 4, 4, 4),
+ }, {virtual_text = true})
+
+ return count_extmarks(diagnostic_bufnr, diagnostic_ns)
+ ]])
+
+ eq(0, exec_lua [[
+ vim.diagnostic.config({
+ virtual_text = false,
+ })
+
+ vim.diagnostic.config({
+ virtual_text = {severity=vim.diagnostic.severity.ERROR},
+ underline = false,
+ }, diagnostic_ns)
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_warning('Some Warning', 4, 4, 4, 4),
+ }, {virtual_text = true})
+
+ return count_extmarks(diagnostic_bufnr, diagnostic_ns)
+ ]])
+
+ eq(1, exec_lua [[
+ vim.diagnostic.config({
+ virtual_text = false,
+ })
+
+ vim.diagnostic.config({
+ virtual_text = {severity=vim.diagnostic.severity.ERROR},
+ underline = false,
+ }, diagnostic_ns)
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_warning('Some Warning', 4, 4, 4, 4),
+ }, {
+ virtual_text = {} -- An empty table uses default values
+ })
+
+ return count_extmarks(diagnostic_bufnr, diagnostic_ns)
+ ]])
+ end)
+
it('can use functions for config values', function()
exec_lua [[
vim.diagnostic.config({
@@ -1013,6 +1085,44 @@ describe('vim.diagnostic', function()
return lines
]])
end)
+
+ it('respects severity_sort', function()
+ exec_lua [[vim.api.nvim_win_set_buf(0, diagnostic_bufnr)]]
+
+ eq({"1. Syntax error", "2. Info", "3. Error", "4. Warning"}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 0, 1, 0, 3),
+ make_info('Info', 0, 3, 0, 4),
+ make_error('Error', 0, 2, 0, 2),
+ make_warning('Warning', 0, 0, 0, 1),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+
+ vim.diagnostic.config({severity_sort = false})
+
+ local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics { show_header = false }
+ local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ eq({"1. Syntax error", "2. Error", "3. Warning", "4. Info"}, exec_lua [[
+ vim.diagnostic.config({severity_sort = true})
+ local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics { show_header = false }
+ local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ eq({"1. Info", "2. Warning", "3. Error", "4. Syntax error"}, exec_lua [[
+ vim.diagnostic.config({severity_sort = { reverse = true } })
+ local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics { show_header = false }
+ local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+ end)
end)
describe('setloclist()', function()
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 255e99032f..0675ec9abd 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -86,14 +86,15 @@ describe('luaeval()', function()
-- meaningful later.
it('correctly evaluates scalars', function()
+ -- Also test method call (->) syntax
eq(1, funcs.luaeval('1'))
- eq(0, eval('type(luaeval("1"))'))
+ eq(0, eval('"1"->luaeval()->type()'))
eq(1.5, funcs.luaeval('1.5'))
- eq(5, eval('type(luaeval("1.5"))'))
+ eq(5, eval('"1.5"->luaeval()->type()'))
eq("test", funcs.luaeval('"test"'))
- eq(1, eval('type(luaeval("\'test\'"))'))
+ eq(1, eval('"\'test\'"->luaeval()->type()'))
eq('', funcs.luaeval('""'))
eq('\000', funcs.luaeval([['\0']]))
diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua
index 052a8a1ecd..81f1820986 100644
--- a/test/functional/lua/uri_spec.lua
+++ b/test/functional/lua/uri_spec.lua
@@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local exec_lua = helpers.exec_lua
local eq = helpers.eq
+local write_file = require('test.helpers').write_file
describe('URI methods', function()
before_each(function()
@@ -158,6 +159,22 @@ describe('URI methods', function()
end)
+ describe('uri from bufnr', function()
+ it('Windows paths should not be treated as uris', function()
+ if not helpers.iswin() then return end
+
+ local file = helpers.tmpname()
+ write_file(file, 'Test content')
+ local test_case = string.format([[
+ local file = '%s'
+ return vim.uri_from_bufnr(vim.fn.bufadd(file))
+ ]], file)
+ local expected_uri = 'file:///' .. file:gsub("\\", "/")
+ eq(expected_uri, exec_lua(test_case))
+ os.remove(file)
+ end)
+ end)
+
describe('uri to bufnr', function()
it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris', function()
local uri = 'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class'
diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua
index 45fcf945f4..b84e9d1533 100644
--- a/test/functional/plugin/health_spec.lua
+++ b/test/functional/plugin/health_spec.lua
@@ -208,12 +208,12 @@ describe('health.vim', function()
^ |
{Heading:foo: } |
{Bar:========================================================================}|
- {Bullet: -} {Error:ERROR:} No healthcheck found for "foo" plugin. |
+ {Bullet: -} {Error:ERROR}: No healthcheck found for "foo" plugin. |
|
{Heading:success1: health#success1#check} |
{Bar:========================================================================}|
{Heading2:##}{Heading: report 1} |
- {Bullet: -} {Ok:OK:} everything is fine |
+ {Bullet: -} {Ok:OK}: everything is fine |
|
]]}
end)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 8f9b194690..81ef8a9733 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -405,7 +405,7 @@ describe('LSP', function()
}
end)
- it('should call unsupported_method when trying to call an unsupported method', function()
+ it('should not call unsupported_method when trying to call an unsupported method', function()
local expected_handlers = {
{NIL, {}, {method="shutdown", client_id=1}};
}
@@ -415,24 +415,12 @@ describe('LSP', function()
exec_lua([=[
BUFFER = vim.api.nvim_get_current_buf()
lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)
- vim.lsp.handlers['textDocument/typeDefinition'] = function(err, result, ctx)
- local method = ctx.method
- vim.lsp._last_lsp_handler = { err = err; method = method }
- end
- vim.lsp._unsupported_method = function(method)
- vim.lsp._last_unsupported_method = method
- return 'fake-error'
- end
- vim.lsp.buf.type_definition()
+ vim.lsp.handlers['textDocument/typeDefinition'] = function() end
]=])
end;
on_init = function(client)
client.stop()
- local method = exec_lua("return vim.lsp._last_unsupported_method")
- eq("textDocument/typeDefinition", method)
- local lsp_cb_call = exec_lua("return vim.lsp._last_lsp_handler")
- eq("fake-error", lsp_cb_call.err)
- eq("textDocument/typeDefinition", lsp_cb_call.method)
+ exec_lua("vim.lsp.buf.type_definition()")
exec_lua [[
vim.api.nvim_command(BUFFER.."bwipeout")
]]
@@ -447,7 +435,7 @@ describe('LSP', function()
}
end)
- it('shouldn\'t call unsupported_method when no client and trying to call an unsupported method', function()
+ it('should not call unsupported_method when no client and trying to call an unsupported method', function()
local expected_handlers = {
{NIL, {}, {method="shutdown", client_id=1}};
}
@@ -455,20 +443,12 @@ describe('LSP', function()
test_name = "capabilities_for_client_supports_method";
on_setup = function()
exec_lua([=[
- vim.lsp.handlers['textDocument/typeDefinition'] = function(err, method)
- vim.lsp._last_lsp_handler = { err = err; method = method }
- end
- vim.lsp._unsupported_method = function(method)
- vim.lsp._last_unsupported_method = method
- return 'fake-error'
- end
- vim.lsp.buf.type_definition()
+ vim.lsp.handlers['textDocument/typeDefinition'] = function() end
]=])
end;
on_init = function(client)
client.stop()
- eq(NIL, exec_lua("return vim.lsp._last_unsupported_method"))
- eq(NIL, exec_lua("return vim.lsp._last_lsp_handler"))
+ exec_lua("vim.lsp.buf.type_definition()")
end;
on_exit = function(code, signal)
eq(0, code, "exit code", fake_lsp_logfile)
@@ -480,6 +460,55 @@ describe('LSP', function()
}
end)
+ it('should not forward RequestCancelled to callback', function()
+ local expected_handlers = {
+ {NIL, {}, {method="finish", client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_forward_request_cancelled";
+ on_init = function(_client)
+ _client.request("error_code_test")
+ client = _client
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, _, ctx)
+ eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler")
+ if ctx.method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
+ it('should forward ContentModified to callback', function()
+ local expected_handlers = {
+ {NIL, {}, {method="finish", client_id=1}};
+ {{code = -32801}, NIL, {method = "error_code_test", client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_forward_content_modified";
+ on_init = function(_client)
+ _client.request("error_code_test")
+ client = _client
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, _, ctx)
+ eq(table.remove(expected_handlers), {err, _, ctx}, "expected handler")
+ -- if ctx.method == 'error_code_test' then client.notify("finish") end
+ if ctx.method ~= 'finish' then client.notify('finish') end
+ if ctx.method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
it('should not send didOpen if the buffer closes before init', function()
local expected_handlers = {
{NIL, {}, {method="shutdown", client_id=1}};
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 103ae59b8e..7dcca231ee 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -22,14 +22,28 @@ describe(':terminal buffer', function()
it('terminal-mode forces various options', function()
feed([[<C-\><C-N>]])
- command('setlocal cursorline cursorcolumn scrolloff=4 sidescrolloff=7')
- eq({ 1, 1, 4, 7 }, eval('[&l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
- eq('n', eval('mode()'))
+ command('setlocal cursorline cursorlineopt=both cursorcolumn scrolloff=4 sidescrolloff=7')
+ eq({ 'both', 1, 1, 4, 7 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
+ eq('nt', eval('mode(1)'))
-- Enter terminal-mode ("insert" mode in :terminal).
feed('i')
- eq('t', eval('mode()'))
- eq({ 0, 0, 0, 0 }, eval('[&l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
+ eq('t', eval('mode(1)'))
+ eq({ 'number', 1, 0, 0, 0 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
+ end)
+
+ it('terminal-mode does not change cursorlineopt if cursorline is disabled', function()
+ feed([[<C-\><C-N>]])
+ command('setlocal nocursorline cursorlineopt=both')
+ feed('i')
+ eq({ 0, 'both' }, eval('[&l:cursorline, &l:cursorlineopt]'))
+ end)
+
+ it('terminal-mode disables cursorline when cursorlineopt is only set to "line', function()
+ feed([[<C-\><C-N>]])
+ command('setlocal cursorline cursorlineopt=line')
+ feed('i')
+ eq({ 0, 'line' }, eval('[&l:cursorline, &l:cursorlineopt]'))
end)
describe('when a new file is edited', function()
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 707c355069..065dd72485 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -96,19 +96,28 @@ describe(':terminal', function()
eq(3, #jumps)
end)
+ it('nvim_get_mode() in :terminal', function()
+ command(':terminal')
+ eq({ blocking=false, mode='nt' }, nvim('get_mode'))
+ feed('i')
+ eq({ blocking=false, mode='t' }, nvim('get_mode'))
+ feed([[<C-\><C-N>]])
+ eq({ blocking=false, mode='nt' }, nvim('get_mode'))
+ end)
+
it(':stopinsert RPC request exits terminal-mode #7807', function()
command(':terminal')
feed('i[tui] insert-mode')
eq({ blocking=false, mode='t' }, nvim('get_mode'))
command('stopinsert')
- eq({ blocking=false, mode='n' }, nvim('get_mode'))
+ eq({ blocking=false, mode='nt' }, nvim('get_mode'))
end)
it(':stopinsert in normal mode doesn\'t break insert mode #9889', function()
command(':terminal')
- eq({ blocking=false, mode='n' }, nvim('get_mode'))
+ eq({ blocking=false, mode='nt' }, nvim('get_mode'))
command(':stopinsert')
- eq({ blocking=false, mode='n' }, nvim('get_mode'))
+ eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('a')
eq({ blocking=false, mode='t' }, nvim('get_mode'))
end)
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index 0eb5901b3b..3d8441b93c 100644
--- a/test/functional/terminal/mouse_spec.lua
+++ b/test/functional/terminal/mouse_spec.lua
@@ -33,16 +33,16 @@ describe(':terminal mouse', function()
describe('when the terminal has focus', function()
it('will exit focus on mouse-scroll', function()
- eq('t', eval('mode()'))
+ eq('t', eval('mode(1)'))
feed('<ScrollWheelUp><0,0>')
- eq('n', eval('mode()'))
+ eq('nt', eval('mode(1)'))
end)
it('will exit focus on <C-\\> + mouse-scroll', function()
- eq('t', eval('mode()'))
+ eq('t', eval('mode(1)'))
feed('<C-\\>')
feed('<ScrollWheelUp><0,0>')
- eq('n', eval('mode()'))
+ eq('nt', eval('mode(1)'))
end)
describe('with mouse events enabled by the program', function()
@@ -94,7 +94,7 @@ describe(':terminal mouse', function()
-- When the display area such as a number is clicked, it returns to the
-- normal mode.
feed('<LeftMouse><3,0>')
- eq('n', eval('mode()'))
+ eq('nt', eval('mode(1)'))
screen:expect([[
{7: 11 }^line28 |
{7: 12 }line29 |
diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua
index 188afa1e84..c92107082e 100644
--- a/test/functional/terminal/window_split_tab_spec.lua
+++ b/test/functional/terminal/window_split_tab_spec.lua
@@ -111,7 +111,7 @@ describe(':terminal', function()
command('terminal')
feed('a<Cmd>wincmd j<CR>')
eq(2, eval("winnr()"))
- eq('t', eval('mode()'))
+ eq('t', eval('mode(1)'))
end)
end)
diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua
index c3b607b544..5d1597f53d 100644
--- a/test/functional/vimscript/json_functions_spec.lua
+++ b/test/functional/vimscript/json_functions_spec.lua
@@ -168,7 +168,8 @@ describe('json_decode() function', function()
end)
it('parses floating-point numbers', function()
- eq('100000.0', eval('string(json_decode("100000.0"))'))
+ -- Also test method call (->) syntax
+ eq('100000.0', eval('"100000.0"->json_decode()->string()'))
eq(100000.5, funcs.json_decode('100000.5'))
eq(-100000.5, funcs.json_decode('-100000.5'))
eq(-100000.5e50, funcs.json_decode('-100000.5e50'))
@@ -549,11 +550,12 @@ describe('json_encode() function', function()
end)
it('dumps floats', function()
- eq('0.0', eval('json_encode(0.0)'))
+ -- Also test method call (->) syntax
+ eq('0.0', eval('0.0->json_encode()'))
eq('10.5', funcs.json_encode(10.5))
eq('-10.5', funcs.json_encode(-10.5))
eq('-1.0e-5', funcs.json_encode(-1e-5))
- eq('1.0e50', eval('json_encode(1.0e50)'))
+ eq('1.0e50', eval('1.0e50->json_encode()'))
end)
it('fails to dump NaN and infinite values', function()