diff options
Diffstat (limited to 'test/functional')
20 files changed, 736 insertions, 67 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 81fad206da..01fcfab543 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -707,4 +707,59 @@ describe('api/buf', function() eq({3, 0}, curbuf('get_mark', 'v')) end) end) + + describe('nvim_buf_set_mark', function() + it('works with buffer local marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + eq(true, curbufmeths.set_mark('z', 1, 1)) + eq({1, 1}, curbufmeths.get_mark('z')) + end) + it('works with file/uppercase marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + eq(true, curbufmeths.set_mark('Z', 3, 1)) + eq({3, 1}, curbufmeths.get_mark('Z')) + end) + it('fails when invalid marks names are used', function() + eq(false, pcall(curbufmeths.set_mark, '!', 1, 0)) + eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0)) + end) + it('fails when invalid buffer number is used', function() + eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1)) + end) + end) + + describe('nvim_buf_del_mark', function() + it('works with buffer local marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + curbufmeths.set_mark('z', 3, 1) + eq(true, curbufmeths.del_mark('z')) + eq({0, 0}, curbufmeths.get_mark('z')) + end) + it('works with file/uppercase marks', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + curbufmeths.set_mark('Z', 3, 3) + eq(true, curbufmeths.del_mark('Z')) + eq({0, 0}, curbufmeths.get_mark('Z')) + end) + it('returns false in marks not set in this buffer', function() + local abuf = meths.create_buf(false,true) + bufmeths.set_lines(abuf, -1, -1, true, {'a', 'bit of', 'text'}) + bufmeths.set_mark(abuf, 'A', 2, 2) + eq(false, curbufmeths.del_mark('A')) + eq({2, 2}, bufmeths.get_mark(abuf, 'A')) + end) + it('returns false if mark was not deleted', function() + curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) + curbufmeths.set_mark('z', 3, 1) + eq(true, curbufmeths.del_mark('z')) + eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted + end) + it('fails when invalid marks names are used', function() + eq(false, pcall(curbufmeths.del_mark, '!')) + eq(false, pcall(curbufmeths.del_mark, 'fail')) + end) + it('fails when invalid buffer number is used', function() + eq(false, pcall(meths.buf_del_mark, 99, 'a')) + end) + end) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 6bcf8dd91f..6b644ed519 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2267,4 +2267,59 @@ describe('API', function() ]]} end) end) + + describe('nvim_del_mark', function() + it('works', function() + local buf = meths.create_buf(false,true) + meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'}) + eq(true, meths.buf_set_mark(buf, 'F', 2, 2)) + eq(true, meths.del_mark('F')) + eq({0, 0}, meths.buf_get_mark(buf, 'F')) + end) + it('fails when invalid marks are used', function() + eq(false, pcall(meths.del_mark, 'f')) + eq(false, pcall(meths.del_mark, '!')) + eq(false, pcall(meths.del_mark, 'fail')) + end) + end) + describe('nvim_get_mark', function() + it('works', function() + local buf = meths.create_buf(false,true) + meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'}) + meths.buf_set_mark(buf, 'F', 2, 2) + meths.buf_set_name(buf, "mybuf") + local mark = meths.get_mark('F') + -- Compare the path tail ony + assert(string.find(mark[4], "mybuf$")) + eq({2, 2, buf.id, mark[4]}, mark) + end) + it('fails when invalid marks are used', function() + eq(false, pcall(meths.del_mark, 'f')) + eq(false, pcall(meths.del_mark, '!')) + eq(false, pcall(meths.del_mark, 'fail')) + end) + it('returns the expected when mark is not set', function() + eq(true, meths.del_mark('A')) + eq({0, 0, 0, ''}, meths.get_mark('A')) + end) + it('works with deleted buffers', function() + local fname = tmpname() + write_file(fname, 'a\nbit of\text') + nvim("command", "edit " .. fname) + local buf = meths.get_current_buf() + + meths.buf_set_mark(buf, 'F', 2, 2) + nvim("command", "new") -- Create new buf to avoid :bd failing + nvim("command", "bd! " .. buf.id) + os.remove(fname) + + local mark = meths.get_mark('F') + -- To avoid comparing relative vs absolute path + local mfname = mark[4] + local tail_patt = [[[\/][^\/]*$]] + -- tail of paths should be equals + eq(fname:match(tail_patt), mfname:match(tail_patt)) + eq({2, 2, buf.id, mark[4]}, mark) + end) + end) end) diff --git a/test/functional/fixtures/autoload/health/full_render.vim b/test/functional/fixtures/autoload/health/full_render.vim new file mode 100644 index 0000000000..2064b8606e --- /dev/null +++ b/test/functional/fixtures/autoload/health/full_render.vim @@ -0,0 +1,8 @@ +function! health#full_render#check() + call health#report_start("report 1") + call health#report_ok("life is fine") + call health#report_warn("no what installed", ["pip what", "make what"]) + call health#report_start("report 2") + call health#report_info("stuff is stable") + call health#report_error("why no hardcopy", [":h :hardcopy", ":h :TOhtml"]) +endfunction 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/fixtures/lua/test_plug/autoload/health/test_plug.vim b/test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim new file mode 100644 index 0000000000..de05f56e9e --- /dev/null +++ b/test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim @@ -0,0 +1,3 @@ +function! health#success1#check() + call health#report_start("If you see this I'm broken") +endfunction diff --git a/test/functional/fixtures/lua/test_plug/health/init.lua b/test/functional/fixtures/lua/test_plug/health/init.lua new file mode 100644 index 0000000000..d07632cff4 --- /dev/null +++ b/test/functional/fixtures/lua/test_plug/health/init.lua @@ -0,0 +1,11 @@ +local M = {} +local health = require("health") + +M.check = function() + health.report_start("report 1") + health.report_ok("everything is fine") + health.report_start("report 2") + health.report_ok("nothing to see here") +end + +return M diff --git a/test/functional/fixtures/lua/test_plug/submodule/health.lua b/test/functional/fixtures/lua/test_plug/submodule/health.lua new file mode 100644 index 0000000000..d07632cff4 --- /dev/null +++ b/test/functional/fixtures/lua/test_plug/submodule/health.lua @@ -0,0 +1,11 @@ +local M = {} +local health = require("health") + +M.check = function() + health.report_start("report 1") + health.report_ok("everything is fine") + health.report_start("report 2") + health.report_ok("nothing to see here") +end + +return M diff --git a/test/functional/fixtures/lua/test_plug/submodule_failed/health.lua b/test/functional/fixtures/lua/test_plug/submodule_failed/health.lua new file mode 100644 index 0000000000..3a8af6ebb2 --- /dev/null +++ b/test/functional/fixtures/lua/test_plug/submodule_failed/health.lua @@ -0,0 +1,12 @@ +local M = {} +local health = require("health") + +M.check = function() + health.report_start("report 1") + health.report_ok("everything is fine") + health.report_warn("About to add a number to nil") + local a = nil + 2 + return a +end + +return M 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..a08c8d8681 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1013,6 +1013,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/vim_spec.lua b/test/functional/lua/vim_spec.lua index a066cfbc10..8651a38025 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -237,29 +237,34 @@ describe('lua stdlib', function() end) it("vim.split", function() - local split = function(str, sep, plain) - return exec_lua('return vim.split(...)', str, sep, plain) + local split = function(str, sep, kwargs) + return exec_lua('return vim.split(...)', str, sep, kwargs) end local tests = { - { "a,b", ",", false, { 'a', 'b' } }, - { ":aa::bb:", ":", false, { '', 'aa', '', 'bb', '' } }, - { "::ee::ff:", ":", false, { '', '', 'ee', '', 'ff', '' } }, - { "ab", ".", false, { '', '', '' } }, - { "a1b2c", "[0-9]", false, { 'a', 'b', 'c' } }, - { "xy", "", false, { 'x', 'y' } }, - { "here be dragons", " ", false, { "here", "be", "dragons"} }, - { "axaby", "ab?", false, { '', 'x', 'y' } }, - { "f v2v v3v w2w ", "([vw])2%1", false, { 'f ', ' v3v ', ' ' } }, - { "", "", false, {} }, - { "", "a", false, { '' } }, - { "x*yz*oo*l", "*", true, { 'x', 'yz', 'oo', 'l' } }, + { "a,b", ",", false, false, { 'a', 'b' } }, + { ":aa::bb:", ":", false, false, { '', 'aa', '', 'bb', '' } }, + { ":aa::bb:", ":", false, true, { 'aa', '', 'bb' } }, + { "::ee::ff:", ":", false, false, { '', '', 'ee', '', 'ff', '' } }, + { "::ee::ff:", ":", false, true, { 'ee', '', 'ff' } }, + { "ab", ".", false, false, { '', '', '' } }, + { "a1b2c", "[0-9]", false, false, { 'a', 'b', 'c' } }, + { "xy", "", false, false, { 'x', 'y' } }, + { "here be dragons", " ", false, false, { "here", "be", "dragons"} }, + { "axaby", "ab?", false, false, { '', 'x', 'y' } }, + { "f v2v v3v w2w ", "([vw])2%1", false, false, { 'f ', ' v3v ', ' ' } }, + { "", "", false, false, {} }, + { "", "a", false, false, { '' } }, + { "x*yz*oo*l", "*", true, false, { 'x', 'yz', 'oo', 'l' } }, } for _, t in ipairs(tests) do - eq(t[4], split(t[1], t[2], t[3])) + eq(t[5], split(t[1], t[2], {plain=t[3], trimempty=t[4]})) end + -- Test old signature + eq({'x', 'yz', 'oo', 'l'}, split("x*yz*oo*l", "*", true)) + local loops = { { "abc", ".-" }, } @@ -283,9 +288,8 @@ describe('lua stdlib', function() vim/shared.lua:0: in function <vim/shared.lua:0>]]), pcall_err(split, 'string', 1)) eq(dedent([[ - Error executing lua: vim/shared.lua:0: plain: expected boolean, got number + Error executing lua: vim/shared.lua:0: kwargs: expected table, got number stack traceback: - vim/shared.lua:0: in function 'gsplit' vim/shared.lua:0: in function <vim/shared.lua:0>]]), pcall_err(split, 'string', 'string', 1)) end) diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 85c67be8f9..45fcf945f4 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local global_helpers = require('test.helpers') local Screen = require('test.functional.ui.screen') local clear = helpers.clear @@ -35,6 +36,7 @@ describe(':checkhealth', function() clear() eq('nvim', getcompletion('nvim', 'checkhealth')[1]) eq('provider', getcompletion('prov', 'checkhealth')[1]) + eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) end) end) @@ -48,42 +50,34 @@ describe('health.vim', function() command("set runtimepath+=test/functional/fixtures") end) - it("health#report_*()", function() - helpers.source([[ - let g:health_report = execute([ - \ "call health#report_start('Check Bar')", - \ "call health#report_ok('Bar status')", - \ "call health#report_ok('Other Bar status')", - \ "call health#report_warn('Zub')", - \ "call health#report_start('Baz')", - \ "call health#report_warn('Zim', ['suggestion 1', 'suggestion 2'])" - \ ]) - ]]) - local result = helpers.eval("g:health_report") - - helpers.eq(helpers.dedent([[ - - - ## Check Bar - - OK: Bar status - - OK: Other Bar status - - WARNING: Zub - - ## Baz - - WARNING: Zim + describe(":checkhealth", function() + it("functions health#report_*() render correctly", function() + command("checkhealth full_render") + helpers.expect([[ + + full_render: health#full_render#check + ======================================================================== + ## report 1 + - OK: life is fine + - WARNING: no what installed - ADVICE: - - suggestion 1 - - suggestion 2]]), - result) - end) + - pip what + - make what + ## report 2 + - INFO: stuff is stable + - ERROR: why no hardcopy + - ADVICE: + - :help |:hardcopy| + - :help |:TOhtml| + ]]) + end) - describe(":checkhealth", function() it("concatenates multiple reports", function() - command("checkhealth success1 success2") + command("checkhealth success1 success2 test_plug") helpers.expect([[ - health#success1#check + success1: health#success1#check ======================================================================== ## report 1 - OK: everything is fine @@ -91,25 +85,111 @@ describe('health.vim', function() ## report 2 - OK: nothing to see here - health#success2#check + success2: health#success2#check ======================================================================== ## another 1 - OK: ok + + test_plug: require("test_plug.health").check() + ======================================================================== + ## report 1 + - OK: everything is fine + + ## report 2 + - OK: nothing to see here + ]]) + end) + + it("lua plugins, skips vimscript healthchecks with the same name", function() + command("checkhealth test_plug") + -- Existing file in test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim + -- and the Lua healthcheck is used instead. + helpers.expect([[ + + test_plug: require("test_plug.health").check() + ======================================================================== + ## report 1 + - OK: everything is fine + + ## report 2 + - OK: nothing to see here ]]) end) + it("lua plugins submodules", function() + command("checkhealth test_plug.submodule") + helpers.expect([[ + + test_plug.submodule: require("test_plug.submodule.health").check() + ======================================================================== + ## report 1 + - OK: everything is fine + + ## report 2 + - OK: nothing to see here + ]]) + end) + + it("lua plugins submodules with expression '*'", function() + command("checkhealth test_plug*") + local buf_lines = helpers.curbuf('get_lines', 0, -1, true) + -- avoid dealing with path separators + local received = table.concat(buf_lines, '\n', 1, #buf_lines - 2) + local expected = helpers.dedent([[ + + test_plug: require("test_plug.health").check() + ======================================================================== + ## report 1 + - OK: everything is fine + + ## report 2 + - OK: nothing to see here + + test_plug.submodule: require("test_plug.submodule.health").check() + ======================================================================== + ## report 1 + - OK: everything is fine + + ## report 2 + - OK: nothing to see here + + test_plug.submodule_failed: require("test_plug.submodule_failed.health").check() + ======================================================================== + - ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: + function health#check, line 24]]) + eq(expected, received) + end) + it("gracefully handles broken healthcheck", function() command("checkhealth broken") helpers.expect([[ - health#broken#check + broken: health#broken#check ======================================================================== - ERROR: Failed to run healthcheck for "broken" plugin. Exception: - function health#check[21]..health#broken#check, line 1 + function health#check[24]..health#broken#check, line 1 caused an error ]]) end) + it("gracefully handles broken lua healthcheck", function() + command("checkhealth test_plug.submodule_failed") + local buf_lines = helpers.curbuf('get_lines', 0, -1, true) + local received = table.concat(buf_lines, '\n', 1, #buf_lines - 2) + -- avoid dealing with path separators + local lua_err = "attempt to perform arithmetic on a nil value" + local last_line = buf_lines[#buf_lines - 1] + assert(string.find(last_line, lua_err) ~= nil, "Lua error not present") + + local expected = global_helpers.dedent([[ + + test_plug.submodule_failed: require("test_plug.submodule_failed.health").check() + ======================================================================== + - ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: + function health#check, line 24]]) + eq(expected, received) + end) + it("highlights OK, ERROR", function() local screen = Screen.new(72, 10) screen:attach() @@ -126,11 +206,11 @@ describe('health.vim', function() command("set laststatus=0") screen:expect{grid=[[ ^ | - {Heading:health#foo#check} | + {Heading:foo: } | {Bar:========================================================================}| {Bullet: -} {Error:ERROR:} No healthcheck found for "foo" plugin. | | - {Heading:health#success1#check} | + {Heading:success1: health#success1#check} | {Bar:========================================================================}| {Heading2:##}{Heading: report 1} | {Bullet: -} {Ok:OK:} everything is fine | @@ -140,9 +220,10 @@ describe('health.vim', function() it("gracefully handles invalid healthcheck", function() command("checkhealth non_existent_healthcheck") + -- luacheck: ignore 613 helpers.expect([[ - health#non_existent_healthcheck#check + non_existent_healthcheck: ======================================================================== - ERROR: No healthcheck found for "non_existent_healthcheck" plugin. ]]) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 8f9b194690..026e6815dc 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -480,6 +480,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/ui/float_spec.lua b/test/functional/ui/float_spec.lua index e57c63bb0f..6c2c4b398a 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -46,6 +46,7 @@ describe('float window', function() [24] = {foreground = Screen.colors.Black, background = Screen.colors.Grey80}; [25] = {blend = 100, background = Screen.colors.Gray0}; [26] = {blend = 80, background = Screen.colors.Gray0}; + [27] = {background = Screen.colors.LightGray}; } it('behavior', function() @@ -6174,6 +6175,132 @@ describe('float window', function() end) end) + it("left drag changes visual selection in float window", function() + local buf = meths.create_buf(false,false) + meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar'}) + meths.open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=5}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {1:foo }| + {1:bar }| + {2:~ }| + ]], float_pos={ + [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2}; + }} + meths.input_mouse('left', 'press', '', 5, 0, 0) + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {1:^foo }| + {1:bar }| + {2:~ }| + ]], float_pos={ + [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2}; + }} + meths.input_mouse('left', 'drag', '', 5, 1, 2) + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {3:-- VISUAL --} | + ## grid 5 + {27:foo}{1: }| + {27:ba}{1:^r }| + {2:~ }| + ]], float_pos={ + [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 2}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }{1:foo }{0: }| + {0:~ }{1:bar }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + | + ]]} + + meths.input_mouse('left', 'press', '', 0, 2, 5) + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }{1:^foo }{0: }| + {0:~ }{1:bar }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + | + ]]} + + meths.input_mouse('left', 'drag', '', 0, 3, 7) + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }{27:foo}{1: }{0: }| + {0:~ }{27:ba}{1:^r }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + {3:-- VISUAL --} | + ]]} + end + end) + it("'winblend' option", function() screen:try_resize(50,9) screen:set_default_attr_ids({ diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index d3fe38ef52..baacef358f 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -585,6 +585,69 @@ describe('ui/mouse/input', function() ]]) end) + it('left drag changes visual selection in split layout', function() + screen:try_resize(53,14) + command('set mouse=a') + command('vsplit') + command('wincmd l') + command('below split') + command('enew') + feed('ifoo\nbar<esc>') + + screen:expect{grid=[[ + testing {4:│}testing | + mouse {4:│}mouse | + support and selection {4:│}support and selection | + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│[No Name] [+] }| + {0:~ }{4:│}foo{0:$} | + {0:~ }{4:│}ba^r{0:$} | + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {4:[No Name] [+] }{5:[No Name] [+] }| + | + ]]} + + meths.input_mouse('left', 'press', '', 0, 6, 27) + screen:expect{grid=[[ + testing {4:│}testing | + mouse {4:│}mouse | + support and selection {4:│}support and selection | + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│[No Name] [+] }| + {0:~ }{4:│}^foo{0:$} | + {0:~ }{4:│}bar{0:$} | + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {4:[No Name] [+] }{5:[No Name] [+] }| + | + ]]} + meths.input_mouse('left', 'drag', '', 0, 7, 30) + + screen:expect{grid=[[ + testing {4:│}testing | + mouse {4:│}mouse | + support and selection {4:│}support and selection | + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│[No Name] [+] }| + {0:~ }{4:│}{1:foo}{3:$} | + {0:~ }{4:│}{1:bar}{0:^$} | + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {0:~ }{4:│}{0:~ }| + {4:[No Name] [+] }{5:[No Name] [+] }| + {2:-- VISUAL --} | + ]]} + end) + it('two clicks will select the word and enter VISUAL', function() feed('<LeftMouse><2,2><LeftMouse><2,2>') screen:expect([[ |