From 1037ce2e461034a20e35ad59969fd05d5ad68b91 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Dec 2023 20:42:00 +0800 Subject: test: avoid repeated screen lines in expected states This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 175 +++------------------ test/functional/plugin/man_spec.lua | 15 +- 2 files changed, 31 insertions(+), 159 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index b7ac53f270..b95d435c2b 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -125,9 +125,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } end) @@ -164,9 +162,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } @@ -199,9 +195,7 @@ describe('semantic token highlighting', function() #endif | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } end) @@ -234,9 +228,7 @@ describe('semantic token highlighting', function() #endif | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } @@ -257,9 +249,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } end) @@ -286,9 +276,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } @@ -309,9 +297,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]], unchanged = true } @@ -365,9 +351,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } feed_command('%s/int x/int x()/') @@ -383,11 +367,8 @@ describe('semantic token highlighting', function() {6:#else} | {6: printf("%d\n", x);} | {6:#endif} | - } | - } | - {1:~ }| - {1:~ }| - {1:~ }| + } |*2 + {1:~ }|*3 :noh | ]] } end) @@ -447,9 +428,7 @@ describe('semantic token highlighting', function() #endif | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } @@ -474,9 +453,7 @@ describe('semantic token highlighting', function() #endif | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]], unchanged = true } end) @@ -520,9 +497,7 @@ describe('semantic token highlighting', function() #endif | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } end) @@ -565,9 +540,7 @@ describe('semantic token highlighting', function() {6:#endif} | } | ^} | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]] } feed_command('%s/int x/int x()/') @@ -587,11 +560,8 @@ describe('semantic token highlighting', function() {6:#else} | {6: printf("%d\n", x);} | {6:#endif} | - } | - } | - {1:~ }| - {1:~ }| - {1:~ }| + } |*2 + {1:~ }|*3 :noh | ]] } local messages = exec_lua('return server2.messages') @@ -633,20 +603,7 @@ describe('semantic token highlighting', function() expected_screen = function() screen:expect{grid=[[ char* {7:foo} = "\n"^; | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*14 | ]]} end, @@ -774,11 +731,7 @@ int main() {6: comment} | {6: #endif} | ^} | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]} end, @@ -828,18 +781,7 @@ b = "as"]], {6:-- comment} | local {7:a} = 1 | {2:b} = "as^" | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*12 | ]]} end, @@ -960,16 +902,7 @@ b = "as"]], //{6:/ what?} | } | ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*10 | ]]} end, @@ -1055,20 +988,7 @@ b = "as"]], expected_screen1 = function() screen:expect{grid=[[ char* {7:foo} = "\n"^; | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*14 | ]]} end, @@ -1076,19 +996,7 @@ b = "as"]], screen:expect{grid=[[ ^ | char* {7:foo} = "\n"; | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*13 | ]]} end, @@ -1304,10 +1212,7 @@ int main() {6: printf("%d\n", x);} | {6:#endif} | ^} | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*4 | ]]} end, @@ -1325,9 +1230,7 @@ int main() {6: printf("%d\n", x);} | {6:^#endif} | } | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]]} end, @@ -1363,40 +1266,14 @@ int main() expected_screen1 = function() screen:expect{grid=[[ {7:string} = "test^" | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*14 | ]]} end, expected_screen2 = function() screen:expect{grid=[[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*14 | ]]} end, diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 815ddbc523..f16fca51f9 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -71,8 +71,7 @@ describe(':Man', function() screen:expect{grid=[[ this i{c:^H}is{c:^H}s a{c:^H}a test | with _{c:^H}o_{c:^H}v_{c:^H}e_{c:^H}r_{c:^H}s_{c:^H}t_{c:^H}r_{c:^H}u_{c:^H}c_{c:^H}k tex^t | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]} @@ -81,8 +80,7 @@ describe(':Man', function() screen:expect([[ ^this {b:is} {b:a} test | with {i:overstruck} text | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]) end) @@ -95,8 +93,7 @@ describe(':Man', function() screen:expect{grid=[=[ this {c:^[}[1mis {c:^[}[3ma {c:^[}[4mtest{c:^[}[0m | {c:^[}[4mwith{c:^[}[24m {c:^[}[4mescaped{c:^[}[24m {c:^[}[4mtext{c:^[}[24^m | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]=]} @@ -105,8 +102,7 @@ describe(':Man', function() screen:expect([[ ^this {b:is }{bi:a }{biu:test} | {u:with} {u:escaped} {u:text} | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]) end) @@ -120,8 +116,7 @@ describe(':Man', function() screen:expect([[ ^this {b:is} {b:あ} test | with {i:överstrũck} te{i:xt¶} | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]) end) -- cgit From 92204b06e7365cf4c68e6ea8258dce801f0a5df9 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Fri, 22 Dec 2023 02:40:01 -0800 Subject: refactor(lsp): move glob parsing to util (#26519) refactor(lsp): move glob parsing to vim.glob Moving the logic for using vim.lpeg to create a match pattern from a glob into `vim.glob`. There are several places in the LSP spec that use globs, and it's very useful to have glob matching as a generally-available utility. --- test/functional/plugin/lsp/watchfiles_spec.lua | 222 ------------------------- 1 file changed, 222 deletions(-) delete mode 100644 test/functional/plugin/lsp/watchfiles_spec.lua (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/watchfiles_spec.lua b/test/functional/plugin/lsp/watchfiles_spec.lua deleted file mode 100644 index a8260e0c98..0000000000 --- a/test/functional/plugin/lsp/watchfiles_spec.lua +++ /dev/null @@ -1,222 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local exec_lua = helpers.exec_lua - -describe('vim.lsp._watchfiles', function() - before_each(helpers.clear) - after_each(helpers.clear) - - local match = function(...) - return exec_lua('return require("vim.lsp._watchfiles")._match(...)', ...) - end - - describe('glob matching', function() - it('should match literal strings', function() - eq(true, match('', '')) - eq(false, match('', 'a')) - eq(true, match('a', 'a')) - eq(true, match('/', '/')) - eq(true, match('abc', 'abc')) - eq(false, match('abc', 'abcdef')) - eq(false, match('abc', 'a')) - eq(false, match('abc', 'bc')) - eq(false, match('a', 'b')) - eq(false, match('.', 'a')) - eq(true, match('$', '$')) - eq(true, match('/dir', '/dir')) - eq(true, match('dir/', 'dir/')) - eq(true, match('dir/subdir', 'dir/subdir')) - eq(false, match('dir/subdir', 'subdir')) - eq(false, match('dir/subdir', 'dir/subdir/file')) - eq(true, match('🤠', '🤠')) - end) - - it('should match * wildcards', function() - eq(false, match('*', '')) - eq(true, match('*', 'a')) - eq(false, match('*', '/')) - eq(false, match('*', '/a')) - eq(false, match('*', 'a/')) - eq(true, match('*', 'aaa')) - eq(true, match('*a', 'aa')) - eq(true, match('*a', 'abca')) - eq(true, match('*.txt', 'file.txt')) - eq(false, match('*.txt', 'file.txtxt')) - eq(false, match('*.txt', 'dir/file.txt')) - eq(false, match('*.txt', '/dir/file.txt')) - eq(false, match('*.txt', 'C:/dir/file.txt')) - eq(false, match('*.dir', 'test.dir/file')) - eq(true, match('file.*', 'file.txt')) - eq(false, match('file.*', 'not-file.txt')) - eq(true, match('*/file.txt', 'dir/file.txt')) - eq(false, match('*/file.txt', 'dir/subdir/file.txt')) - eq(false, match('*/file.txt', '/dir/file.txt')) - eq(true, match('dir/*', 'dir/file.txt')) - eq(false, match('dir/*', 'dir')) - eq(false, match('dir/*.txt', 'file.txt')) - eq(true, match('dir/*.txt', 'dir/file.txt')) - eq(false, match('dir/*.txt', 'dir/subdir/file.txt')) - eq(false, match('dir/*/file.txt', 'dir/file.txt')) - eq(true, match('dir/*/file.txt', 'dir/subdir/file.txt')) - eq(false, match('dir/*/file.txt', 'dir/subdir/subdir/file.txt')) - - -- TODO: The spec does not describe this, but VSCode only interprets ** when it's by - -- itself in a path segment, and otherwise interprets ** as consecutive * directives. - -- The following tests show how this behavior should work, but is not yet fully implemented. - -- Currently, "a**" parses incorrectly as "a" "**" and "**a" parses correctly as "*" "*" "a". - -- see: https://github.com/microsoft/vscode/blob/eef30e7165e19b33daa1e15e92fa34ff4a5df0d3/src/vs/base/common/glob.ts#L112 - eq(true, match('a**', 'abc')) -- '**' should parse as two '*'s when not by itself in a path segment - eq(true, match('**c', 'abc')) - -- eq(false, match('a**', 'ab')) -- each '*' should still represent at least one character - eq(false, match('**c', 'bc')) - eq(true, match('a**', 'abcd')) - eq(true, match('**d', 'abcd')) - -- eq(false, match('a**', 'abc/d')) - eq(false, match('**d', 'abc/d')) - end) - - it('should match ? wildcards', function() - eq(false, match('?', '')) - eq(true, match('?', 'a')) - eq(false, match('??', 'a')) - eq(false, match('?', 'ab')) - eq(true, match('??', 'ab')) - eq(true, match('a?c', 'abc')) - eq(false, match('a?c', 'a/c')) - end) - - it('should match ** wildcards', function() - eq(true, match('**', '')) - eq(true, match('**', 'a')) - eq(true, match('**', '/')) - eq(true, match('**', 'a/')) - eq(true, match('**', '/a')) - eq(true, match('**', 'C:/a')) - eq(true, match('**', 'a/a')) - eq(true, match('**', 'a/a/a')) - eq(false, match('/**', '')) -- /** matches leading / literally - eq(true, match('/**', '/')) - eq(true, match('/**', '/a/b/c')) - eq(true, match('**/', '')) -- **/ absorbs trailing / - eq(true, match('**/', '/a/b/c')) - eq(true, match('**/**', '')) - eq(true, match('**/**', 'a')) - eq(false, match('a/**', '')) - eq(false, match('a/**', 'a')) - eq(true, match('a/**', 'a/b')) - eq(true, match('a/**', 'a/b/c')) - eq(false, match('a/**', 'b/a')) - eq(false, match('a/**', '/a')) - eq(false, match('**/a', '')) - eq(true, match('**/a', 'a')) - eq(false, match('**/a', 'a/b')) - eq(true, match('**/a', '/a')) - eq(true, match('**/a', '/b/a')) - eq(true, match('**/a', '/c/b/a')) - eq(true, match('**/a', '/a/a')) - eq(true, match('**/a', '/abc/a')) - eq(false, match('a/**/c', 'a')) - eq(false, match('a/**/c', 'c')) - eq(true, match('a/**/c', 'a/c')) - eq(true, match('a/**/c', 'a/b/c')) - eq(true, match('a/**/c', 'a/b/b/c')) - eq(false, match('**/a/**', 'a')) - eq(true, match('**/a/**', 'a/')) - eq(false, match('**/a/**', '/dir/a')) - eq(false, match('**/a/**', 'dir/a')) - eq(true, match('**/a/**', 'dir/a/')) - eq(true, match('**/a/**', 'a/dir')) - eq(true, match('**/a/**', 'dir/a/dir')) - eq(true, match('**/a/**', '/a/dir')) - eq(true, match('**/a/**', 'C:/a/dir')) - eq(false, match('**/a/**', 'a.txt')) - end) - - it('should match {} groups', function() - eq(true, match('{}', '')) - eq(false, match('{}', 'a')) - eq(true, match('a{}', 'a')) - eq(true, match('{}a', 'a')) - eq(true, match('{,}', '')) - eq(true, match('{a,}', '')) - eq(true, match('{a,}', 'a')) - eq(true, match('{a}', 'a')) - eq(false, match('{a}', 'aa')) - eq(false, match('{a}', 'ab')) - eq(true, match('{a?c}', 'abc')) - eq(false, match('{ab}', 'a')) - eq(false, match('{ab}', 'b')) - eq(true, match('{ab}', 'ab')) - eq(true, match('{a,b}', 'a')) - eq(true, match('{a,b}', 'b')) - eq(false, match('{a,b}', 'ab')) - eq(true, match('{ab,cd}', 'ab')) - eq(false, match('{ab,cd}', 'a')) - eq(true, match('{ab,cd}', 'cd')) - eq(true, match('{a,b,c}', 'c')) - eq(true, match('{a,{b,c}}', 'c')) - end) - - it('should match [] groups', function() - eq(true, match('[]', '[]')) -- empty [] is a literal - eq(false, match('[a-z]', '')) - eq(true, match('[a-z]', 'a')) - eq(false, match('[a-z]', 'ab')) - eq(true, match('[a-z]', 'z')) - eq(true, match('[a-z]', 'j')) - eq(false, match('[a-f]', 'j')) - eq(false, match('[a-z]', '`')) -- 'a' - 1 - eq(false, match('[a-z]', '{')) -- 'z' + 1 - eq(false, match('[a-z]', 'A')) - eq(false, match('[a-z]', '5')) - eq(true, match('[A-Z]', 'A')) - eq(true, match('[A-Z]', 'Z')) - eq(true, match('[A-Z]', 'J')) - eq(false, match('[A-Z]', '@')) -- 'A' - 1 - eq(false, match('[A-Z]', '[')) -- 'Z' + 1 - eq(false, match('[A-Z]', 'a')) - eq(false, match('[A-Z]', '5')) - eq(true, match('[a-zA-Z0-9]', 'z')) - eq(true, match('[a-zA-Z0-9]', 'Z')) - eq(true, match('[a-zA-Z0-9]', '9')) - eq(false, match('[a-zA-Z0-9]', '&')) - end) - - it('should match [!...] groups', function() - eq(true, match('[!]', '[!]')) -- [!] is a literal - eq(false, match('[!a-z]', '')) - eq(false, match('[!a-z]', 'a')) - eq(false, match('[!a-z]', 'z')) - eq(false, match('[!a-z]', 'j')) - eq(true, match('[!a-f]', 'j')) - eq(false, match('[!a-f]', 'jj')) - eq(true, match('[!a-z]', '`')) -- 'a' - 1 - eq(true, match('[!a-z]', '{')) -- 'z' + 1 - eq(false, match('[!a-zA-Z0-9]', 'a')) - eq(false, match('[!a-zA-Z0-9]', 'A')) - eq(false, match('[!a-zA-Z0-9]', '0')) - eq(true, match('[!a-zA-Z0-9]', '!')) - end) - - it('should match complex patterns', function() - eq(false, match('**/*.{c,h}', '')) - eq(false, match('**/*.{c,h}', 'c')) - eq(false, match('**/*.{c,h}', 'file.m')) - eq(true, match('**/*.{c,h}', 'file.c')) - eq(true, match('**/*.{c,h}', 'file.h')) - eq(true, match('**/*.{c,h}', '/file.c')) - eq(true, match('**/*.{c,h}', 'dir/subdir/file.c')) - eq(true, match('**/*.{c,h}', 'dir/subdir/file.h')) - eq(true, match('**/*.{c,h}', '/dir/subdir/file.c')) - eq(true, match('**/*.{c,h}', 'C:/dir/subdir/file.c')) - eq(true, match('/dir/**/*.{c,h}', '/dir/file.c')) - eq(false, match('/dir/**/*.{c,h}', 'dir/file.c')) - eq(true, match('/dir/**/*.{c,h}', '/dir/subdir/subdir/file.c')) - - eq(true, match('{[0-9],[a-z]}', '0')) - eq(true, match('{[0-9],[a-z]}', 'a')) - eq(false, match('{[0-9],[a-z]}', 'A')) - end) - end) -end) -- cgit From 031088fc0afffe4af6fa90d68d5b93ca09992ef1 Mon Sep 17 00:00:00 2001 From: Michal Liszcz Date: Fri, 22 Dec 2023 15:03:13 +0100 Subject: fix(lsp): filetype matching to documentSelector in dynamic capabilities (#25425) Use the get_language_id client option to resolve the filetype when matching the document selector in a dynamic capability. Co-authored-by: Mathias Fussenegger --- test/functional/plugin/lsp_spec.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 56d31a0e44..0026a7caa7 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3936,12 +3936,15 @@ describe('LSP', function() describe('#dynamic vim.lsp._dynamic', function() it('supports dynamic registration', function() + ---@type string local root_dir = helpers.tmpname() os.remove(root_dir) mkdir(root_dir) local tmpfile = root_dir .. '/dynamic.foo' local file = io.open(tmpfile, 'w') - file:close() + if file then + file:close() + end exec_lua(create_server_definition) local result = exec_lua([[ @@ -3952,6 +3955,9 @@ describe('LSP', function() name = 'dynamic-test', cmd = server.cmd, root_dir = root_dir, + get_language_id = function() + return "dummy-lang" + end, capabilities = { textDocument = { formatting = { @@ -3985,6 +3991,13 @@ describe('LSP', function() { id = 'range-formatting', method = 'textDocument/rangeFormatting', + registerOptions = { + documentSelector = { + { + language = "dummy-lang" + }, + } + } }, }, }, { client_id = client_id }) @@ -4002,7 +4015,11 @@ describe('LSP', function() local function check(method, fname) local bufnr = fname and vim.fn.bufadd(fname) or nil local client = vim.lsp.get_client_by_id(client_id) - result[#result + 1] = {method = method, fname = fname, supported = client.supports_method(method, {bufnr = bufnr})} + result[#result + 1] = { + method = method, + fname = fname, + supported = client.supports_method(method, {bufnr = bufnr}) + } end -- cgit From 2ff2785c396e66c285fecf5b151d8f8863f9d4e6 Mon Sep 17 00:00:00 2001 From: Pablo Arias Date: Mon, 25 Dec 2023 01:30:56 +0100 Subject: feat(health): checkhealth buffer can show in a split window (#26714) :checkhealth now respects :vertical and :horizontal. For example: :vertical checkhealth foo bar will open the healthcheck buffer in a vertical split. --- test/functional/plugin/health_spec.lua | 190 +++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 50b1d03f36..7f23c3e7db 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -6,6 +6,9 @@ local curbuf_contents = helpers.curbuf_contents local command = helpers.command local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches local getcompletion = helpers.funcs.getcompletion +local feed = helpers.feed +local source = helpers.source +local exec_lua = helpers.exec_lua describe(':checkhealth', function() it("detects invalid $VIMRUNTIME", function() @@ -200,3 +203,190 @@ describe(':checkhealth provider', function() eq(nil, string.match(curbuf_contents(), 'WRONG!!!')) end) end) + +describe(':checkhealth window', function() + before_each(function() + clear{args={'-u', 'NORC'}} + -- Provides healthcheck functions + command("set runtimepath+=test/functional/fixtures") + command("set nofoldenable nowrap laststatus=0") + end) + + it("opens directly if no buffer created", function() + local screen = Screen.new(50, 12) + screen:attach({ext_multigrid=true}) + command("checkhealth success1") + screen:expect{grid=[[ + ## grid 1 + [2:--------------------------------------------------]|*11 + [3:--------------------------------------------------]| + ## grid 2 + ^ | + ──────────────────────────────────────────────────| + ──────────────────────────── | + test_plug.success1: require("test_plug.success1. | + health").check() | + | + report 1 | + - OK everything is fine | + | + report 2 | + - OK nothing to see here | + ## grid 3 + | + ]]} + end) + + it("opens in vsplit window when no buffer created", function() + local screen = Screen.new(50, 20) + screen:attach({ext_multigrid=true}) + command("vertical checkhealth success1") + screen:expect{grid=[[ + ## grid 1 + [4:-------------------------]│[2:------------------------]|*19 + [3:--------------------------------------------------]| + ## grid 2 + | + ~ |*18 + ## grid 3 + | + ## grid 4 + ^ | + ─────────────────────────|*3 + ─── | + test_plug.success1: | + require("test_plug. | + success1.health").check()| + | + report 1 | + - OK everything is fine | + | + report 2 | + - OK nothing to see here | + | + ~ |*4 + ]]} + end) + + it("opens in split window when no buffer created", function() + local screen = Screen.new(50, 25) + screen:attach({ext_multigrid=true}) + command("horizontal checkhealth success1") + screen:expect{grid=[[ + ## grid 1 + [4:--------------------------------------------------]|*12 + health:// | + [2:--------------------------------------------------]|*11 + [3:--------------------------------------------------]| + ## grid 2 + | + ~ |*10 + ## grid 3 + | + ## grid 4 + ^ | + ──────────────────────────────────────────────────| + ──────────────────────────── | + test_plug.success1: require("test_plug.success1. | + health").check() | + | + report 1 | + - OK everything is fine | + | + report 2 | + - OK nothing to see here | + | + ]]} + end) + + it("opens in split window", function() + local screen = Screen.new(50, 25) + screen:attach({ext_multigrid=true}) + feed('ihello') + feed('') + command("horizontal checkhealth success1") + screen:expect{grid=[[ + ## grid 1 + [4:--------------------------------------------------]|*12 + health:// | + [2:--------------------------------------------------]|*11 + [3:--------------------------------------------------]| + ## grid 2 + hello | + ~ |*10 + ## grid 3 + | + ## grid 4 + ^ | + ──────────────────────────────────────────────────| + ──────────────────────────── | + test_plug.success1: require("test_plug.success1. | + health").check() | + | + report 1 | + - OK everything is fine | + | + report 2 | + - OK nothing to see here | + | + ]]} + end) + + it("opens in vsplit window", function() + local screen = Screen.new(50, 25) + screen:attach({ext_multigrid=true}) + feed('ihello') + feed('') + command("vertical checkhealth success1") + screen:expect{grid=[[ + ## grid 1 + [4:-------------------------]│[2:------------------------]|*24 + [3:--------------------------------------------------]| + ## grid 2 + hello | + ~ |*23 + ## grid 3 + | + ## grid 4 + ^ | + ─────────────────────────|*3 + ─── | + test_plug.success1: | + require("test_plug. | + success1.health").check()| + | + report 1 | + - OK everything is fine | + | + report 2 | + - OK nothing to see here | + | + ~ |*9 + ]]} + end) + + it("opens in tab", function() + -- create an empty buffer called "my_buff" + exec_lua 'vim.api.nvim_create_buf(false, true)' + command('file my_buff') + command("checkhealth success1") + -- define a function that collects all buffers in each tab + -- returns a dictionary like {tab1 = ["buf1", "buf2"], tab2 = ["buf3"]} + source([[ + function CollectBuffersPerTab() + let buffs = {} + for i in range(tabpagenr('$')) + let key = 'tab' . (i + 1) + let value = [] + for j in tabpagebuflist(i + 1) + call add(value, bufname(j)) + endfor + let buffs[key] = value + endfor + return buffs + endfunction + ]]) + local buffers_per_tab = exec_lua("return vim.fn.CollectBuffersPerTab()") + eq(buffers_per_tab, {tab1 = { "my_buff" }, tab2 = {"health://"}}) + end) +end) -- cgit From 2877672d70e76f71ae1190090b8aea7044d458be Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Dec 2023 10:21:13 +0800 Subject: feat(health): make :checkhealth support more split modifiers (#26731) --- test/functional/plugin/health_spec.lua | 147 +++++++++++++++------------------ 1 file changed, 68 insertions(+), 79 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 7f23c3e7db..9120655724 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -6,7 +6,7 @@ local curbuf_contents = helpers.curbuf_contents local command = helpers.command local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches local getcompletion = helpers.funcs.getcompletion -local feed = helpers.feed +local insert = helpers.insert local source = helpers.source local exec_lua = helpers.exec_lua @@ -237,16 +237,19 @@ describe(':checkhealth window', function() ]]} end) - it("opens in vsplit window when no buffer created", function() + local function test_health_vsplit(left, emptybuf, mods) local screen = Screen.new(50, 20) screen:attach({ext_multigrid=true}) - command("vertical checkhealth success1") - screen:expect{grid=[[ + if not emptybuf then + insert('hello') + end + command(mods .. ' checkhealth success1') + screen:expect(([[ ## grid 1 - [4:-------------------------]│[2:------------------------]|*19 + %s [3:--------------------------------------------------]| ## grid 2 - | + %s | ~ |*18 ## grid 3 | @@ -265,21 +268,44 @@ describe(':checkhealth window', function() - OK nothing to see here | | ~ |*4 - ]]} - end) + ]]):format(left + and '[4:-------------------------]│[2:------------------------]|*19' + or '[2:------------------------]│[4:-------------------------]|*19', + emptybuf and ' ' or 'hello') + ) + end + + for _, mods in ipairs({ 'vertical', 'leftabove vertical', 'topleft vertical' }) do + it(('opens in left vsplit window with :%s and no buffer created'):format(mods), function() + test_health_vsplit(true, true, mods) + end) + it(('opens in left vsplit window with :%s and non-empty buffer'):format(mods), function() + test_health_vsplit(true, false, mods) + end) + end - it("opens in split window when no buffer created", function() + for _, mods in ipairs({ 'rightbelow vertical', 'botright vertical' }) do + it(('opens in right vsplit window with :%s and no buffer created'):format(mods), function() + test_health_vsplit(false, true, mods) + end) + it(('opens in right vsplit window with :%s and non-empty buffer'):format(mods), function() + test_health_vsplit(false, false, mods) + end) + end + + local function test_health_split(top, emptybuf, mods) local screen = Screen.new(50, 25) screen:attach({ext_multigrid=true}) - command("horizontal checkhealth success1") - screen:expect{grid=[[ + if not emptybuf then + insert('hello') + end + command(mods .. ' checkhealth success1') + screen:expect(([[ ## grid 1 - [4:--------------------------------------------------]|*12 - health:// | - [2:--------------------------------------------------]|*11 +%s [3:--------------------------------------------------]| ## grid 2 - | + %s | ~ |*10 ## grid 3 | @@ -296,74 +322,37 @@ describe(':checkhealth window', function() report 2 | - OK nothing to see here | | - ]]} - end) - - it("opens in split window", function() - local screen = Screen.new(50, 25) - screen:attach({ext_multigrid=true}) - feed('ihello') - feed('') - command("horizontal checkhealth success1") - screen:expect{grid=[[ - ## grid 1 + ]]):format(top + and [[ [4:--------------------------------------------------]|*12 health:// | + [2:--------------------------------------------------]|*11]] + or ([[ [2:--------------------------------------------------]|*11 - [3:--------------------------------------------------]| - ## grid 2 - hello | - ~ |*10 - ## grid 3 - | - ## grid 4 - ^ | - ──────────────────────────────────────────────────| - ──────────────────────────── | - test_plug.success1: require("test_plug.success1. | - health").check() | - | - report 1 | - - OK everything is fine | - | - report 2 | - - OK nothing to see here | - | - ]]} - end) + [No Name] %s | + [4:--------------------------------------------------]|*12]] + ):format(emptybuf and ' ' or '[+]'), + emptybuf and ' ' or 'hello') + ) + end + + for _, mods in ipairs({ 'horizontal', 'leftabove', 'topleft' }) do + it(('opens in top split window with :%s and no buffer created'):format(mods), function() + test_health_split(true, true, mods) + end) + it(('opens in top split window with :%s and non-empty buffer'):format(mods), function() + test_health_split(true, false, mods) + end) + end - it("opens in vsplit window", function() - local screen = Screen.new(50, 25) - screen:attach({ext_multigrid=true}) - feed('ihello') - feed('') - command("vertical checkhealth success1") - screen:expect{grid=[[ - ## grid 1 - [4:-------------------------]│[2:------------------------]|*24 - [3:--------------------------------------------------]| - ## grid 2 - hello | - ~ |*23 - ## grid 3 - | - ## grid 4 - ^ | - ─────────────────────────|*3 - ─── | - test_plug.success1: | - require("test_plug. | - success1.health").check()| - | - report 1 | - - OK everything is fine | - | - report 2 | - - OK nothing to see here | - | - ~ |*9 - ]]} - end) + for _, mods in ipairs({ 'rightbelow', 'botright' }) do + it(('opens in bottom split window with :%s and no buffer created'):format(mods), function() + test_health_split(false, true, mods) + end) + it(('opens in bottom split window with :%s and non-empty buffer'):format(mods), function() + test_health_split(false, false, mods) + end) + end it("opens in tab", function() -- create an empty buffer called "my_buff" -- cgit From 164f1ea06d17e935f41e178e46bb05bbb676af20 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 10 Apr 2023 16:48:58 -0600 Subject: refactor(health): refactor provider healthchecks * Prefer pure Lua functions over vim.fn * Split up provider healthchecks into separate modules to help manage complexity --- test/functional/plugin/health_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 9120655724..5d32768260 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -36,7 +36,7 @@ describe(':checkhealth', function() it('completions can be listed via getcompletion()', function() clear() eq('nvim', getcompletion('nvim', 'checkhealth')[1]) - eq('provider', getcompletion('prov', 'checkhealth')[1]) + eq('provider.clipboard', getcompletion('prov', 'checkhealth')[1]) eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) neq('vim', getcompletion('^vim', 'checkhealth')[1]) -- should not complete vim.health end) -- cgit From 3f788e73b34521f093846d362bf51e68bc9a3827 Mon Sep 17 00:00:00 2001 From: TheLeoP <53507599+TheLeoP@users.noreply.github.com> Date: Tue, 2 Jan 2024 04:08:36 -0500 Subject: feat(lsp): support connect via named pipes/unix domain sockets (#26032) Closes https://github.com/neovim/neovim/issues/26031 Co-authored-by: Mathias Fussenegger --- test/functional/plugin/lsp_spec.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 0026a7caa7..a6b3835dbc 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3861,6 +3861,39 @@ describe('LSP', function() ]] eq(result.method, "initialize") end) + it('can connect to lsp server via rpc.domain_socket_connect', function() + local tmpfile + if is_os("win") then + tmpfile = "\\\\.\\\\pipe\\pipe.test" + else + tmpfile = helpers.tmpname() + os.remove(tmpfile) + end + local result = exec_lua([[ + local SOCK = ... + local uv = vim.uv + local server = uv.new_pipe(false) + server:bind(SOCK) + local init = nil + + server:listen(127, function(err) + assert(not err, err) + local client = uv.new_pipe() + server:accept(client) + client:read_start(require("vim.lsp.rpc").create_read_loop(function(body) + init = body + client:close() + end)) + end) + vim.lsp.start({ name = "dummy", cmd = vim.lsp.rpc.domain_socket_connect(SOCK) }) + vim.wait(1000, function() return init ~= nil end) + assert(init, "server must receive `initialize` request") + server:close() + server:shutdown() + return vim.json.decode(init) + ]], tmpfile) + eq(result.method, "initialize") + end) end) describe('handlers', function() -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/plugin/editorconfig_spec.lua | 2 +- test/functional/plugin/health_spec.lua | 124 +- test/functional/plugin/lsp/codelens_spec.lua | 43 +- test/functional/plugin/lsp/completion_spec.lua | 90 +- test/functional/plugin/lsp/diagnostic_spec.lua | 59 +- test/functional/plugin/lsp/handler_spec.lua | 19 +- test/functional/plugin/lsp/helpers.lua | 43 +- .../plugin/lsp/incremental_sync_spec.lua | 426 +-- test/functional/plugin/lsp/inlay_hint_spec.lua | 16 +- .../functional/plugin/lsp/semantic_tokens_spec.lua | 251 +- test/functional/plugin/lsp/utils_spec.lua | 117 +- test/functional/plugin/lsp_spec.lua | 2215 ++++++------ test/functional/plugin/man_spec.lua | 115 +- test/functional/plugin/matchparen_spec.lua | 13 +- test/functional/plugin/msgpack_spec.lua | 497 +-- test/functional/plugin/shada_spec.lua | 3598 ++++++++++++-------- test/functional/plugin/tutor_spec.lua | 6 +- 17 files changed, 4388 insertions(+), 3246 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index ac78003a8c..2c9ce7ae1a 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -13,7 +13,7 @@ local function test_case(name, expected) local filename = testdir .. pathsep .. name command('edit ' .. filename) for opt, val in pairs(expected) do - eq(val, meths.get_option_value(opt, {buf=0}), name) + eq(val, meths.get_option_value(opt, { buf = 0 }), name) end end diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 5d32768260..f08f207d39 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -11,9 +11,9 @@ local source = helpers.source local exec_lua = helpers.exec_lua describe(':checkhealth', function() - it("detects invalid $VIMRUNTIME", function() + it('detects invalid $VIMRUNTIME', function() clear({ - env={ VIMRUNTIME='bogus', }, + env = { VIMRUNTIME = 'bogus' }, }) local status, err = pcall(command, 'checkhealth') eq(false, status) @@ -26,11 +26,11 @@ describe(':checkhealth', function() eq(false, status) eq("Invalid 'runtimepath'", string.match(err, 'Invalid.*')) end) - it("detects invalid $VIM", function() + it('detects invalid $VIM', function() clear() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. command("let $VIM='zub'") - command("checkhealth nvim") + command('checkhealth nvim') matches('ERROR $VIM .* zub', curbuf_contents()) end) it('completions can be listed via getcompletion()', function() @@ -38,20 +38,20 @@ describe(':checkhealth', function() eq('nvim', getcompletion('nvim', 'checkhealth')[1]) eq('provider.clipboard', getcompletion('prov', 'checkhealth')[1]) eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) - neq('vim', getcompletion('^vim', 'checkhealth')[1]) -- should not complete vim.health + neq('vim', getcompletion('^vim', 'checkhealth')[1]) -- should not complete vim.health end) end) describe('health.vim', function() before_each(function() - clear{args={'-u', 'NORC'}} + clear { args = { '-u', 'NORC' } } -- Provides healthcheck functions - command("set runtimepath+=test/functional/fixtures") + command('set runtimepath+=test/functional/fixtures') end) - describe(":checkhealth", function() - it("functions report_*() render correctly", function() - command("checkhealth full_render") + describe(':checkhealth', function() + it('functions report_*() render correctly', function() + command('checkhealth full_render') helpers.expect([[ ============================================================================== @@ -73,8 +73,8 @@ describe('health.vim', function() ]]) end) - it("concatenates multiple reports", function() - command("checkhealth success1 success2 test_plug") + it('concatenates multiple reports', function() + command('checkhealth success1 success2 test_plug') helpers.expect([[ ============================================================================== @@ -103,8 +103,8 @@ describe('health.vim', function() ]]) end) - it("lua plugins submodules", function() - command("checkhealth test_plug.submodule") + it('lua plugins submodules', function() + command('checkhealth test_plug.submodule') helpers.expect([[ ============================================================================== @@ -118,8 +118,8 @@ describe('health.vim', function() ]]) end) - it("... including empty reports", function() - command("checkhealth test_plug.submodule_empty") + it('... including empty reports', function() + command('checkhealth test_plug.submodule_empty') helpers.expect([[ ============================================================================== @@ -129,7 +129,7 @@ describe('health.vim', function() ]]) end) - it("highlights OK, ERROR", function() + it('highlights OK, ERROR', function() local screen = Screen.new(50, 12) screen:attach() screen:set_default_attr_ids({ @@ -138,9 +138,10 @@ describe('health.vim', function() Heading = { foreground = tonumber('0x6a0dad') }, Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey }, }) - command("checkhealth foo success1") - command("set nofoldenable nowrap laststatus=0") - screen:expect{grid=[[ + command('checkhealth foo success1') + command('set nofoldenable nowrap laststatus=0') + screen:expect { + grid = [[ ^ | {Bar:──────────────────────────────────────────────────}| {Heading:foo: } | @@ -153,15 +154,17 @@ describe('health.vim', function() {Heading:report 1} | - {Ok:OK} everything is fine | | - ]]} + ]], + } end) - it("fold healthchecks", function() + it('fold healthchecks', function() local screen = Screen.new(50, 7) screen:attach() - command("checkhealth foo success1") - command("set nowrap laststatus=0") - screen:expect{grid=[[ + command('checkhealth foo success1') + command('set nowrap laststatus=0') + screen:expect { + grid = [[ ^ | ──────────────────────────────────────────────────| +WE 4 lines: foo: ·······························| @@ -169,11 +172,12 @@ describe('health.vim', function() +-- 8 lines: test_plug.success1: require("test_pl| ~ | | - ]]} + ]], + } end) - it("gracefully handles invalid healthcheck", function() - command("checkhealth non_existent_healthcheck") + it('gracefully handles invalid healthcheck', function() + command('checkhealth non_existent_healthcheck') -- luacheck: ignore 613 helpers.expect([[ @@ -184,9 +188,9 @@ describe('health.vim', function() ]]) end) - it("does not use vim.health as a healtcheck", function() + it('does not use vim.health as a healtcheck', function() -- vim.health is not a healthcheck - command("checkhealth vim") + command('checkhealth vim') helpers.expect([[ ERROR: No healthchecks found.]]) end) @@ -206,17 +210,18 @@ end) describe(':checkhealth window', function() before_each(function() - clear{args={'-u', 'NORC'}} + clear { args = { '-u', 'NORC' } } -- Provides healthcheck functions - command("set runtimepath+=test/functional/fixtures") - command("set nofoldenable nowrap laststatus=0") + command('set runtimepath+=test/functional/fixtures') + command('set nofoldenable nowrap laststatus=0') end) - it("opens directly if no buffer created", function() + it('opens directly if no buffer created', function() local screen = Screen.new(50, 12) - screen:attach({ext_multigrid=true}) - command("checkhealth success1") - screen:expect{grid=[[ + screen:attach({ ext_multigrid = true }) + command('checkhealth success1') + screen:expect { + grid = [[ ## grid 1 [2:--------------------------------------------------]|*11 [3:--------------------------------------------------]| @@ -234,17 +239,19 @@ describe(':checkhealth window', function() - OK nothing to see here | ## grid 3 | - ]]} + ]], + } end) local function test_health_vsplit(left, emptybuf, mods) local screen = Screen.new(50, 20) - screen:attach({ext_multigrid=true}) + screen:attach({ ext_multigrid = true }) if not emptybuf then insert('hello') end command(mods .. ' checkhealth success1') - screen:expect(([[ + screen:expect( + ([[ ## grid 1 %s [3:--------------------------------------------------]| @@ -268,10 +275,11 @@ describe(':checkhealth window', function() - OK nothing to see here | | ~ |*4 - ]]):format(left - and '[4:-------------------------]│[2:------------------------]|*19' - or '[2:------------------------]│[4:-------------------------]|*19', - emptybuf and ' ' or 'hello') + ]]):format( + left and '[4:-------------------------]│[2:------------------------]|*19' + or '[2:------------------------]│[4:-------------------------]|*19', + emptybuf and ' ' or 'hello' + ) ) end @@ -295,12 +303,13 @@ describe(':checkhealth window', function() local function test_health_split(top, emptybuf, mods) local screen = Screen.new(50, 25) - screen:attach({ext_multigrid=true}) + screen:attach({ ext_multigrid = true }) if not emptybuf then insert('hello') end command(mods .. ' checkhealth success1') - screen:expect(([[ + screen:expect( + ([[ ## grid 1 %s [3:--------------------------------------------------]| @@ -322,17 +331,20 @@ describe(':checkhealth window', function() report 2 | - OK nothing to see here | | - ]]):format(top - and [[ + ]]):format( + top + and [[ [4:--------------------------------------------------]|*12 health:// | [2:--------------------------------------------------]|*11]] - or ([[ + or ([[ [2:--------------------------------------------------]|*11 [No Name] %s | - [4:--------------------------------------------------]|*12]] - ):format(emptybuf and ' ' or '[+]'), - emptybuf and ' ' or 'hello') + [4:--------------------------------------------------]|*12]]):format( + emptybuf and ' ' or '[+]' + ), + emptybuf and ' ' or 'hello' + ) ) end @@ -354,11 +366,11 @@ describe(':checkhealth window', function() end) end - it("opens in tab", function() + it('opens in tab', function() -- create an empty buffer called "my_buff" exec_lua 'vim.api.nvim_create_buf(false, true)' command('file my_buff') - command("checkhealth success1") + command('checkhealth success1') -- define a function that collects all buffers in each tab -- returns a dictionary like {tab1 = ["buf1", "buf2"], tab2 = ["buf3"]} source([[ @@ -375,7 +387,7 @@ describe(':checkhealth window', function() return buffs endfunction ]]) - local buffers_per_tab = exec_lua("return vim.fn.CollectBuffersPerTab()") - eq(buffers_per_tab, {tab1 = { "my_buff" }, tab2 = {"health://"}}) + local buffers_per_tab = exec_lua('return vim.fn.CollectBuffersPerTab()') + eq(buffers_per_tab, { tab1 = { 'my_buff' }, tab2 = { 'health://' } }) end) end) diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index 3d7a15a191..29daf7a066 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -11,17 +11,21 @@ describe('vim.lsp.codelens', function() after_each(helpers.clear) it('on_codelens_stores_and_displays_lenses', function() - local fake_uri = "file:///fake/uri" - local bufnr = exec_lua([[ + local fake_uri = 'file:///fake/uri' + local bufnr = exec_lua( + [[ fake_uri = ... local bufnr = vim.uri_to_bufnr(fake_uri) local lines = {'So', 'many', 'lines'} vim.fn.bufload(bufnr) vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) return bufnr - ]], fake_uri) + ]], + fake_uri + ) - exec_lua([[ + exec_lua( + [[ local bufnr = ... local lenses = { { @@ -33,14 +37,16 @@ describe('vim.lsp.codelens', function() }, } vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) - ]], bufnr) + ]], + bufnr + ) local stored_lenses = exec_lua('return vim.lsp.codelens.get(...)', bufnr) local expected = { { range = { start = { line = 0, character = 0 }, - ['end'] = { line = 0, character = 0 } + ['end'] = { line = 0, character = 0 }, }, command = { title = 'Lens1', @@ -50,28 +56,35 @@ describe('vim.lsp.codelens', function() } eq(expected, stored_lenses) - local virtual_text_chunks = exec_lua([[ + local virtual_text_chunks = exec_lua( + [[ local bufnr = ... local ns = vim.lsp.codelens.__namespaces[1] local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {}) return vim.api.nvim_buf_get_extmark_by_id(bufnr, ns, extmarks[1][1], { details = true })[3].virt_text - ]], bufnr) + ]], + bufnr + ) - eq({[1] = {'Lens1', 'LspCodeLens'}}, virtual_text_chunks) + eq({ [1] = { 'Lens1', 'LspCodeLens' } }, virtual_text_chunks) end) it('can clear all lens', function() - local fake_uri = "file:///fake/uri" - local bufnr = exec_lua([[ + local fake_uri = 'file:///fake/uri' + local bufnr = exec_lua( + [[ fake_uri = ... local bufnr = vim.uri_to_bufnr(fake_uri) local lines = {'So', 'many', 'lines'} vim.fn.bufload(bufnr) vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) return bufnr - ]], fake_uri) + ]], + fake_uri + ) - exec_lua([[ + exec_lua( + [[ local bufnr = ... local lenses = { { @@ -83,7 +96,9 @@ describe('vim.lsp.codelens', function() }, } vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) - ]], bufnr) + ]], + bufnr + ) local stored_lenses = exec_lua('return vim.lsp.codelens.get(...)', bufnr) eq(1, #stored_lenses) diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 9354654afe..b49f970385 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local exec_lua = helpers.exec_lua - --- Convert completion results. --- ---@param line string line contents. Mark cursor position with `|` @@ -13,9 +12,10 @@ local exec_lua = helpers.exec_lua local function complete(line, candidates, lnum) lnum = lnum or 0 -- nvim_win_get_cursor returns 0 based column, line:find returns 1 based - local cursor_col = line:find("|") - 1 - line = line:gsub("|", "") - return exec_lua([[ + local cursor_col = line:find('|') - 1 + line = line:gsub('|', '') + return exec_lua( + [[ local line, cursor_col, lnum, result = ... local line_to_cursor = line:sub(1, cursor_col) local client_start_boundary = vim.fn.match(line_to_cursor, '\\k*$') @@ -32,18 +32,22 @@ local function complete(line, candidates, lnum) items = items, server_start_boundary = server_start_boundary } - ]], line, cursor_col, lnum, candidates) + ]], + line, + cursor_col, + lnum, + candidates + ) end - -describe("vim.lsp._completion", function() +describe('vim.lsp._completion', function() before_each(helpers.clear) -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion it('prefers textEdit over label as word', function() local range0 = { start = { line = 0, character = 0 }, - ["end"] = { line = 0, character = 0 }, + ['end'] = { line = 0, character = 0 }, } local completion_list = { -- resolves into label @@ -57,7 +61,12 @@ describe("vim.lsp._completion", function() { label = 'foocar', sortText = 'c', insertText = 'foobar' }, { label = 'foocar', sortText = 'd', insertText = 'foobar' }, -- resolves into textEdit.newText - { label = 'foocar', sortText = 'e', insertText = 'foodar', textEdit = { newText = 'foobar', range = range0 } }, + { + label = 'foocar', + sortText = 'e', + insertText = 'foodar', + textEdit = { newText = 'foobar', range = range0 }, + }, { label = 'foocar', sortText = 'f', textEdit = { newText = 'foobar', range = range0 } }, -- real-world snippet text { @@ -65,7 +74,10 @@ describe("vim.lsp._completion", function() sortText = 'g', insertText = 'foodar', insertTextFormat = 2, - textEdit = { newText = 'foobar(${1:place holder}, ${2:more ...holder{\\}})', range = range0 }, + textEdit = { + newText = 'foobar(${1:place holder}, ${2:more ...holder{\\}})', + range = range0, + }, }, { label = 'foocar', @@ -81,7 +93,7 @@ describe("vim.lsp._completion", function() insertTextFormat = 2, }, -- braced tabstop - { label = 'foocar', sortText = 'j', insertText = 'foodar()${0}', insertTextFormat = 2}, + { label = 'foocar', sortText = 'j', insertText = 'foodar()${0}', insertTextFormat = 2 }, -- plain text { label = 'foocar', @@ -140,32 +152,32 @@ describe("vim.lsp._completion", function() result = vim.tbl_map(function(x) return { abbr = x.abbr, - word = x.word + word = x.word, } end, result.items) eq(expected, result) end) - it("uses correct start boundary", function() + it('uses correct start boundary', function() local completion_list = { isIncomplete = false, items = { { - filterText = "this_thread", - insertText = "this_thread", + filterText = 'this_thread', + insertText = 'this_thread', insertTextFormat = 1, kind = 9, - label = " this_thread", + label = ' this_thread', score = 1.3205767869949, - sortText = "4056f757this_thread", + sortText = '4056f757this_thread', textEdit = { - newText = "this_thread", + newText = 'this_thread', range = { start = { line = 0, character = 7 }, - ["end"] = { line = 0, character = 11 }, + ['end'] = { line = 0, character = 11 }, }, - } + }, }, - } + }, } local expected = { abbr = ' this_thread', @@ -176,50 +188,50 @@ describe("vim.lsp._completion", function() menu = '', word = 'this_thread', } - local result = complete(" std::this|", completion_list) + local result = complete(' std::this|', completion_list) eq(7, result.server_start_boundary) local item = result.items[1] item.user_data = nil eq(expected, item) end) - it("should search from start boundary to cursor position", function() + it('should search from start boundary to cursor position', function() local completion_list = { isIncomplete = false, items = { { - filterText = "this_thread", - insertText = "this_thread", + filterText = 'this_thread', + insertText = 'this_thread', insertTextFormat = 1, kind = 9, - label = " this_thread", + label = ' this_thread', score = 1.3205767869949, - sortText = "4056f757this_thread", + sortText = '4056f757this_thread', textEdit = { - newText = "this_thread", + newText = 'this_thread', range = { start = { line = 0, character = 7 }, - ["end"] = { line = 0, character = 11 }, + ['end'] = { line = 0, character = 11 }, }, - } + }, }, { - filterText = "notthis_thread", - insertText = "notthis_thread", + filterText = 'notthis_thread', + insertText = 'notthis_thread', insertTextFormat = 1, kind = 9, - label = " notthis_thread", + label = ' notthis_thread', score = 1.3205767869949, - sortText = "4056f757this_thread", + sortText = '4056f757this_thread', textEdit = { - newText = "notthis_thread", + newText = 'notthis_thread', range = { start = { line = 0, character = 7 }, - ["end"] = { line = 0, character = 11 }, + ['end'] = { line = 0, character = 11 }, }, - } + }, }, - } + }, } local expected = { abbr = ' this_thread', @@ -230,7 +242,7 @@ describe("vim.lsp._completion", function() menu = '', word = 'this_thread', } - local result = complete(" std::this|is", completion_list) + local result = complete(' std::this|is', completion_list) eq(1, #result.items) local item = result.items[1] item.user_data = nil diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 1da0222114..ee8dfc7a60 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -12,10 +12,10 @@ describe('vim.lsp.diagnostic', function() local fake_uri before_each(function() - clear {env={ - NVIM_LUA_NOTRACK="1"; - VIMRUNTIME=os.getenv"VIMRUNTIME"; - }} + clear { env = { + NVIM_LUA_NOTRACK = '1', + VIMRUNTIME = os.getenv 'VIMRUNTIME', + } } exec_lua [[ require('vim.lsp') @@ -76,9 +76,10 @@ describe('vim.lsp.diagnostic', function() } ]] - fake_uri = "file:///fake/uri" + fake_uri = 'file:///fake/uri' - exec_lua([[ + exec_lua( + [[ fake_uri = ... diagnostic_bufnr = vim.uri_to_bufnr(fake_uri) local lines = {"1st line of text", "2nd line of text", "wow", "cool", "more", "lines"} @@ -86,7 +87,9 @@ describe('vim.lsp.diagnostic', function() vim.api.nvim_buf_set_lines(diagnostic_bufnr, 0, 1, false, lines) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) return diagnostic_bufnr - ]], fake_uri) + ]], + fake_uri + ) end) after_each(function() @@ -113,17 +116,18 @@ describe('vim.lsp.diagnostic', function() vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1)[1], } ]] - eq({code = 42, data = "Hello world"}, result[1].user_data.lsp) + eq({ code = 42, data = 'Hello world' }, result[1].user_data.lsp) eq(42, result[1].code) eq(42, result[2].code) - eq("Hello world", result[2].data) + eq('Hello world', result[2].data) end) end) - describe("vim.lsp.diagnostic.on_publish_diagnostics", function() + describe('vim.lsp.diagnostic.on_publish_diagnostics', function() it('allows configuring the virtual text via vim.lsp.with', function() local expected_spacing = 10 - local extmarks = exec_lua([[ + local extmarks = exec_lua( + [[ PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { spacing = ..., @@ -139,7 +143,9 @@ describe('vim.lsp.diagnostic', function() ) return get_extmarks(diagnostic_bufnr, client_id) - ]], expected_spacing) + ]], + expected_spacing + ) local virt_text = extmarks[1][4].virt_text local spacing = virt_text[1][1] @@ -149,7 +155,8 @@ describe('vim.lsp.diagnostic', function() it('allows configuring the virtual text via vim.lsp.with using a function', function() local expected_spacing = 10 - local extmarks = exec_lua([[ + local extmarks = exec_lua( + [[ spacing = ... PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { @@ -169,7 +176,9 @@ describe('vim.lsp.diagnostic', function() ) return get_extmarks(diagnostic_bufnr, client_id) - ]], expected_spacing) + ]], + expected_spacing + ) local virt_text = extmarks[1][4].virt_text local spacing = virt_text[1][1] @@ -179,7 +188,8 @@ describe('vim.lsp.diagnostic', function() it('allows filtering via severity limit', function() local get_extmark_count_with_severity = function(severity_limit) - return exec_lua([[ + return exec_lua( + [[ PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { underline = false, virtual_text = { @@ -196,20 +206,23 @@ describe('vim.lsp.diagnostic', function() ) return #get_extmarks(diagnostic_bufnr, client_id) - ]], severity_limit) + ]], + severity_limit + ) end -- No messages with Error or higher - eq(0, get_extmark_count_with_severity("Error")) + eq(0, get_extmark_count_with_severity('Error')) -- But now we don't filter it - eq(1, get_extmark_count_with_severity("Warning")) - eq(1, get_extmark_count_with_severity("Hint")) + eq(1, get_extmark_count_with_severity('Warning')) + eq(1, get_extmark_count_with_severity('Hint')) end) it('correctly handles UTF-16 offsets', function() - local line = "All 💼 and no 🎉 makes Jack a dull 👦" - local result = exec_lua([[ + local line = 'All 💼 and no 🎉 makes Jack a dull 👦' + local result = exec_lua( + [[ local line = ... vim.api.nvim_buf_set_lines(diagnostic_bufnr, 0, -1, false, {line}) @@ -225,7 +238,9 @@ describe('vim.lsp.diagnostic', function() vim.lsp.stop_client(client_id) vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) return diags - ]], line) + ]], + line + ) eq(1, #result) eq(exec_lua([[return vim.str_byteindex(..., 7, true)]], line), result[1].col) eq(exec_lua([[return vim.str_byteindex(..., 8, true)]], line), result[1].end_col) diff --git a/test/functional/plugin/lsp/handler_spec.lua b/test/functional/plugin/lsp/handler_spec.lua index 3086c23fe8..56e29e7337 100644 --- a/test/functional/plugin/lsp/handler_spec.lua +++ b/test/functional/plugin/lsp/handler_spec.lua @@ -8,21 +8,30 @@ local matches = helpers.matches describe('lsp-handlers', function() describe('vim.lsp._with_extend', function() it('should return a table with the default keys', function() - eq({hello = 'world' }, exec_lua [[ + eq( + { hello = 'world' }, + exec_lua [[ return vim.lsp._with_extend('test', { hello = 'world' }) - ]]) + ]] + ) end) it('should override with config keys', function() - eq({hello = 'universe', other = true}, exec_lua [[ + eq( + { hello = 'universe', other = true }, + exec_lua [[ return vim.lsp._with_extend('test', { other = true, hello = 'world' }, { hello = 'universe' }) - ]]) + ]] + ) end) it('should not allow invalid keys', function() matches( '.*Invalid option for `test`.*', - pcall_err(exec_lua, "return vim.lsp._with_extend('test', { hello = 'world' }, { invalid = true })") + pcall_err( + exec_lua, + "return vim.lsp._with_extend('test', { hello = 'world' }, { invalid = true })" + ) ) end) end) diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 15e6a62781..f641b42727 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -11,11 +11,13 @@ local M = {} function M.clear_notrace() -- problem: here be dragons -- solution: don't look too closely for dragons - clear {env={ - NVIM_LUA_NOTRACK="1"; - NVIM_APPNAME="nvim_lsp_test"; - VIMRUNTIME=os.getenv"VIMRUNTIME"; - }} + clear { + env = { + NVIM_LUA_NOTRACK = '1', + NVIM_APPNAME = 'nvim_lsp_test', + VIMRUNTIME = os.getenv 'VIMRUNTIME', + }, + } end M.create_server_definition = [[ @@ -79,7 +81,8 @@ M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' M.fake_lsp_logfile = 'Xtest-fake-lsp.log' local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) - exec_lua([=[ + exec_lua( + [=[ lsp = require('vim.lsp') local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ... TEST_RPC_CLIENT_ID = lsp.start_client { @@ -115,33 +118,49 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) vim.rpcnotify(1, "exit", ...) end; } - ]=], test_name, M.fake_lsp_code, M.fake_lsp_logfile, timeout_ms or 1e3, options or {}, settings or {}) + ]=], + test_name, + M.fake_lsp_code, + M.fake_lsp_logfile, + timeout_ms or 1e3, + options or {}, + settings or {} + ) end function M.test_rpc_server(config) if config.test_name then M.clear_notrace() - fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3, config.options, config.settings) + fake_lsp_server_setup( + config.test_name, + config.timeout_ms or 1e3, + config.options, + config.settings + ) end local client = setmetatable({}, { __index = function(_, name) -- Workaround for not being able to yield() inside __index for Lua 5.1 :( -- Otherwise I would just return the value here. return function(...) - return exec_lua([=[ + return exec_lua( + [=[ local name = ... if type(TEST_RPC_CLIENT[name]) == 'function' then return TEST_RPC_CLIENT[name](select(2, ...)) else return TEST_RPC_CLIENT[name] end - ]=], name, ...) + ]=], + name, + ... + ) end - end; + end, }) local code, signal local function on_request(method, args) - if method == "init" then + if method == 'init' then if config.on_init then config.on_init(client, unpack(args)) end diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index 724b3efb97..9b33f4451e 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -7,7 +7,7 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local feed = helpers.feed -before_each(function () +before_each(function() clear() exec_lua [[ local evname = ... @@ -52,19 +52,24 @@ before_each(function () ]] end) -local function test_edit(prev_buffer, edit_operations, expected_text_changes, offset_encoding, line_ending) +local function test_edit( + prev_buffer, + edit_operations, + expected_text_changes, + offset_encoding, + line_ending +) offset_encoding = offset_encoding or 'utf-16' line_ending = line_ending or '\n' meths.buf_set_lines(0, 0, -1, true, prev_buffer) - exec_lua("return test_register(...)", 0, "test1", offset_encoding, line_ending) + exec_lua('return test_register(...)', 0, 'test1', offset_encoding, line_ending) for _, edit in ipairs(edit_operations) do feed(edit) end - eq(expected_text_changes, exec_lua("return get_events(...)" )) + eq(expected_text_changes, exec_lua('return get_events(...)')) exec_lua("test_unreg = 'test1'") - end describe('incremental synchronization', function() @@ -75,18 +80,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 0, - line = 0 - } + line = 0, + }, }, rangeLength = 0, - text = 'a' - } + text = 'a', + }, } - test_edit({""}, {"ia"}, expected_text_changes, 'utf-16', '\n') + test_edit({ '' }, { 'ia' }, expected_text_changes, 'utf-16', '\n') end) it('inserting a character in the middle of a the first line', function() local expected_text_changes = { @@ -94,18 +99,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 1, - line = 0 + line = 0, }, ['end'] = { character = 1, - line = 0 - } + line = 0, + }, }, rangeLength = 0, - text = 'a' - } + text = 'a', + }, } - test_edit({"ab"}, {"lia"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'ab' }, { 'lia' }, expected_text_changes, 'utf-16', '\n') end) it('deleting the only character in a buffer', function() local expected_text_changes = { @@ -113,18 +118,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 1, - line = 0 - } + line = 0, + }, }, rangeLength = 1, - text = '' - } + text = '', + }, } - test_edit({"a"}, {"x"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'a' }, { 'x' }, expected_text_changes, 'utf-16', '\n') end) it('deleting a character in the middle of the line', function() local expected_text_changes = { @@ -132,18 +137,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 1, - line = 0 + line = 0, }, ['end'] = { character = 2, - line = 0 - } + line = 0, + }, }, rangeLength = 1, - text = '' - } + text = '', + }, } - test_edit({"abc"}, {"lx"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'abc' }, { 'lx' }, expected_text_changes, 'utf-16', '\n') end) it('replacing a character', function() local expected_text_changes = { @@ -151,18 +156,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 1, - line = 0 - } + line = 0, + }, }, rangeLength = 1, - text = 'b' - } + text = 'b', + }, } - test_edit({"a"}, {"rb"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'a' }, { 'rb' }, expected_text_changes, 'utf-16', '\n') end) it('deleting a line', function() local expected_text_changes = { @@ -170,18 +175,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 0, - line = 1 - } + line = 1, + }, }, rangeLength = 12, - text = '' - } + text = '', + }, } - test_edit({"hello world"}, {"dd"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'hello world' }, { 'dd' }, expected_text_changes, 'utf-16', '\n') end) it('deleting an empty line', function() local expected_text_changes = { @@ -189,18 +194,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 1 + line = 1, }, ['end'] = { character = 0, - line = 2 - } + line = 2, + }, }, rangeLength = 1, - text = '' - } + text = '', + }, } - test_edit({"hello world", ""}, {"jdd"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'hello world', '' }, { 'jdd' }, expected_text_changes, 'utf-16', '\n') end) it('adding a line', function() local expected_text_changes = { @@ -212,14 +217,14 @@ describe('incremental synchronization', function() }, ['end'] = { character = 0, - line = 1 - } + line = 1, + }, }, rangeLength = 1, - text = '\nhello world\n' - } + text = '\nhello world\n', + }, } - test_edit({"hello world"}, {"yyp"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'hello world' }, { 'yyp' }, expected_text_changes, 'utf-16', '\n') end) it('adding an empty line', function() local expected_text_changes = { @@ -227,18 +232,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 11, - line = 0 + line = 0, }, ['end'] = { character = 0, - line = 1 - } + line = 1, + }, }, rangeLength = 1, - text = '\n\n' - } + text = '\n\n', + }, } - test_edit({"hello world"}, {"o"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'hello world' }, { 'o' }, expected_text_changes, 'utf-16', '\n') end) it('adding a line to an empty buffer', function() local expected_text_changes = { @@ -246,18 +251,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 0, - line = 1 - } + line = 1, + }, }, rangeLength = 1, - text = '\n\n' - } + text = '\n\n', + }, } - test_edit({""}, {"o"}, expected_text_changes, 'utf-16', '\n') + test_edit({ '' }, { 'o' }, expected_text_changes, 'utf-16', '\n') end) it('insert a line above the current line', function() local expected_text_changes = { @@ -265,18 +270,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 0, - line = 0 - } + line = 0, + }, }, rangeLength = 0, - text = '\n' - } + text = '\n', + }, } - test_edit({""}, {"O"}, expected_text_changes, 'utf-16', '\n') + test_edit({ '' }, { 'O' }, expected_text_changes, 'utf-16', '\n') end) end) describe('multi line edit', function() @@ -287,115 +292,115 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 4, - line = 1 + line = 1, }, ['end'] = { character = 9, - line = 1 - } + line = 1, + }, }, rangeLength = 5, - text = '' + text = '', }, -- delete "hello world\n" from line 2 { range = { ['start'] = { character = 0, - line = 2 + line = 2, }, ['end'] = { character = 0, - line = 3 - } + line = 3, + }, }, rangeLength = 12, - text = '' + text = '', }, -- delete "1234" from beginning of line 2 { range = { ['start'] = { character = 0, - line = 2 + line = 2, }, ['end'] = { character = 4, - line = 2 - } + line = 2, + }, }, rangeLength = 4, - text = '' + text = '', }, -- add " asdf" to end of line 1 { range = { ['start'] = { character = 4, - line = 1 + line = 1, }, ['end'] = { character = 4, - line = 1 - } + line = 1, + }, }, rangeLength = 0, - text = ' asdf' + text = ' asdf', }, -- delete " asdf\n" from line 2 { range = { ['start'] = { character = 0, - line = 2 + line = 2, }, ['end'] = { character = 0, - line = 3 - } + line = 3, + }, }, rangeLength = 6, - text = '' + text = '', }, -- undo entire deletion { range = { ['start'] = { character = 4, - line = 1 + line = 1, }, ['end'] = { character = 9, - line = 1 - } + line = 1, + }, }, rangeLength = 5, - text = "_fdsa\nhello world\n1234 asdf" + text = '_fdsa\nhello world\n1234 asdf', }, -- redo entire deletion { range = { ['start'] = { character = 4, - line = 1 + line = 1, }, ['end'] = { character = 9, - line = 3 - } + line = 3, + }, }, rangeLength = 27, - text = ' asdf' + text = ' asdf', }, } local original_lines = { - "\\begin{document}", - "test_fdsa", - "hello world", - "1234 asdf", - "\\end{document}" + '\\begin{document}', + 'test_fdsa', + 'hello world', + '1234 asdf', + '\\end{document}', } - test_edit(original_lines, {"jf_vejjbhhdu"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { 'jf_vejjbhhdu' }, expected_text_changes, 'utf-16', '\n') end) end) @@ -404,64 +409,83 @@ describe('incremental synchronization', function() local expected_text_changes = { { range = { - ["end"] = { - character = 11, - line = 2 }, - ["start"] = { - character = 10, - line = 2 } }, + ['end'] = { + character = 11, + line = 2, + }, + ['start'] = { + character = 10, + line = 2, + }, + }, rangeLength = 1, text = '', - },{ + }, + { range = { - ["end"] = { + ['end'] = { character = 10, - line = 2 }, + line = 2, + }, start = { character = 10, - line = 2 } }, + line = 2, + }, + }, rangeLength = 0, text = '2', - },{ + }, + { range = { - ["end"] = { + ['end'] = { character = 11, - line = 3 }, - ["start"] = { + line = 3, + }, + ['start'] = { character = 10, - line = 3 } }, + line = 3, + }, + }, rangeLength = 1, - text = '' - },{ + text = '', + }, + { range = { ['end'] = { character = 10, - line = 3 }, + line = 3, + }, ['start'] = { character = 10, - line = 3 } }, + line = 3, + }, + }, rangeLength = 0, - text = '3' }, + text = '3', + }, { range = { ['end'] = { character = 0, - line = 3 }, + line = 3, + }, ['start'] = { character = 12, - line = 2 } }, + line = 2, + }, + }, rangeLength = 1, - text = '\n' - } + text = '\n', + }, } local original_lines = { - "\\begin{document}", - "\\section*{1}", - "\\section*{1}", - "\\section*{1}", - "\\end{document}" + '\\begin{document}', + '\\section*{1}', + '\\section*{1}', + '\\section*{1}', + '\\end{document}', } - test_edit(original_lines, {"3gg$hjg"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { '3gg$hjg' }, expected_text_changes, 'utf-16', '\n') end) it('join and undo', function() local expected_text_changes = { @@ -469,44 +493,46 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 11, - line = 0 + line = 0, }, ['end'] = { character = 11, - line = 0 - } + line = 0, + }, }, rangeLength = 0, - text = ' test3' - },{ + text = ' test3', + }, + { range = { ['start'] = { character = 0, - line = 1 + line = 1, }, ['end'] = { character = 0, - line = 2 - } + line = 2, + }, }, rangeLength = 6, - text = '' - },{ + text = '', + }, + { range = { ['start'] = { character = 11, - line = 0 + line = 0, }, ['end'] = { character = 17, - line = 0 - } + line = 0, + }, }, rangeLength = 6, - text = '\ntest3' + text = '\ntest3', }, } - test_edit({"test1 test2", "test3"}, {"J", "u"}, expected_text_changes, 'utf-16', '\n') + test_edit({ 'test1 test2', 'test3' }, { 'J', 'u' }, expected_text_changes, 'utf-16', '\n') end) end) @@ -517,18 +543,18 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 0 + line = 0, }, ['end'] = { character = 2, - line = 0 - } + line = 0, + }, }, rangeLength = 2, - text = '' - } + text = '', + }, } - test_edit({"🔥"}, {"x"}, expected_text_changes, 'utf-16', '\n') + test_edit({ '🔥' }, { 'x' }, expected_text_changes, 'utf-16', '\n') end) it('replacing a multibyte character with matching prefix', function() local expected_text_changes = { @@ -536,24 +562,24 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 1 + line = 1, }, ['end'] = { character = 1, - line = 1 - } + line = 1, + }, }, rangeLength = 1, - text = '⟩' - } + text = '⟩', + }, } -- ⟨ is e29fa8, ⟩ is e29fa9 local original_lines = { - "\\begin{document}", - "⟨", - "\\end{document}", + '\\begin{document}', + '⟨', + '\\end{document}', } - test_edit(original_lines, {"jr⟩"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { 'jr⟩' }, expected_text_changes, 'utf-16', '\n') end) it('replacing a multibyte character with matching suffix', function() local expected_text_changes = { @@ -561,24 +587,24 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 1 + line = 1, }, ['end'] = { character = 1, - line = 1 - } + line = 1, + }, }, rangeLength = 1, - text = 'ḟ' - } + text = 'ḟ', + }, } -- ฟ is e0b89f, ḟ is e1b89f local original_lines = { - "\\begin{document}", - "ฟ", - "\\end{document}", + '\\begin{document}', + 'ฟ', + '\\end{document}', } - test_edit(original_lines, {"jrḟ"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { 'jrḟ' }, expected_text_changes, 'utf-16', '\n') end) it('inserting before a multibyte character', function() local expected_text_changes = { @@ -586,23 +612,23 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 1 + line = 1, }, ['end'] = { character = 0, - line = 1 - } + line = 1, + }, }, rangeLength = 0, - text = ' ' - } + text = ' ', + }, } local original_lines = { - "\\begin{document}", - "→", - "\\end{document}", + '\\begin{document}', + '→', + '\\end{document}', } - test_edit(original_lines, {"ji "}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { 'ji ' }, expected_text_changes, 'utf-16', '\n') end) it('deleting a multibyte character from a long line', function() local expected_text_changes = { @@ -610,23 +636,23 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 85, - line = 1 + line = 1, }, ['end'] = { character = 86, - line = 1 - } + line = 1, + }, }, rangeLength = 1, - text = '' - } + text = '', + }, } local original_lines = { - "\\begin{document}", - "→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→", - "\\end{document}", + '\\begin{document}', + '→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→', + '\\end{document}', } - test_edit(original_lines, {"jx"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { 'jx' }, expected_text_changes, 'utf-16', '\n') end) it('deleting multiple lines containing multibyte characters', function() local expected_text_changes = { @@ -634,19 +660,25 @@ describe('incremental synchronization', function() range = { ['start'] = { character = 0, - line = 1 + line = 1, }, ['end'] = { character = 0, - line = 3 - } + line = 3, + }, }, --utf 16 len of 🔥 is 2 rangeLength = 8, - text = '' - } + text = '', + }, } - test_edit({"a🔥", "b🔥", "c🔥", "d🔥"}, {"j2dd"}, expected_text_changes, 'utf-16', '\n') + test_edit( + { 'a🔥', 'b🔥', 'c🔥', 'd🔥' }, + { 'j2dd' }, + expected_text_changes, + 'utf-16', + '\n' + ) end) end) end) diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index d0d55df72b..192797b312 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -40,7 +40,7 @@ local grid_without_inlay_hints = [[ | ]] -local grid_with_inlay_hints = [[ +local grid_with_inlay_hints = [[ auto add(int a, int b)-> int { return a + b; } | | int main() { | @@ -60,7 +60,8 @@ before_each(function() screen:attach() exec_lua(create_server_definition) - exec_lua([[ + exec_lua( + [[ local response = ... server = _create_server({ capabilities = { @@ -77,7 +78,9 @@ before_each(function() vim.api.nvim_win_set_buf(0, bufnr) client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) - ]], response) + ]], + response + ) insert(text) exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]]) @@ -145,7 +148,8 @@ describe('vim.lsp.inlay_hint', function() paddingRight = false, } - exec_lua([[ + exec_lua( + [[ local expected2 = ... server2 = _create_server({ capabilities = { @@ -159,7 +163,9 @@ describe('vim.lsp.inlay_hint', function() }) client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd }) vim.lsp.inlay_hint.enable(bufnr) - ]], expected2) + ]], + expected2 + ) --- @type vim.lsp.inlay_hint.get.ret local res = exec_lua([[return vim.lsp.inlay_hint.get()]]) diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index b95d435c2b..77e39c81c8 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -23,21 +23,20 @@ after_each(function() end) describe('semantic token highlighting', function() - local screen before_each(function() screen = Screen.new(40, 16) screen:attach() screen:set_default_attr_ids { - [1] = { bold = true, foreground = Screen.colors.Blue1 }; - [2] = { foreground = Screen.colors.DarkCyan }; - [3] = { foreground = Screen.colors.SlateBlue }; - [4] = { bold = true, foreground = Screen.colors.SeaGreen }; - [5] = { foreground = tonumber('0x6a0dad') }; - [6] = { foreground = Screen.colors.Blue1 }; - [7] = { bold = true, foreground = Screen.colors.DarkCyan }; - [8] = { bold = true, foreground = Screen.colors.SlateBlue }; - [9] = { bold = true, foreground = tonumber('0x6a0dad') }; + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.DarkCyan }, + [3] = { foreground = Screen.colors.SlateBlue }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen }, + [5] = { foreground = tonumber('0x6a0dad') }, + [6] = { foreground = Screen.colors.Blue1 }, + [7] = { bold = true, foreground = Screen.colors.DarkCyan }, + [8] = { bold = true, foreground = Screen.colors.SlateBlue }, + [9] = { bold = true, foreground = tonumber('0x6a0dad') }, } command([[ hi link @lsp.type.namespace Type ]]) command([[ hi link @lsp.type.function Special ]]) @@ -81,7 +80,8 @@ describe('semantic token highlighting', function() before_each(function() exec_lua(create_server_definition) - exec_lua([[ + exec_lua( + [[ local legend, response, edit_response = ... server = _create_server({ capabilities = { @@ -99,7 +99,11 @@ describe('semantic token highlighting', function() end, } }) - ]], legend, response, edit_response) + ]], + legend, + response, + edit_response + ) end) it('buffer is highlighted when attached', function() @@ -112,7 +116,8 @@ describe('semantic token highlighting', function() insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -127,7 +132,8 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } end) it('use LspTokenUpdate and highlight_token', function() @@ -149,7 +155,8 @@ describe('semantic token highlighting', function() insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {9:main}() | @@ -164,8 +171,8 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } - + ]], + } end) it('buffer is unhighlighted when client is detached', function() @@ -182,7 +189,8 @@ describe('semantic token highlighting', function() vim.lsp.buf_detach_client(bufnr, client_id) ]]) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int main() | @@ -197,25 +205,28 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } end) - it('buffer is highlighted and unhighlighted when semantic token highlighting is started and stopped' - , function() - exec_lua([[ + it( + 'buffer is highlighted and unhighlighted when semantic token highlighting is started and stopped', + function() + exec_lua([[ bufnr = vim.api.nvim_get_current_buf() vim.api.nvim_win_set_buf(0, bufnr) client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) ]]) - insert(text) + insert(text) - exec_lua([[ + exec_lua([[ vim.notify = function() end vim.lsp.semantic_tokens.stop(bufnr, client_id) ]]) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int main() | @@ -230,13 +241,15 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } - exec_lua([[ + exec_lua([[ vim.lsp.semantic_tokens.start(bufnr, client_id) ]]) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -251,8 +264,10 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } - end) + ]], + } + end + ) it('buffer is re-highlighted when force refreshed', function() exec_lua([[ @@ -263,7 +278,8 @@ describe('semantic token highlighting', function() insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -278,13 +294,15 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } exec_lua([[ vim.lsp.semantic_tokens.force_refresh(bufnr) ]]) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -299,7 +317,9 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]], unchanged = true } + ]], + unchanged = true, + } local messages = exec_lua('return server.messages') local token_request_count = 0 @@ -338,7 +358,8 @@ describe('semantic token highlighting', function() ]]) insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -353,10 +374,12 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } feed_command('%s/int x/int x()/') feed_command('noh') - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -370,7 +393,8 @@ describe('semantic token highlighting', function() } |*2 {1:~ }|*3 :noh | - ]] } + ]], + } end) it('prevents starting semantic token highlighting with invalid conditions', function() @@ -381,7 +405,7 @@ describe('semantic token highlighting', function() notifications = {} vim.notify = function(...) table.insert(notifications, 1, {...}) end ]]) - eq(false, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) + eq(false, exec_lua('return vim.lsp.buf_is_attached(bufnr, client_id)')) insert(text) @@ -398,7 +422,8 @@ describe('semantic token highlighting', function() matches('%[LSP%] No client with id %d', notifications[1][1]) end) - it('opt-out: does not activate semantic token highlighting if disabled in client attach', + it( + 'opt-out: does not activate semantic token highlighting if disabled in client attach', function() exec_lua([[ bufnr = vim.api.nvim_get_current_buf() @@ -411,11 +436,12 @@ describe('semantic token highlighting', function() end), }) ]]) - eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) + eq(true, exec_lua('return vim.lsp.buf_is_attached(bufnr, client_id)')) insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int main() | @@ -430,7 +456,8 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } local notifications = exec_lua([[ local notifications = {} @@ -440,7 +467,8 @@ describe('semantic token highlighting', function() ]]) eq('[LSP] Server does not support semantic tokens', notifications[1][1]) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int main() | @@ -455,10 +483,13 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]], unchanged = true } - end) + ]], + unchanged = true, + } + end + ) - it('ignores null responses from the server', function() + it('ignores null responses from the server', function() exec_lua([[ local legend, response, edit_response = ... server2 = _create_server({ @@ -480,11 +511,12 @@ describe('semantic token highlighting', function() vim.api.nvim_win_set_buf(0, bufnr) client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd }) ]]) - eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) + eq(true, exec_lua('return vim.lsp.buf_is_attached(bufnr, client_id)')) insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int main() | @@ -499,11 +531,13 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } end) it('does not send delta requests if not supported by server', function() - exec_lua([[ + exec_lua( + [[ local legend, response, edit_response = ... server2 = _create_server({ capabilities = { @@ -524,10 +558,15 @@ describe('semantic token highlighting', function() bufnr = vim.api.nvim_get_current_buf() vim.api.nvim_win_set_buf(0, bufnr) client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd }) - ]], legend, response, edit_response) + ]], + legend, + response, + edit_response + ) insert(text) - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -542,14 +581,16 @@ describe('semantic token highlighting', function() ^} | {1:~ }|*3 | - ]] } + ]], + } feed_command('%s/int x/int x()/') feed_command('noh') -- the highlights don't change because our fake server sent the exact -- same result for the same method (the full request). "x" would have -- changed to highlight index 3 had we sent a delta request - screen:expect { grid = [[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -563,7 +604,8 @@ describe('semantic token highlighting', function() } |*2 {1:~ }|*3 :noh | - ]] } + ]], + } local messages = exec_lua('return server2.messages') local token_request_count = 0 for _, message in ipairs(messages) do @@ -601,11 +643,13 @@ describe('semantic token highlighting', function() }, }, expected_screen = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ char* {7:foo} = "\n"^; | {1:~ }|*14 | - ]]} + ]], + } end, }, { @@ -720,7 +764,8 @@ int main() }, }, expected_screen = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ #include | int {8:main}() | { | @@ -733,7 +778,8 @@ int main() ^} | {1:~ }|*5 | - ]]} + ]], + } end, }, { @@ -777,13 +823,15 @@ b = "as"]], }, }, expected_screen = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ {6:-- comment} | local {7:a} = 1 | {2:b} = "as^" | {1:~ }|*12 | - ]]} + ]], + } end, }, { @@ -896,7 +944,8 @@ b = "as"]], }, }, expected_screen = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ pub fn {8:main}() { | break rust; | //{6:/ what?} | @@ -904,13 +953,15 @@ b = "as"]], ^ | {1:~ }|*10 | - ]]} + ]], + } end, }, }) do it(test.it, function() exec_lua(create_server_definition) - exec_lua([[ + exec_lua( + [[ local legend, resp = ... server = _create_server({ capabilities = { @@ -928,7 +979,10 @@ b = "as"]], bufnr = vim.api.nvim_get_current_buf() vim.api.nvim_win_set_buf(0, bufnr) client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) - ]], test.legend, test.response) + ]], + test.legend, + test.response + ) insert(test.text) @@ -970,7 +1024,7 @@ b = "as"]], end_col = 9, type = 'variable', marked = true, - } + }, }, expected2 = { { @@ -983,22 +1037,26 @@ b = "as"]], end_col = 9, type = 'variable', marked = true, - } + }, }, expected_screen1 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ char* {7:foo} = "\n"^; | {1:~ }|*14 | - ]]} + ]], + } end, expected_screen2 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | char* {7:foo} = "\n"; | {1:~ }|*13 | - ]]} + ]], + } end, }, { @@ -1115,7 +1173,7 @@ int main() modifiers = {}, type = 'comment', marked = true, - } + }, }, expected2 = { { @@ -1197,10 +1255,11 @@ int main() modifiers = {}, type = 'comment', marked = true, - } + }, }, expected_screen1 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -1214,10 +1273,12 @@ int main() ^} | {1:~ }|*4 | - ]]} + ]], + } end, expected_screen2 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ #include | | int {8:main}() | @@ -1232,7 +1293,8 @@ int main() } | {1:~ }|*3 | - ]]} + ]], + } end, }, { @@ -1259,29 +1321,33 @@ int main() end_col = 6, type = 'variable', marked = true, - } - }, - expected2 = { + }, }, + expected2 = {}, expected_screen1 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ {7:string} = "test^" | {1:~ }|*14 | - ]]} + ]], + } end, expected_screen2 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*14 | - ]]} + ]], + } end, }, }) do it(test.it, function() exec_lua(create_server_definition) - exec_lua([[ + exec_lua( + [[ local legend, resp1, resp2 = ... server = _create_server({ capabilities = { @@ -1309,7 +1375,11 @@ int main() semantic_tokens.stop(bufnr, client_id) semantic_tokens.start(bufnr, client_id, { debounce = 10 }) end) - ]], test.legend, test.response1, test.response2) + ]], + test.legend, + test.response1, + test.response2 + ) insert(test.text1) @@ -1324,11 +1394,14 @@ int main() if test.edit then feed(test.edit) else - exec_lua([[ + exec_lua( + [[ local text = ... vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, vim.fn.split(text, "\n")) vim.wait(15) -- wait for debounce - ]], test.text2) + ]], + test.text2 + ) end test.expected_screen2() diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index 804dc32f0d..bb9cdb8390 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -10,7 +10,8 @@ describe('vim.lsp.util', function() describe('stylize_markdown', function() local stylize_markdown = function(content, opts) - return exec_lua([[ + return exec_lua( + [[ local bufnr = vim.uri_to_bufnr("file:///fake/uri") vim.fn.bufload(bufnr) @@ -20,14 +21,17 @@ describe('vim.lsp.util', function() local stripped_content = vim.lsp.util.stylize_markdown(bufnr, content, opts) return stripped_content - ]], content, opts) + ]], + content, + opts + ) end it('code fences', function() local lines = { - "```lua", + '```lua', "local hello = 'world'", - "```", + '```', } local expected = { "local hello = 'world'", @@ -38,9 +42,9 @@ describe('vim.lsp.util', function() it('code fences with whitespace surrounded info string', function() local lines = { - "``` lua ", + '``` lua ', "local hello = 'world'", - "```", + '```', } local expected = { "local hello = 'world'", @@ -51,16 +55,16 @@ describe('vim.lsp.util', function() it('adds separator after code block', function() local lines = { - "```lua", + '```lua', "local hello = 'world'", - "```", - "", - "something", + '```', + '', + 'something', } local expected = { "local hello = 'world'", - "─────────────────────", - "something", + '─────────────────────', + 'something', } local opts = { separator = true } eq(expected, stylize_markdown(lines, opts)) @@ -68,28 +72,28 @@ describe('vim.lsp.util', function() it('replaces supported HTML entities', function() local lines = { - "1 < 2", - "3 > 2", - ""quoted"", - "'apos'", - "   ", - "&", + '1 < 2', + '3 > 2', + '"quoted"', + ''apos'', + '   ', + '&', } local expected = { - "1 < 2", - "3 > 2", + '1 < 2', + '3 > 2', '"quoted"', "'apos'", - " ", - "&", + ' ', + '&', } local opts = {} eq(expected, stylize_markdown(lines, opts)) end) end) - describe('normalize_markdown', function () - it('collapses consecutive blank lines', function () + describe('normalize_markdown', function() + it('collapses consecutive blank lines', function() local result = exec_lua [[ local lines = { 'foo', @@ -102,11 +106,11 @@ describe('vim.lsp.util', function() } return vim.lsp.util._normalize_markdown(lines) ]] - local expected = {'foo', '', 'bar', '', 'baz'} + local expected = { 'foo', '', 'bar', '', 'baz' } eq(expected, result) end) - it('removes preceding and trailing empty lines', function () + it('removes preceding and trailing empty lines', function() local result = exec_lua [[ local lines = { '', @@ -117,103 +121,105 @@ describe('vim.lsp.util', function() } return vim.lsp.util._normalize_markdown(lines) ]] - local expected = {'foo', 'bar'} + local expected = { 'foo', 'bar' } eq(expected, result) end) end) - describe("make_floating_popup_options", function () - + describe('make_floating_popup_options', function() local function assert_anchor(anchor_bias, expected_anchor) - local opts = exec_lua([[ + local opts = exec_lua( + [[ local args = { ... } local anchor_bias = args[1] return vim.lsp.util.make_floating_popup_options(30, 10, { anchor_bias = anchor_bias }) - ]], anchor_bias) + ]], + anchor_bias + ) - eq(expected_anchor, string.sub(opts.anchor, 1, 1)) + eq(expected_anchor, string.sub(opts.anchor, 1, 1)) end local screen - before_each(function () + before_each(function() helpers.clear() screen = Screen.new(80, 80) screen:attach() - feed("79i") -- fill screen with empty lines + feed('79i') -- fill screen with empty lines end) - describe('when on the first line it places window below', function () - before_each(function () + describe('when on the first line it places window below', function() + before_each(function() feed('gg') end) - it('for anchor_bias = "auto"', function () + it('for anchor_bias = "auto"', function() assert_anchor('auto', 'N') end) - it('for anchor_bias = "above"', function () + it('for anchor_bias = "above"', function() assert_anchor('above', 'N') end) - it('for anchor_bias = "below"', function () + it('for anchor_bias = "below"', function() assert_anchor('below', 'N') end) end) - describe('when on the last line it places window above', function () - before_each(function () + describe('when on the last line it places window above', function() + before_each(function() feed('G') end) - it('for anchor_bias = "auto"', function () + it('for anchor_bias = "auto"', function() assert_anchor('auto', 'S') end) - it('for anchor_bias = "above"', function () + it('for anchor_bias = "above"', function() assert_anchor('above', 'S') end) - it('for anchor_bias = "below"', function () + it('for anchor_bias = "below"', function() assert_anchor('below', 'S') end) end) - describe('with 20 lines above, 59 lines below', function () - before_each(function () + describe('with 20 lines above, 59 lines below', function() + before_each(function() feed('gg20j') end) - it('places window below for anchor_bias = "auto"', function () + it('places window below for anchor_bias = "auto"', function() assert_anchor('auto', 'N') end) - it('places window above for anchor_bias = "above"', function () + it('places window above for anchor_bias = "above"', function() assert_anchor('above', 'S') end) - it('places window below for anchor_bias = "below"', function () + it('places window below for anchor_bias = "below"', function() assert_anchor('below', 'N') end) end) - describe('with 59 lines above, 20 lines below', function () - before_each(function () + describe('with 59 lines above, 20 lines below', function() + before_each(function() feed('G20k') end) - it('places window above for anchor_bias = "auto"', function () + it('places window above for anchor_bias = "auto"', function() assert_anchor('auto', 'S') end) - it('places window above for anchor_bias = "above"', function () + it('places window above for anchor_bias = "above"', function() assert_anchor('above', 'S') end) - it('places window below for anchor_bias = "below"', function () + it('places window below for anchor_bias = "below"', function() assert_anchor('below', 'N') end) - it('bordered window truncates dimensions correctly', function () + it('bordered window truncates dimensions correctly', function() local opts = exec_lua([[ return vim.lsp.util.make_floating_popup_options(100, 100, { border = 'single' }) ]]) @@ -222,5 +228,4 @@ describe('vim.lsp.util', function() end) end) end) - end) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a6b3835dbc..86b9be79e0 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -32,14 +32,16 @@ local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile local test_rpc_server = lsp_helpers.test_rpc_server local function get_buf_option(name, bufnr) - bufnr = bufnr or "BUFFER" - return exec_lua( - string.format("return vim.api.nvim_get_option_value('%s', { buf = %s })", name, bufnr) - ) + bufnr = bufnr or 'BUFFER' + return exec_lua( + string.format("return vim.api.nvim_get_option_value('%s', { buf = %s })", name, bufnr) + ) end -- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 -if skip(is_os('win')) then return end +if skip(is_os('win')) then + return +end teardown(function() os.remove(fake_lsp_logfile) @@ -51,8 +53,9 @@ describe('LSP', function() -- Run an instance of nvim on the file which contains our "scripts". -- Pass TEST_NAME to pick the script. - local test_name = "basic_init" - exec_lua([=[ + local test_name = 'basic_init' + exec_lua( + [=[ lsp = require('vim.lsp') local test_name, fake_lsp_code, fake_lsp_logfile = ... function test__start_client() @@ -71,12 +74,16 @@ describe('LSP', function() } end TEST_CLIENT1 = test__start_client() - ]=], test_name, fake_lsp_code, fake_lsp_logfile) + ]=], + test_name, + fake_lsp_code, + fake_lsp_logfile + ) end) after_each(function() exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") - -- exec_lua("lsp.stop_all_clients(true)") + -- exec_lua("lsp.stop_all_clients(true)") end) describe('server_name specified', function() @@ -84,14 +91,20 @@ describe('LSP', function() retry(nil, 4000, function() eq(1, exec_lua('return #lsp.get_clients()')) end) - eq(2, exec_lua([[ + eq( + 2, + exec_lua([[ TEST_CLIENT2 = test__start_client() return TEST_CLIENT2 - ]])) - eq(3, exec_lua([[ + ]]) + ) + eq( + 3, + exec_lua([[ TEST_CLIENT3 = test__start_client() return TEST_CLIENT3 - ]])) + ]]) + ) retry(nil, 4000, function() eq(3, exec_lua('return #lsp.get_clients()')) end) @@ -128,21 +141,25 @@ describe('LSP', function() describe('lsp._cmd_parts test', function() local function _cmd_parts(input) - return exec_lua([[ + return exec_lua( + [[ lsp = require('vim.lsp') return lsp._cmd_parts(...) - ]], input) + ]], + input + ) end it('should valid cmd argument', function() - eq(true, pcall(_cmd_parts, {"nvim"})) - eq(true, pcall(_cmd_parts, {"nvim", "--head"})) + eq(true, pcall(_cmd_parts, { 'nvim' })) + eq(true, pcall(_cmd_parts, { 'nvim', '--head' })) end) it('should invalid cmd argument', function() - eq('.../lsp.lua:0: cmd: expected list, got nvim', - pcall_err(_cmd_parts, 'nvim')) - eq('.../lsp.lua:0: cmd argument: expected string, got number', - pcall_err(_cmd_parts, {'nvim', 1})) + eq('.../lsp.lua:0: cmd: expected list, got nvim', pcall_err(_cmd_parts, 'nvim')) + eq( + '.../lsp.lua:0: cmd argument: expected string, got number', + pcall_err(_cmd_parts, { 'nvim', 1 }) + ) end) end) end) @@ -151,54 +168,56 @@ describe('LSP', function() describe('basic_init test', function() after_each(function() stop() - exec_lua("lsp.stop_client(lsp.get_clients(), true)") + exec_lua('lsp.stop_client(lsp.get_clients(), true)') exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") end) it('should run correctly', function() local expected_handlers = { - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client, _) -- client is a dummy object which will queue up commands to be run -- once the server initializes. It can't accept lua callbacks or -- other types that may be unserializable for now. client.stop() - end; + end, -- If the program timed out, then code will be nil. on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, -- Note that NIL must be used here. -- on_handler(err, method, result, client_id) on_handler = function(...) - eq(table.remove(expected_handlers), {...}) - end; + eq(table.remove(expected_handlers), { ... }) + end, } end) it('should fail', function() local expected_handlers = { - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client) client.notify('test') client.stop() - end; + end, on_exit = function(code, signal) - eq(101, code, "exit code") -- See fake-lsp-server.lua - eq(0, signal, "exit signal") - assert_log(pesc([[assert_eq failed: left == "\"shutdown\"", right == "\"test\""]]), - fake_lsp_logfile) - end; + eq(101, code, 'exit code') -- See fake-lsp-server.lua + eq(0, signal, 'exit signal') + assert_log( + pesc([[assert_eq failed: left == "\"shutdown\"", right == "\"test\""]]), + fake_lsp_logfile + ) + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) @@ -218,10 +237,12 @@ describe('LSP', function() }) end) - it("should set the client's offset_encoding when positionEncoding capability is supported", function() - clear() - exec_lua(create_server_definition) - local result = exec_lua([[ + it( + "should set the client's offset_encoding when positionEncoding capability is supported", + function() + clear() + exec_lua(create_server_definition) + local result = exec_lua([[ local server = _create_server({ capabilities = { positionEncoding = "utf-8" @@ -243,8 +264,9 @@ describe('LSP', function() end return client.offset_encoding ]]) - eq('utf-8', result) - end) + eq('utf-8', result) + end + ) it('should succeed with manual shutdown', function() if is_ci() then @@ -254,68 +276,68 @@ describe('LSP', function() return end local expected_handlers = { - {NIL, {}, {method="shutdown", bufnr=1, client_id=1}}; - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'shutdown', bufnr = 1, client_id = 1 } }, + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client) eq(0, client.server_capabilities().textDocumentSync.change) client.request('shutdown') client.notify('exit') client.stop() - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) it('should detach buffer in response to nvim_buf_detach', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_finish"; + test_name = 'basic_finish', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) ]] - eq(true, exec_lua("return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")) - eq(true, exec_lua("return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)")) + eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)')) + eq(true, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)')) exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end; + end, on_init = function(_client) client = _client client.notify('finish') - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then - exec_lua("return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)") - eq(false, exec_lua("return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)")) + exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') + eq(false, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)')) client.stop() end - end; + end, } end) it('should fire autocommands on attach and detach', function() local client test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -332,69 +354,75 @@ describe('LSP', function() end, }) ]] - end; + end, on_init = function(_client) client = _client - eq(true, exec_lua("return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")) + eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)')) client.notify('finish') - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'finish' then eq('basic_init', meths.get_var('lsp_attached')) - exec_lua("return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)") + exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') eq('basic_init', meths.get_var('lsp_detached')) client.stop() end - end; + end, } end) it('should set default options on attach', function() local client test_rpc_server { - test_name = "set_defaults_all_capabilities"; + test_name = 'set_defaults_all_capabilities', on_init = function(_client) client = _client exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) ]] - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'test' then - eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc")) - eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc")) - eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr")) - eq('', get_buf_option("keywordprg")) - eq(true, exec_lua[[ + eq('v:lua.vim.lsp.tagfunc', get_buf_option('tagfunc')) + eq('v:lua.vim.lsp.omnifunc', get_buf_option('omnifunc')) + eq('v:lua.vim.lsp.formatexpr()', get_buf_option('formatexpr')) + eq('', get_buf_option('keywordprg')) + eq( + true, + exec_lua [[ local keymap vim.api.nvim_buf_call(BUFFER, function() keymap = vim.fn.maparg("K", "n", false, true) end) return keymap.callback == vim.lsp.buf.hover - ]]) + ]] + ) client.stop() end - end; + end, on_exit = function(_, _) - eq('', get_buf_option("tagfunc")) - eq('', get_buf_option("omnifunc")) - eq('', get_buf_option("formatexpr")) - eq('', exec_lua[[ + eq('', get_buf_option('tagfunc')) + eq('', get_buf_option('omnifunc')) + eq('', get_buf_option('formatexpr')) + eq( + '', + exec_lua [[ local keymap vim.api.nvim_buf_call(BUFFER, function() keymap = vim.fn.maparg("K", "n", false, false) end) return keymap - ]]) - end; + ]] + ) + end, } end) it('should overwrite options set by ftplugins', function() local client test_rpc_server { - test_name = "set_defaults_all_capabilities"; + test_name = 'set_defaults_all_capabilities', on_init = function(_client) client = _client exec_lua [[ @@ -406,35 +434,35 @@ describe('LSP', function() ]] -- Sanity check to ensure that some values are set after setting filetype. - eq('v:lua.require\'man\'.goto_tag', get_buf_option("tagfunc", "BUFFER_1")) - eq('xmlcomplete#CompleteTags', get_buf_option("omnifunc", "BUFFER_2")) - eq('xmlformat#Format()', get_buf_option("formatexpr", "BUFFER_2")) + eq("v:lua.require'man'.goto_tag", get_buf_option('tagfunc', 'BUFFER_1')) + eq('xmlcomplete#CompleteTags', get_buf_option('omnifunc', 'BUFFER_2')) + eq('xmlformat#Format()', get_buf_option('formatexpr', 'BUFFER_2')) exec_lua [[ lsp.buf_attach_client(BUFFER_1, TEST_RPC_CLIENT_ID) lsp.buf_attach_client(BUFFER_2, TEST_RPC_CLIENT_ID) ]] - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'test' then - eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc", "BUFFER_1")) - eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc", "BUFFER_2")) - eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr", "BUFFER_2")) + eq('v:lua.vim.lsp.tagfunc', get_buf_option('tagfunc', 'BUFFER_1')) + eq('v:lua.vim.lsp.omnifunc', get_buf_option('omnifunc', 'BUFFER_2')) + eq('v:lua.vim.lsp.formatexpr()', get_buf_option('formatexpr', 'BUFFER_2')) client.stop() end - end; + end, on_exit = function(_, _) - eq('', get_buf_option("tagfunc", "BUFFER_1")) - eq('', get_buf_option("omnifunc", "BUFFER_2")) - eq('', get_buf_option("formatexpr", "BUFFER_2")) - end; + eq('', get_buf_option('tagfunc', 'BUFFER_1')) + eq('', get_buf_option('omnifunc', 'BUFFER_2')) + eq('', get_buf_option('formatexpr', 'BUFFER_2')) + end, } end) it('should not overwrite user-defined options', function() local client test_rpc_server { - test_name = "set_defaults_all_capabilities"; + test_name = 'set_defaults_all_capabilities', on_init = function(_client) client = _client exec_lua [[ @@ -444,20 +472,20 @@ describe('LSP', function() vim.api.nvim_set_option_value('formatexpr', 'fex', { buf = BUFFER }) lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) ]] - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'test' then - eq('tfu', get_buf_option("tagfunc")) - eq('ofu', get_buf_option("omnifunc")) - eq('fex', get_buf_option("formatexpr")) + eq('tfu', get_buf_option('tagfunc')) + eq('ofu', get_buf_option('omnifunc')) + eq('fex', get_buf_option('formatexpr')) client.stop() end - end; + end, on_exit = function(_, _) - eq('tfu', get_buf_option("tagfunc")) - eq('ofu', get_buf_option("omnifunc")) - eq('fex', get_buf_option("formatexpr")) - end; + eq('tfu', get_buf_option('tagfunc')) + eq('ofu', get_buf_option('omnifunc')) + eq('fex', get_buf_option('formatexpr')) + end, } end) @@ -481,34 +509,40 @@ describe('LSP', function() num_attached_after = num_attached_after, } ]]) - eq(true, result ~= nil, "exec_lua must return result") + eq(true, result ~= nil, 'exec_lua must return result') eq(1, result.num_attached_before) eq(0, result.num_attached_after) end) it('client should return settings via workspace/configuration handler', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, { items = { - { section = "testSetting1" }; - { section = "testSetting2" }; - { section = "test.Setting3" }; - { section = "test.Setting4" }; - }}, { method="workspace/configuration", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { + NIL, + { + items = { + { section = 'testSetting1' }, + { section = 'testSetting2' }, + { section = 'test.Setting3' }, + { section = 'test.Setting4' }, + }, + }, + { method = 'workspace/configuration', client_id = 1 }, + }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "check_workspace_configuration"; + test_name = 'check_workspace_configuration', on_init = function(_client) client = _client - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'start' then exec_lua([=[ local client = vim.lsp.get_client_by_id(TEST_RPC_CLIENT_ID) @@ -519,24 +553,32 @@ describe('LSP', function() }]=]) end if ctx.method == 'workspace/configuration' then - local server_result = exec_lua([=[ + local server_result = exec_lua( + [=[ local method, params = ... - return require'vim.lsp.handlers'['workspace/configuration'](err, params, {method=method, client_id=TEST_RPC_CLIENT_ID})]=], ctx.method, result) + return require'vim.lsp.handlers'['workspace/configuration'](err, params, {method=method, client_id=TEST_RPC_CLIENT_ID})]=], + ctx.method, + result + ) client.notify('workspace/configuration', server_result) end if ctx.method == 'shutdown' then client.stop() end - end; + end, } end) - it('workspace/configuration returns NIL per section if client was started without config.settings', function() - local result = nil - test_rpc_server { - test_name = 'basic_init'; - on_init = function(c) c.stop() end, - on_setup = function() - result = exec_lua [[ + it( + 'workspace/configuration returns NIL per section if client was started without config.settings', + function() + local result = nil + test_rpc_server { + test_name = 'basic_init', + on_init = function(c) + c.stop() + end, + on_setup = function() + result = exec_lua [[ local result = { items = { {section = 'foo'}, @@ -545,52 +587,53 @@ describe('LSP', function() } return vim.lsp.handlers['workspace/configuration'](nil, result, {client_id=TEST_RPC_CLIENT_ID}) ]] - end - } - eq({ NIL, NIL }, result) - end) + end, + } + eq({ NIL, NIL }, result) + end + ) it('should verify capabilities sent', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, } test_rpc_server { - test_name = "basic_check_capabilities"; + test_name = 'basic_check_capabilities', on_init = function(client) client.stop() local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) - eq({includeText = false}, client.server_capabilities().textDocumentSync.save) + eq({ includeText = false }, client.server_capabilities().textDocumentSync.save) eq(false, client.server_capabilities().codeLensProvider) - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) it('BufWritePost sends didSave with bool textDocumentSync.save', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "text_document_sync_save_bool"; + test_name = 'text_document_sync_save_bool', on_init = function(c) client = c - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") - if ctx.method == "start" then + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') + if ctx.method == 'start' then exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) @@ -599,7 +642,7 @@ describe('LSP', function() else client.stop() end - end; + end, } end) @@ -664,7 +707,7 @@ describe('LSP', function() local messages = result.messages eq('textDocument/willSave', messages[3].method) eq('textDocument/willSaveWaitUntil', messages[4].method) - eq({'Hello'}, result.lines) + eq({ 'Hello' }, result.lines) end) it('saveas sends didOpen if filename changed', function() @@ -709,22 +752,22 @@ describe('LSP', function() it('BufWritePost sends didSave including text if server capability is set', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "text_document_sync_save_includeText"; + test_name = 'text_document_sync_save_includeText', on_init = function(c) client = c - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") - if ctx.method == "start" then + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') + if ctx.method == 'start' then exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() vim.api.nvim_buf_set_lines(BUFFER, 0, -1, true, {"help me"}) @@ -734,16 +777,16 @@ describe('LSP', function() else client.stop() end - end; + end, } end) it('client.supports_methods() should validate capabilities', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, } test_rpc_server { - test_name = "capabilities_for_client_supports_method"; + test_name = 'capabilities_for_client_supports_method', on_init = function(client) client.stop() local expected_sync_capabilities = { @@ -761,268 +804,285 @@ describe('LSP', function() eq(true, client.server_capabilities().codeLensProvider.resolveProvider) -- known methods for resolved capabilities - eq(true, client.supports_method("textDocument/hover")) - eq(false, client.supports_method("textDocument/definition")) + eq(true, client.supports_method('textDocument/hover')) + eq(false, client.supports_method('textDocument/definition')) -- unknown methods are assumed to be supported. - eq(true, client.supports_method("unknown-method")) - end; + eq(true, client.supports_method('unknown-method')) + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) it('should not call unsupported_method when trying to call an unsupported method', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, } test_rpc_server { - test_name = "capabilities_for_client_supports_method"; + test_name = 'capabilities_for_client_supports_method', on_setup = function() - exec_lua([=[ + exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) vim.lsp.handlers['textDocument/typeDefinition'] = function() end ]=]) - end; + end, on_init = function(client) client.stop() - exec_lua("vim.lsp.buf.type_definition()") + exec_lua('vim.lsp.buf.type_definition()') exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) - 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}}; - } - test_rpc_server { - test_name = "capabilities_for_client_supports_method"; - on_setup = 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 } }, + } + test_rpc_server { + test_name = 'capabilities_for_client_supports_method', + on_setup = function() exec_lua([=[ vim.lsp.handlers['textDocument/typeDefinition'] = function() end ]=]) - end; - on_init = function(client) - client.stop() - exec_lua("vim.lsp.buf.type_definition()") - end; - on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; - on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; - } - end) + end, + on_init = function(client) + client.stop() + exec_lua('vim.lsp.buf.type_definition()') + end, + on_exit = function(code, signal) + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, + on_handler = function(...) + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, + } + end + ) it('should not forward RequestCancelled to callback', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, } local client test_rpc_server { - test_name = "check_forward_request_cancelled"; + test_name = 'check_forward_request_cancelled', on_init = function(_client) - _client.request("error_code_test") + _client.request('error_code_test') client = _client - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + 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; + 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", bufnr=1, client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, + { { code = -32801 }, NIL, { method = 'error_code_test', bufnr = 1, client_id = 1 } }, } local client test_rpc_server { - test_name = "check_forward_content_modified"; + test_name = 'check_forward_content_modified', on_init = function(_client) - _client.request("error_code_test") + _client.request('error_code_test') client = _client - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, _, ctx}, "expected handler") + 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; + if ctx.method ~= 'finish' then + client.notify('finish') + end + if ctx.method == 'finish' then + client.stop() + end + end, } end) it('should track pending requests to the language server', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="slow_request", bufnr=1, client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } local client test_rpc_server { - test_name = "check_pending_request_tracked"; + test_name = 'check_pending_request_tracked', on_init = function(_client) client = _client - client.request("slow_request") + client.request('slow_request') local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) - eq("slow_request", request.method) - eq("pending", request.type) - client.notify("release") - end; + eq('slow_request', request.method) + eq('pending', request.type) + client.notify('release') + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, {}, ctx }, 'expected handler') if ctx.method == 'slow_request' then local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) eq(NIL, request) - client.notify("finish") + client.notify('finish') end - if ctx.method == 'finish' then client.stop() end - end; + if ctx.method == 'finish' then + client.stop() + end + end, } end) it('should track cancel requests to the language server', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, } local client test_rpc_server { - test_name = "check_cancel_request_tracked"; + test_name = 'check_cancel_request_tracked', on_init = function(_client) client = _client - client.request("slow_request") + client.request('slow_request') client.cancel_request(2) local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) - eq("slow_request", request.method) - eq("cancel", request.type) - client.notify("release") - end; + eq('slow_request', request.method) + eq('cancel', request.type) + client.notify('release') + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, {}, ctx }, 'expected handler') local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) eq(NIL, request) - if ctx.method == 'finish' then client.stop() end - end; + if ctx.method == 'finish' then + client.stop() + end + end, } end) it('should clear pending and cancel requests on reply', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="slow_request", bufnr=1, client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } local client test_rpc_server { - test_name = "check_tracked_requests_cleared"; + test_name = 'check_tracked_requests_cleared', on_init = function(_client) client = _client - client.request("slow_request") + client.request('slow_request') local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) - eq("slow_request", request.method) - eq("pending", request.type) + eq('slow_request', request.method) + eq('pending', request.type) client.cancel_request(2) request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) - eq("slow_request", request.method) - eq("cancel", request.type) - client.notify("release") - end; + eq('slow_request', request.method) + eq('cancel', request.type) + client.notify('release') + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, {}, ctx }, 'expected handler') if ctx.method == 'slow_request' then local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) eq(NIL, request) - client.notify("finish") + client.notify('finish') end - if ctx.method == 'finish' then client.stop() end - end; + if ctx.method == 'finish' then + client.stop() + end + end, } end) it('should trigger LspRequest autocmd when requests table changes', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="slow_request", bufnr=1, client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } local client test_rpc_server { - test_name = "check_tracked_requests_cleared"; + test_name = 'check_tracked_requests_cleared', on_init = function(_client) command('let g:requests = 0') command('autocmd LspRequest * let g:requests+=1') client = _client - client.request("slow_request") + client.request('slow_request') eq(1, eval('g:requests')) client.cancel_request(2) eq(2, eval('g:requests')) - client.notify("release") - end; + client.notify('release') + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') eq(3, eval('g:requests')) - end; + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, {}, ctx }, 'expected handler') if ctx.method == 'slow_request' then - client.notify("finish") + client.notify('finish') end - if ctx.method == 'finish' then client.stop() end - 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}}; - {NIL, {}, {method="finish", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_finish"; + test_name = 'basic_finish', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1031,42 +1091,42 @@ describe('LSP', function() "123"; }) ]] - eq(1, exec_lua("return TEST_RPC_CLIENT_ID")) - eq(true, exec_lua("return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")) - eq(true, exec_lua("return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)")) + eq(1, exec_lua('return TEST_RPC_CLIENT_ID')) + eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)')) + eq(true, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)')) exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end; + end, on_init = function(_client) client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) client.notify('finish') - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body sent attaching before init', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open"; + test_name = 'basic_check_buffer_open', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1078,7 +1138,7 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_init = function(_client) client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") @@ -1087,32 +1147,32 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID), "Already attached, returns true") ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body sent attaching after init', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open"; + test_name = 'basic_check_buffer_open', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1121,7 +1181,7 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") @@ -1130,32 +1190,32 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body and didChange full', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change"; + test_name = 'basic_check_buffer_open_and_change', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1164,7 +1224,7 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") @@ -1173,11 +1233,11 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ @@ -1187,23 +1247,23 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body and didChange full with noeol', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change_noeol"; + test_name = 'basic_check_buffer_open_and_change_noeol', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1213,7 +1273,7 @@ describe('LSP', function() }) vim.bo[BUFFER].eol = false ]] - end; + end, on_init = function(_client) client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") @@ -1222,11 +1282,11 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ @@ -1236,37 +1296,41 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should send correct range for inlay hints with noeol', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, { - method="textDocument/inlayHint", - params = { - textDocument = { - uri = 'file://', + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { + NIL, + {}, + { + method = 'textDocument/inlayHint', + params = { + textDocument = { + uri = 'file://', + }, + range = { + start = { line = 0, character = 0 }, + ['end'] = { line = 1, character = 3 }, + }, }, - range = { - start = { line = 0, character = 0 }, - ['end'] = { line = 1, character = 3 }, - } + bufnr = 2, + client_id = 1, }, - bufnr=2, - client_id=1, - }}; - {NIL, {}, {method="start", client_id=1}}; + }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "inlay_hint"; + test_name = 'inlay_hint', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1276,18 +1340,18 @@ describe('LSP', function() }) vim.bo[BUFFER].eol = false ]] - end; + end, on_init = function(_client) client = _client eq(true, client.supports_method('textDocument/inlayHint')) exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ @@ -1297,26 +1361,26 @@ describe('LSP', function() if ctx.method == 'textDocument/inlayHint' then client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body and didChange incremental', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change_incremental"; + 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) @@ -1325,20 +1389,21 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client - local sync_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Incremental") + local sync_kind = + exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Incremental") eq(sync_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ @@ -1348,26 +1413,26 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body and didChange incremental with debounce', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change_incremental"; + test_name = 'basic_check_buffer_open_and_change_incremental', options = { allow_incremental_sync = true, - debounce_text_changes = 5 - }; + debounce_text_changes = 5, + }, on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1376,20 +1441,21 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client - local sync_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Incremental") + local sync_kind = + exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Incremental") eq(sync_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ @@ -1399,24 +1465,24 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) -- TODO(askhan) we don't support full for now, so we can disable these tests. pending('should check the body and didChange incremental normal mode editing', function() local expected_handlers = { - {NIL, {}, {method="shutdown", bufnr=1, client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', bufnr = 1, client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change_incremental_editing"; + test_name = 'basic_check_buffer_open_and_change_incremental_editing', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1425,42 +1491,43 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client - local sync_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Incremental") + local sync_kind = + exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Incremental") eq(sync_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then - helpers.command("normal! 1Go") + helpers.command('normal! 1Go') client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body and didChange full with 2 changes', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change_multi"; + test_name = 'basic_check_buffer_open_and_change_multi', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1469,7 +1536,7 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client local sync_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") @@ -1478,11 +1545,11 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ @@ -1495,23 +1562,23 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) it('should check the body and didChange full lifecycle', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_check_buffer_open_and_change_multi_and_close"; + test_name = 'basic_check_buffer_open_and_change_multi_and_close', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1520,7 +1587,7 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client local sync_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") @@ -1529,12 +1596,12 @@ describe('LSP', function() exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; - on_handler = function(err, result,ctx) + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, + on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { @@ -1547,55 +1614,58 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) end) - describe("parsing tests", function() + describe('parsing tests', function() it('should handle invalid content-length correctly', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "invalid_header"; - on_setup = function() - end; + test_name = 'invalid_header', + on_setup = function() end, on_init = function(_client) client = _client client.stop(true) - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") - end; + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') + end, } end) it('should not trim vim.NIL from the end of a list', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; - {NIL,{ - arguments = { "EXTRACT_METHOD", {metadata = {}}, 3, 0, 6123, NIL }, - command = "refactor.perform", - title = "EXTRACT_METHOD" - }, {method="workspace/executeCommand", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, + { + NIL, + { + arguments = { 'EXTRACT_METHOD', { metadata = {} }, 3, 0, 6123, NIL }, + command = 'refactor.perform', + title = 'EXTRACT_METHOD', + }, + { method = 'workspace/executeCommand', client_id = 1 }, + }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "decode_nil"; + test_name = 'decode_nil', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -1604,23 +1674,23 @@ describe('LSP', function() "123"; }) ]] - end; + end, on_init = function(_client) client = _client exec_lua [[ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then client.stop() end - end; + end, } end) end) @@ -1634,10 +1704,10 @@ describe('LSP', function() local function make_edit(y_0, x_0, y_1, x_1, text) return { range = { - start = { line = y_0, character = x_0 }; - ["end"] = { line = y_1, character = x_1 }; - }; - newText = type(text) == 'table' and table.concat(text, '\n') or (text or ""); + start = { line = y_0, character = x_0 }, + ['end'] = { line = y_1, character = x_1 }, + }, + newText = type(text) == 'table' and table.concat(text, '\n') or (text or ''), } end @@ -1652,121 +1722,121 @@ describe('LSP', function() end) it('applies simple edits', function() local edits = { - make_edit(0, 0, 0, 0, {"123"}); - make_edit(1, 0, 1, 1, {"2"}); - make_edit(2, 0, 2, 2, {"3"}); - make_edit(3, 2, 3, 4, {""}); + make_edit(0, 0, 0, 0, { '123' }), + make_edit(1, 0, 1, 1, { '2' }), + make_edit(2, 0, 2, 2, { '3' }), + make_edit(3, 2, 3, 4, { '' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - '123First line of text'; - '2econd line of text'; - '3ird line of text'; - 'Foth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + '123First line of text', + '2econd line of text', + '3ird line of text', + 'Foth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) end) it('applies complex edits', function() local edits = { - make_edit(0, 0, 0, 0, {"", "12"}); - make_edit(0, 0, 0, 0, {"3", "foo"}); - make_edit(0, 1, 0, 1, {"bar", "123"}); - make_edit(0, #"First ", 0, #"First line of text", {"guy"}); - make_edit(1, 0, 1, #'Second', {"baz"}); - make_edit(2, #'Th', 2, #"Third", {"e next"}); - make_edit(3, #'', 3, #"Fourth", {"another line of text", "before this"}); - make_edit(3, #'Fourth', 3, #"Fourth line of text", {"!"}); + make_edit(0, 0, 0, 0, { '', '12' }), + make_edit(0, 0, 0, 0, { '3', 'foo' }), + make_edit(0, 1, 0, 1, { 'bar', '123' }), + make_edit(0, #'First ', 0, #'First line of text', { 'guy' }), + make_edit(1, 0, 1, #'Second', { 'baz' }), + make_edit(2, #'Th', 2, #'Third', { 'e next' }), + make_edit(3, #'', 3, #'Fourth', { 'another line of text', 'before this' }), + make_edit(3, #'Fourth', 3, #'Fourth line of text', { '!' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - ''; - '123'; - 'fooFbar'; - '123irst guy'; - 'baz line of text'; - 'The next line of text'; - 'another line of text'; - 'before this!'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + '', + '123', + 'fooFbar', + '123irst guy', + 'baz line of text', + 'The next line of text', + 'another line of text', + 'before this!', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) end) it('applies complex edits (reversed range)', function() local edits = { - make_edit(0, 0, 0, 0, {"", "12"}); - make_edit(0, 0, 0, 0, {"3", "foo"}); - make_edit(0, 1, 0, 1, {"bar", "123"}); - make_edit(0, #"First line of text", 0, #"First ", {"guy"}); - make_edit(1, #'Second', 1, 0, {"baz"}); - make_edit(2, #"Third", 2, #'Th', {"e next"}); - make_edit(3, #"Fourth", 3, #'', {"another line of text", "before this"}); - make_edit(3, #"Fourth line of text", 3, #'Fourth', {"!"}); + make_edit(0, 0, 0, 0, { '', '12' }), + make_edit(0, 0, 0, 0, { '3', 'foo' }), + make_edit(0, 1, 0, 1, { 'bar', '123' }), + make_edit(0, #'First line of text', 0, #'First ', { 'guy' }), + make_edit(1, #'Second', 1, 0, { 'baz' }), + make_edit(2, #'Third', 2, #'Th', { 'e next' }), + make_edit(3, #'Fourth', 3, #'', { 'another line of text', 'before this' }), + make_edit(3, #'Fourth line of text', 3, #'Fourth', { '!' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - ''; - '123'; - 'fooFbar'; - '123irst guy'; - 'baz line of text'; - 'The next line of text'; - 'another line of text'; - 'before this!'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + '', + '123', + 'fooFbar', + '123irst guy', + 'baz line of text', + 'The next line of text', + 'another line of text', + 'before this!', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) end) it('applies non-ASCII characters edits', function() local edits = { - make_edit(4, 3, 4, 4, {"ä"}); + make_edit(4, 3, 4, 4, { 'ä' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Second line of text'; - 'Third line of text'; - 'Fourth line of text'; - 'å ä ɧ 汉语 ↥ 🤦 🦄'; + 'First line of text', + 'Second line of text', + 'Third line of text', + 'Fourth line of text', + 'å ä ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) end) it('applies text edits at the end of the document', function() local edits = { - make_edit(5, 0, 5, 0, "foobar"); + make_edit(5, 0, 5, 0, 'foobar'), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Second line of text'; - 'Third line of text'; - 'Fourth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; - 'foobar'; + 'First line of text', + 'Second line of text', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', + 'foobar', }, buf_lines(1)) end) it('applies multiple text edits at the end of the document', function() local edits = { - make_edit(4, 0, 5, 0, ""); - make_edit(5, 0, 5, 0, "foobar"); + make_edit(4, 0, 5, 0, ''), + make_edit(5, 0, 5, 0, 'foobar'), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Second line of text'; - 'Third line of text'; - 'Fourth line of text'; - 'foobar'; + 'First line of text', + 'Second line of text', + 'Third line of text', + 'Fourth line of text', + 'foobar', }, buf_lines(1)) end) it('it restores marks', function() local edits = { - make_edit(1, 0, 2, 5, "foobar"); - make_edit(4, 0, 5, 0, "barfoo"); + make_edit(1, 0, 2, 5, 'foobar'), + make_edit(4, 0, 5, 0, 'barfoo'), } eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 1, {})')) - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'foobar line of text'; - 'Fourth line of text'; - 'barfoo'; + 'First line of text', + 'foobar line of text', + 'Fourth line of text', + 'barfoo', }, buf_lines(1)) local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")') eq({ 2, 1 }, mark) @@ -1774,16 +1844,16 @@ describe('LSP', function() it('it restores marks to last valid col', function() local edits = { - make_edit(1, 0, 2, 15, "foobar"); - make_edit(4, 0, 5, 0, "barfoo"); + make_edit(1, 0, 2, 15, 'foobar'), + make_edit(4, 0, 5, 0, 'barfoo'), } eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 10, {})')) - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'foobarext'; - 'Fourth line of text'; - 'barfoo'; + 'First line of text', + 'foobarext', + 'Fourth line of text', + 'barfoo', }, buf_lines(1)) local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")') eq({ 2, 9 }, mark) @@ -1791,32 +1861,32 @@ describe('LSP', function() it('it restores marks to last valid line', function() local edits = { - make_edit(1, 0, 4, 5, "foobar"); - make_edit(4, 0, 5, 0, "barfoo"); + make_edit(1, 0, 4, 5, 'foobar'), + make_edit(4, 0, 5, 0, 'barfoo'), } eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 4, 1, {})')) - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'foobaro'; + 'First line of text', + 'foobaro', }, buf_lines(1)) local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")') eq({ 2, 1 }, mark) end) describe('cursor position', function() - it('don\'t fix the cursor if the range contains the cursor', function() + it("don't fix the cursor if the range contains the cursor", function() funcs.nvim_win_set_cursor(0, { 2, 6 }) local edits = { - make_edit(1, 0, 1, 19, 'Second line of text') + make_edit(1, 0, 1, 19, 'Second line of text'), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Second line of text'; - 'Third line of text'; - 'Fourth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + 'First line of text', + 'Second line of text', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) eq({ 2, 6 }, funcs.nvim_win_get_cursor(0)) end) @@ -1825,15 +1895,15 @@ describe('LSP', function() funcs.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), - make_edit(1, 6, 1, 19, '') + make_edit(1, 6, 1, 19, ''), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - ''; - 'Third line of text'; - 'Fourth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + 'First line of text', + '', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) end) @@ -1842,11 +1912,11 @@ describe('LSP', function() funcs.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), - make_edit(0, 18, 5, 0, '') + make_edit(0, 18, 5, 0, ''), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; + 'First line of text', }, buf_lines(1)) eq({ 1, 17 }, funcs.nvim_win_get_cursor(0)) end) @@ -1854,34 +1924,34 @@ describe('LSP', function() it('fix the cursor row', function() funcs.nvim_win_set_cursor(0, { 3, 0 }) local edits = { - make_edit(1, 0, 2, 0, '') + make_edit(1, 0, 2, 0, ''), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Third line of text'; - 'Fourth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + 'First line of text', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) end) it('fix the cursor col', function() -- append empty last line. See #22636 - exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, {''}) + exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, { '' }) funcs.nvim_win_set_cursor(0, { 2, 11 }) local edits = { - make_edit(1, 7, 1, 11, '') + make_edit(1, 7, 1, 11, ''), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Second of text'; - 'Third line of text'; - 'Fourth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; - ''; + 'First line of text', + 'Second of text', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', + '', }, buf_lines(1)) eq({ 2, 7 }, funcs.nvim_win_get_cursor(0)) end) @@ -1889,14 +1959,14 @@ describe('LSP', function() it('fix the cursor row and col', function() funcs.nvim_win_set_cursor(0, { 2, 12 }) local edits = { - make_edit(0, 11, 1, 12, '') + make_edit(0, 11, 1, 12, ''), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ - 'First line of text'; - 'Third line of text'; - 'Fourth line of text'; - 'å å ɧ 汉语 ↥ 🤦 🦄'; + 'First line of text', + 'Third line of text', + 'Fourth line of text', + 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) eq({ 1, 11 }, funcs.nvim_win_get_cursor(0)) end) @@ -1905,24 +1975,24 @@ describe('LSP', function() describe('with LSP end line after what Vim considers to be the end line', function() it('applies edits when the last linebreak is considered a new line', function() local edits = { - make_edit(0, 0, 5, 0, {"All replaced"}); + make_edit(0, 0, 5, 0, { 'All replaced' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") - eq({'All replaced'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') + eq({ 'All replaced' }, buf_lines(1)) end) - it('applies edits when the end line is 2 larger than vim\'s', function() + it("applies edits when the end line is 2 larger than vim's", function() local edits = { - make_edit(0, 0, 6, 0, {"All replaced"}); + make_edit(0, 0, 6, 0, { 'All replaced' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") - eq({'All replaced'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') + eq({ 'All replaced' }, buf_lines(1)) end) it('applies edits with a column offset', function() local edits = { - make_edit(0, 0, 5, 2, {"All replaced"}); + make_edit(0, 0, 5, 2, { 'All replaced' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-16") - eq({'All replaced'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') + eq({ 'All replaced' }, buf_lines(1)) end) end) end) @@ -1936,33 +2006,39 @@ describe('LSP', function() describe('with LSP end column out of bounds and start column at 0', function() it('applies edits at the end of the buffer', function() local edits = { - make_edit(0, 0, 1, 22, {'#include "whatever.h"\r\n#include \r'}); + make_edit(0, 0, 1, 22, { '#include "whatever.h"\r\n#include \r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'#include "whatever.h"', '#include '}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-8') + eq({ '#include "whatever.h"', '#include ' }, buf_lines(1)) end) it('applies edits in the middle of the buffer', function() local edits = { - make_edit(0, 0, 0, 22, {'#include "whatever.h"\r\n#include \r'}); + make_edit(0, 0, 0, 22, { '#include "whatever.h"\r\n#include \r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'#include "whatever.h"', '#include ', 'Test line two 21 char'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-8') + eq( + { '#include "whatever.h"', '#include ', 'Test line two 21 char' }, + buf_lines(1) + ) end) end) describe('with LSP end column out of bounds and start column NOT at 0', function() it('applies edits at the end of the buffer', function() local edits = { - make_edit(0, 2, 1, 22, {'#include "whatever.h"\r\n#include \r'}); + make_edit(0, 2, 1, 22, { '#include "whatever.h"\r\n#include \r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'Te#include "whatever.h"', '#include '}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-8') + eq({ 'Te#include "whatever.h"', '#include ' }, buf_lines(1)) end) it('applies edits in the middle of the buffer', function() local edits = { - make_edit(0, 2, 0, 22, {'#include "whatever.h"\r\n#include \r'}); + make_edit(0, 2, 0, 22, { '#include "whatever.h"\r\n#include \r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'Te#include "whatever.h"', '#include ', 'Test line two 21 char'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-8') + eq( + { 'Te#include "whatever.h"', '#include ', 'Test line two 21 char' }, + buf_lines(1) + ) end) end) end) @@ -1972,12 +2048,12 @@ describe('LSP', function() local text_document_edit = function(editVersion) return { edits = { - make_edit(0, 0, 0, 3, "First ↥ 🤦 🦄") + make_edit(0, 0, 0, 3, 'First ↥ 🤦 🦄'), }, textDocument = { - uri = "file:///fake/uri"; - version = editVersion - } + uri = 'file:///fake/uri', + version = editVersion, + }, } end before_each(function() @@ -1991,49 +2067,63 @@ describe('LSP', function() it('correctly goes ahead with the edit if all is normal', function() exec_lua("vim.lsp.util.apply_text_document_edit(..., nil, 'utf-16')", text_document_edit(5)) eq({ - 'First ↥ 🤦 🦄 line of text'; - '2nd line of 语text'; + 'First ↥ 🤦 🦄 line of text', + '2nd line of 语text', }, buf_lines(target_bufnr)) end) it('always accepts edit with version = 0', function() - exec_lua([[ + exec_lua( + [[ local args = {...} local bufnr = select(1, ...) local text_edit = select(2, ...) vim.lsp.util.buf_versions[bufnr] = 10 vim.lsp.util.apply_text_document_edit(text_edit, nil, 'utf-16') - ]], target_bufnr, text_document_edit(0)) + ]], + target_bufnr, + text_document_edit(0) + ) eq({ - 'First ↥ 🤦 🦄 line of text'; - '2nd line of 语text'; + 'First ↥ 🤦 🦄 line of text', + '2nd line of 语text', }, buf_lines(target_bufnr)) end) it('skips the edit if the version of the edit is behind the local buffer ', function() local apply_edit_mocking_current_version = function(edit, versionedBuf) - exec_lua([[ + exec_lua( + [[ local args = {...} local versionedBuf = args[2] vim.lsp.util.buf_versions[versionedBuf.bufnr] = versionedBuf.currentVersion vim.lsp.util.apply_text_document_edit(args[1], nil, 'utf-16') - ]], edit, versionedBuf) + ]], + edit, + versionedBuf + ) end local baseText = { - '1st line of text'; - '2nd line of 语text'; + '1st line of text', + '2nd line of 语text', } eq(baseText, buf_lines(target_bufnr)) -- Apply an edit for an old version, should skip - apply_edit_mocking_current_version(text_document_edit(2), {currentVersion=7; bufnr=target_bufnr}) + apply_edit_mocking_current_version( + text_document_edit(2), + { currentVersion = 7, bufnr = target_bufnr } + ) eq(baseText, buf_lines(target_bufnr)) -- no change -- Sanity check that next version to current does apply change - apply_edit_mocking_current_version(text_document_edit(8), {currentVersion=7; bufnr=target_bufnr}) + apply_edit_mocking_current_version( + text_document_edit(8), + { currentVersion = 7, bufnr = target_bufnr } + ) eq({ - 'First ↥ 🤦 🦄 line of text'; - '2nd line of 语text'; + 'First ↥ 🤦 🦄 line of text', + '2nd line of 语text', }, buf_lines(target_bufnr)) end) end) @@ -2041,34 +2131,37 @@ describe('LSP', function() describe('workspace_apply_edit', function() it('workspace/applyEdit returns ApplyWorkspaceEditResponse', function() local expected_handlers = { - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client, _) client.stop() - end; + end, -- If the program timed out, then code will be nil. on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, -- Note that NIL must be used here. -- on_handler(err, method, result, client_id) on_handler = function(...) local expected = { - applied = true; - failureReason = nil; + applied = true, + failureReason = nil, } - eq(expected, exec_lua [[ + eq( + expected, + exec_lua [[ local apply_edit = { label = nil; edit = {}; } return vim.lsp.handlers['workspace/applyEdit'](nil, apply_edit, {client_id = TEST_RPC_CLIENT_ID}) - ]]) - eq(table.remove(expected_handlers), {...}) - end; + ]] + ) + eq(table.remove(expected_handlers), { ... }) + end, } end) end) @@ -2078,12 +2171,12 @@ describe('LSP', function() return { edits = { -- NOTE: This is a hack if you have a line longer than 1000 it won't replace it - make_edit(row, 0, row, 1000, new_line) + make_edit(row, 0, row, 1000, new_line), }, textDocument = { - uri = "file:///fake/uri"; - version = editVersion - } + uri = 'file:///fake/uri', + version = editVersion, + }, } end @@ -2091,7 +2184,7 @@ describe('LSP', function() -- We should not stop applying the edits local make_workspace_edit = function(changes) return { - documentChanges = changes + documentChanges = changes, } end @@ -2127,7 +2220,7 @@ describe('LSP', function() it('apply_workspace_edit applies a single edit', function() local new_lines = { - "First Line", + 'First Line', } local edits = {} @@ -2135,10 +2228,13 @@ describe('LSP', function() table.insert(edits, replace_line_edit(row - 1, line, changedtick)) end - eq({ - "First Line", - "Original Line #2", - }, exec_lua([[ + eq( + { + 'First Line', + 'Original Line #2', + }, + exec_lua( + [[ local args = {...} local workspace_edits = args[1] local target_bufnr = args[2] @@ -2146,13 +2242,17 @@ describe('LSP', function() vim.lsp.util.apply_workspace_edit(workspace_edits, 'utf-16') return vim.api.nvim_buf_get_lines(target_bufnr, 0, -1, false) - ]], make_workspace_edit(edits), target_bufnr)) + ]], + make_workspace_edit(edits), + target_bufnr + ) + ) end) it('apply_workspace_edit applies multiple edits', function() local new_lines = { - "First Line", - "Second Line", + 'First Line', + 'Second Line', } local edits = {} @@ -2160,7 +2260,10 @@ describe('LSP', function() table.insert(edits, replace_line_edit(row - 1, line, changedtick)) end - eq(new_lines, exec_lua([[ + eq( + new_lines, + exec_lua( + [[ local args = {...} local workspace_edits = args[1] local target_bufnr = args[2] @@ -2168,7 +2271,11 @@ describe('LSP', function() vim.lsp.util.apply_workspace_edit(workspace_edits, 'utf-16') return vim.api.nvim_buf_get_lines(target_bufnr, 0, -1, false) - ]], make_workspace_edit(edits), target_bufnr)) + ]], + make_workspace_edit(edits), + target_bufnr + ) + ) end) it('Supports file creation with CreateFile payload', function() local tmpfile = helpers.tmpname() @@ -2180,27 +2287,30 @@ describe('LSP', function() kind = 'create', uri = uri, }, - } + }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) end) - it('Supports file creation in folder that needs to be created with CreateFile payload', function() - local tmpfile = helpers.tmpname() - os.remove(tmpfile) -- Should not exist, only interested in a tmpname - tmpfile = tmpfile .. '/dummy/x/' - local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) - local edit = { - documentChanges = { - { - kind = 'create', - uri = uri, + it( + 'Supports file creation in folder that needs to be created with CreateFile payload', + function() + local tmpfile = helpers.tmpname() + os.remove(tmpfile) -- Should not exist, only interested in a tmpname + tmpfile = tmpfile .. '/dummy/x/' + local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) + local edit = { + documentChanges = { + { + kind = 'create', + uri = uri, + }, }, } - } - exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) - end) + exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') + eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) + end + ) it('createFile does not touch file if it exists and ignoreIfExists is set', function() local tmpfile = helpers.tmpname() write_file(tmpfile, 'Dummy content') @@ -2214,7 +2324,7 @@ describe('LSP', function() ignoreIfExists = true, }, }, - } + }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) @@ -2234,7 +2344,7 @@ describe('LSP', function() ignoreIfExists = true, -- overwrite must win over ignoreIfExists }, }, - } + }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) @@ -2243,19 +2353,22 @@ describe('LSP', function() it('DeleteFile delete file and buffer', function() local tmpfile = helpers.tmpname() write_file(tmpfile, 'Be gone') - local uri = exec_lua([[ + local uri = exec_lua( + [[ local fname = select(1, ...) local bufnr = vim.fn.bufadd(fname) vim.fn.bufload(bufnr) return vim.uri_from_fname(fname) - ]], tmpfile) + ]], + tmpfile + ) local edit = { documentChanges = { { kind = 'delete', uri = uri, - } - } + }, + }, } eq(true, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')) eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) @@ -2272,9 +2385,9 @@ describe('LSP', function() uri = uri, options = { ignoreIfNotExists = false, - } - } - } + }, + }, + }, } eq(false, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit)) eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) @@ -2288,8 +2401,9 @@ describe('LSP', function() local old = helpers.tmpname() write_file(old, 'Test content') local new = helpers.tmpname() - os.remove(new) -- only reserve the name, file must not exist for the test scenario - local lines = exec_lua([[ + os.remove(new) -- only reserve the name, file must not exist for the test scenario + local lines = exec_lua( + [[ local old = select(1, ...) local new = select(2, ...) vim.lsp.util.rename(old, new) @@ -2298,26 +2412,33 @@ describe('LSP', function() local bufnr = vim.fn.bufadd(new) vim.fn.bufload(new) return vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) - ]], old, new) - eq({'Test content'}, lines) + ]], + old, + new + ) + eq({ 'Test content' }, lines) local exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', old) eq(false, exists) exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', new) eq(true, exists) os.remove(new) end) - it("Kills old buffer after renaming an existing file", function() + it('Kills old buffer after renaming an existing file', function() local old = helpers.tmpname() write_file(old, 'Test content') local new = helpers.tmpname() - os.remove(new) -- only reserve the name, file must not exist for the test scenario - local lines = exec_lua([[ + os.remove(new) -- only reserve the name, file must not exist for the test scenario + local lines = exec_lua( + [[ local old = select(1, ...) local oldbufnr = vim.fn.bufadd(old) local new = select(2, ...) vim.lsp.util.rename(old, new) return vim.fn.bufloaded(oldbufnr) - ]], old, new) + ]], + old, + new + ) eq(0, lines) os.remove(new) end) @@ -2333,7 +2454,8 @@ describe('LSP', function() local file = 'file.txt' write_file(old_dir .. pathsep .. file, 'Test content') - local lines = exec_lua([[ + local lines = exec_lua( + [[ local old_dir = select(1, ...) local new_dir = select(2, ...) local pathsep = select(3, ...) @@ -2341,7 +2463,11 @@ describe('LSP', function() vim.lsp.util.rename(old_dir, new_dir) return vim.fn.bufloaded(oldbufnr) - ]], old_dir, new_dir, pathsep) + ]], + old_dir, + new_dir, + pathsep + ) eq(0, lines) eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old_dir)) eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir)) @@ -2350,43 +2476,58 @@ describe('LSP', function() os.remove(new_dir) end) - it('Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() - local old = helpers.tmpname() - write_file(old, 'Old File') - local new = helpers.tmpname() - write_file(new, 'New file') + it( + 'Does not rename file if target exists and ignoreIfExists is set or overwrite is false', + function() + local old = helpers.tmpname() + write_file(old, 'Old File') + local new = helpers.tmpname() + write_file(new, 'New file') - exec_lua([[ + exec_lua( + [[ local old = select(1, ...) local new = select(2, ...) vim.lsp.util.rename(old, new, { ignoreIfExists = true }) - ]], old, new) + ]], + old, + new + ) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) - eq('New file', read_file(new)) + eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) + eq('New file', read_file(new)) - exec_lua([[ + exec_lua( + [[ local old = select(1, ...) local new = select(2, ...) vim.lsp.util.rename(old, new, { overwrite = false }) - ]], old, new) + ]], + old, + new + ) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) - eq('New file', read_file(new)) - end) + eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) + eq('New file', read_file(new)) + end + ) it('Does override target if overwrite is true', function() local old = helpers.tmpname() write_file(old, 'Old file') local new = helpers.tmpname() write_file(new, 'New file') - exec_lua([[ + exec_lua( + [[ local old = select(1, ...) local new = select(2, ...) vim.lsp.util.rename(old, new, { overwrite = true }) - ]], old, new) + ]], + old, + new + ) eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) @@ -2407,8 +2548,8 @@ describe('LSP', function() range = { start = { line = 0, character = 2 }, ['end'] = { line = 0, character = 3 }, - } - } + }, + }, }, } local actual = exec_lua [[ @@ -2436,7 +2577,7 @@ describe('LSP', function() col = 3, text = 'testing', user_data = { - targetUri = "file:///fake/uri", + targetUri = 'file:///fake/uri', targetRange = { start = { line = 0, character = 2 }, ['end'] = { line = 0, character = 3 }, @@ -2444,8 +2585,8 @@ describe('LSP', function() targetSelectionRange = { start = { line = 0, character = 2 }, ['end'] = { line = 0, character = 3 }, - } - } + }, + }, }, } local actual = exec_lua [[ @@ -2479,24 +2620,26 @@ describe('LSP', function() filename = '', kind = 'File', lnum = 2, - text = '[File] TestA' + text = '[File] TestA', }, { col = 1, filename = '', kind = 'Module', lnum = 4, - text = '[Module] TestB' + text = '[Module] TestB', }, { col = 1, filename = '', kind = 'Namespace', lnum = 6, - text = '[Namespace] TestC' - } + text = '[Namespace] TestC', + }, } - eq(expected, exec_lua [[ + eq( + expected, + exec_lua [[ local doc_syms = { { deprecated = false, @@ -2581,7 +2724,8 @@ describe('LSP', function() } } return vim.lsp.util.symbols_to_items(doc_syms, nil) - ]]) + ]] + ) end) it('DocumentSymbol has no children', function() local expected = { @@ -2590,17 +2734,19 @@ describe('LSP', function() filename = '', kind = 'File', lnum = 2, - text = '[File] TestA' + text = '[File] TestA', }, { col = 1, filename = '', kind = 'Namespace', lnum = 6, - text = '[Namespace] TestC' - } + text = '[Namespace] TestC', + }, } - eq(expected, exec_lua [[ + eq( + expected, + exec_lua [[ local doc_syms = { { deprecated = false, @@ -2656,27 +2802,30 @@ describe('LSP', function() } } return vim.lsp.util.symbols_to_items(doc_syms, nil) - ]]) + ]] + ) end) end) it('convert SymbolInformation[] to items', function() - local expected = { - { - col = 1, - filename = '/test_a', - kind = 'File', - lnum = 2, - text = '[File] TestA' - }, - { - col = 1, - filename = '/test_b', - kind = 'Module', - lnum = 4, - text = '[Module] TestB' - } - } - eq(expected, exec_lua [[ + local expected = { + { + col = 1, + filename = '/test_a', + kind = 'File', + lnum = 2, + text = '[File] TestA', + }, + { + col = 1, + filename = '/test_b', + kind = 'Module', + lnum = 4, + text = '[Module] TestB', + }, + } + eq( + expected, + exec_lua [[ local sym_info = { { deprecated = false, @@ -2718,19 +2867,20 @@ describe('LSP', function() } } return vim.lsp.util.symbols_to_items(sym_info, nil) - ]]) + ]] + ) end) end) describe('lsp.util._get_symbol_kind_name', function() it('returns the name specified by protocol', function() - eq("File", exec_lua("return vim.lsp.util._get_symbol_kind_name(1)")) - eq("TypeParameter", exec_lua("return vim.lsp.util._get_symbol_kind_name(26)")) + eq('File', exec_lua('return vim.lsp.util._get_symbol_kind_name(1)')) + eq('TypeParameter', exec_lua('return vim.lsp.util._get_symbol_kind_name(26)')) end) it('returns the name not specified by protocol', function() - eq("Unknown", exec_lua("return vim.lsp.util._get_symbol_kind_name(nil)")) - eq("Unknown", exec_lua("return vim.lsp.util._get_symbol_kind_name(vim.NIL)")) - eq("Unknown", exec_lua("return vim.lsp.util._get_symbol_kind_name(1000)")) + eq('Unknown', exec_lua('return vim.lsp.util._get_symbol_kind_name(nil)')) + eq('Unknown', exec_lua('return vim.lsp.util._get_symbol_kind_name(vim.NIL)')) + eq('Unknown', exec_lua('return vim.lsp.util._get_symbol_kind_name(1000)')) end) end) @@ -2748,20 +2898,20 @@ describe('LSP', function() local location = function(start_line, start_char, end_line, end_char) return { - uri = "file:///fake/uri", + uri = 'file:///fake/uri', range = { start = { line = start_line, character = start_char }, - ["end"] = { line = end_line, character = end_char }, + ['end'] = { line = end_line, character = end_char }, }, } end local jump = function(msg) - eq(true, exec_lua('return vim.lsp.util.jump_to_location(...)', msg, "utf-16")) - eq(target_bufnr, exec_lua[[return vim.fn.bufnr('%')]]) + eq(true, exec_lua('return vim.lsp.util.jump_to_location(...)', msg, 'utf-16')) + eq(target_bufnr, exec_lua [[return vim.fn.bufnr('%')]]) return { - line = exec_lua[[return vim.fn.line('.')]], - col = exec_lua[[return vim.fn.col('.')]], + line = exec_lua [[return vim.fn.line('.')]], + col = exec_lua [[return vim.fn.col('.')]], } end @@ -2773,16 +2923,16 @@ describe('LSP', function() it('jumps to a LocationLink', function() local pos = jump({ - targetUri = "file:///fake/uri", - targetSelectionRange = { - start = { line = 0, character = 4 }, - ["end"] = { line = 0, character = 4 }, - }, - targetRange = { - start = { line = 1, character = 5 }, - ["end"] = { line = 1, character = 5 }, - }, - }) + targetUri = 'file:///fake/uri', + targetSelectionRange = { + start = { line = 0, character = 4 }, + ['end'] = { line = 0, character = 4 }, + }, + targetRange = { + start = { line = 1, character = 5 }, + ['end'] = { line = 1, character = 5 }, + }, + }) eq(1, pos.line) eq(5, pos.col) end) @@ -2791,7 +2941,7 @@ describe('LSP', function() local pos = jump(location(1, 2, 1, 2)) eq(2, pos.line) eq(4, pos.col) - eq('å', exec_lua[[return vim.fn.expand('')]]) + eq('å', exec_lua [[return vim.fn.expand('')]]) end) it('adds current position to jumplist before jumping', function() @@ -3004,11 +3154,14 @@ describe('LSP', function() end) it('calculates size correctly', function() - eq({19,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]]) + eq({ 19, 3 }, exec_lua [[ return {vim.lsp.util._make_floating_popup_size(contents)} ]]) end) it('calculates size correctly with wrapping', function() - eq({15,5}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents,{width = 15, wrap_at = 14})} ]]) + eq( + { 15, 5 }, + exec_lua [[ return {vim.lsp.util._make_floating_popup_size(contents,{width = 15, wrap_at = 14})} ]] + ) end) it('handles NUL bytes in text', function() @@ -3018,21 +3171,24 @@ describe('LSP', function() '\020\021\022\023\024\025\026\027\028\029', } ]]) command('set list listchars=') - eq({20,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]]) + eq({ 20, 3 }, exec_lua [[ return {vim.lsp.util._make_floating_popup_size(contents)} ]]) command('set display+=uhex') - eq({40,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]]) + eq({ 40, 3 }, exec_lua [[ return {vim.lsp.util._make_floating_popup_size(contents)} ]]) end) end) describe('lsp.util.trim.trim_empty_lines', function() it('properly trims empty lines', function() - eq({{"foo", "bar"}}, exec_lua[[ return vim.lsp.util.trim_empty_lines({{ "foo", "bar" }, nil}) ]]) + eq( + { { 'foo', 'bar' } }, + exec_lua [[ return vim.lsp.util.trim_empty_lines({{ "foo", "bar" }, nil}) ]] + ) end) end) describe('lsp.util.convert_signature_help_to_markdown_lines', function() it('can handle negative activeSignature', function() - local result = exec_lua[[ + local result = exec_lua [[ local signature_help = { activeParameter = 0, activeSignature = -1, @@ -3046,22 +3202,29 @@ describe('LSP', function() } return vim.lsp.util.convert_signature_help_to_markdown_lines(signature_help, 'cs', {','}) ]] - local expected = {'```cs', 'TestEntity.TestEntity()', '```', 'some doc'} + local expected = { '```cs', 'TestEntity.TestEntity()', '```', 'some doc' } eq(expected, result) end) end) describe('lsp.util.get_effective_tabstop', function() local function test_tabstop(tabsize, shiftwidth) - exec_lua(string.format([[ + exec_lua(string.format( + [[ vim.bo.shiftwidth = %d vim.bo.tabstop = 2 - ]], shiftwidth)) + ]], + shiftwidth + )) eq(tabsize, exec_lua('return vim.lsp.util.get_effective_tabstop()')) end - it('with shiftwidth = 1', function() test_tabstop(1, 1) end) - it('with shiftwidth = 0', function() test_tabstop(2, 0) end) + it('with shiftwidth = 1', function() + test_tabstop(1, 1) + end) + it('with shiftwidth = 0', function() + test_tabstop(2, 0) + end) end) describe('vim.lsp.buf.outgoing_calls', function() @@ -3118,20 +3281,22 @@ describe('LSP', function() return vim.fn.getqflist() ]=]) - local expected = { { - bufnr = 2, - col = 5, - end_col = 0, - lnum = 4, - end_lnum = 0, - module = "", - nr = 0, - pattern = "", - text = "foo", - type = "", - valid = 1, - vcol = 0 - } } + local expected = { + { + bufnr = 2, + col = 5, + end_col = 0, + lnum = 4, + end_lnum = 0, + module = '', + nr = 0, + pattern = '', + text = 'foo', + type = '', + valid = 1, + vcol = 0, + }, + } eq(expected, qflist) end) @@ -3192,20 +3357,22 @@ describe('LSP', function() return vim.fn.getqflist() ]=]) - local expected = { { - bufnr = 2, - col = 5, - end_col = 0, - lnum = 4, - end_lnum = 0, - module = "", - nr = 0, - pattern = "", - text = "main", - type = "", - valid = 1, - vcol = 0 - } } + local expected = { + { + bufnr = 2, + col = 5, + end_col = 0, + lnum = 4, + end_lnum = 0, + module = '', + nr = 0, + pattern = '', + text = 'main', + type = '', + valid = 1, + vcol = 0, + }, + } eq(expected, qflist) end) @@ -3214,52 +3381,52 @@ describe('LSP', function() describe('vim.lsp.buf.rename', function() for _, test in ipairs({ { - it = "does not attempt to rename on nil response", - name = "prepare_rename_nil", + it = 'does not attempt to rename on nil response', + name = 'prepare_rename_nil', expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, }, }, { - it = "handles prepareRename placeholder response", - name = "prepare_rename_placeholder", + it = 'handles prepareRename placeholder response', + name = 'prepare_rename_placeholder', expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, NIL, {method="textDocument/rename", client_id=1, bufnr=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, NIL, { method = 'textDocument/rename', client_id = 1, bufnr = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, }, - expected_text = "placeholder", -- see fake lsp response + expected_text = 'placeholder', -- see fake lsp response }, { - it = "handles range response", - name = "prepare_rename_range", + it = 'handles range response', + name = 'prepare_rename_range', expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, NIL, {method="textDocument/rename", client_id=1, bufnr=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, NIL, { method = 'textDocument/rename', client_id = 1, bufnr = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, }, - expected_text = "line", -- see test case and fake lsp response + expected_text = 'line', -- see test case and fake lsp response }, { - it = "handles error", - name = "prepare_rename_error", + it = 'handles error', + name = 'prepare_rename_error', expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, }, }, }) do - it(test.it, function() - local client - test_rpc_server { - test_name = test.name; - on_init = function(_client) - client = _client - eq(true, client.server_capabilities().renameProvider.prepareProvider) - end; - on_setup = function() - exec_lua([=[ + it(test.it, function() + local client + test_rpc_server { + test_name = test.name, + on_init = function(_client) + client = _client + eq(true, client.server_capabilities().renameProvider.prepareProvider) + end, + on_setup = function() + exec_lua([=[ local bufnr = vim.api.nvim_get_current_buf() lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID) vim.lsp._stubs = {} @@ -3271,31 +3438,31 @@ describe('LSP', function() vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'', 'this is line two'}) vim.fn.cursor(2, 13) -- the space between "line" and "two" ]=]) - end; - on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; - on_handler = function(err, result, ctx) - -- Don't compare & assert params and version, they're not relevant for the testcase - -- This allows us to be lazy and avoid declaring them - ctx.params = nil - ctx.version = nil - - eq(table.remove(test.expected_handlers), {err, result, ctx}, "expected handler") - if ctx.method == 'start' then - exec_lua("vim.lsp.buf.rename()") - end - if ctx.method == 'shutdown' then - if test.expected_text then - eq("New Name: ", exec_lua("return vim.lsp._stubs.input_prompt")) - eq(test.expected_text, exec_lua("return vim.lsp._stubs.input_text")) + end, + on_exit = function(code, signal) + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, + on_handler = function(err, result, ctx) + -- Don't compare & assert params and version, they're not relevant for the testcase + -- This allows us to be lazy and avoid declaring them + ctx.params = nil + ctx.version = nil + + eq(table.remove(test.expected_handlers), { err, result, ctx }, 'expected handler') + if ctx.method == 'start' then + exec_lua('vim.lsp.buf.rename()') end - client.stop() - end - end; - } - end) + if ctx.method == 'shutdown' then + if test.expected_text then + eq('New Name: ', exec_lua('return vim.lsp._stubs.input_prompt')) + eq(test.expected_text, exec_lua('return vim.lsp._stubs.input_text')) + end + client.stop() + end + end, + } + end) end end) @@ -3303,22 +3470,21 @@ describe('LSP', function() it('Calls client side command if available', function() local client local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } test_rpc_server { test_name = 'code_action_with_resolve', on_init = function(client_) client = client_ end, - on_setup = function() - end, + on_setup = function() end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}) + eq(table.remove(expected_handlers), { err, result, ctx }) if ctx.method == 'start' then exec_lua([[ vim.lsp.commands['dummy1'] = function(cmd) @@ -3333,10 +3499,10 @@ describe('LSP', function() vim.lsp.buf.code_action() ]]) elseif ctx.method == 'shutdown' then - eq('function', exec_lua[[return type(vim.lsp.commands['dummy2'])]]) + eq('function', exec_lua [[return type(vim.lsp.commands['dummy2'])]]) client.stop() end - end + end, } end) it('Calls workspace/executeCommand if no client side command', function() @@ -3382,22 +3548,21 @@ describe('LSP', function() it('Filters and automatically applies action if requested', function() local client local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } test_rpc_server { test_name = 'code_action_filter', on_init = function(client_) client = client_ end, - on_setup = function() - end, + on_setup = function() end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}) + eq(table.remove(expected_handlers), { err, result, ctx }) if ctx.method == 'start' then exec_lua([[ vim.lsp.commands['preferred_command'] = function(cmd) @@ -3428,15 +3593,15 @@ describe('LSP', function() }) ]]) elseif ctx.method == 'shutdown' then - eq('function', exec_lua[[return type(vim.lsp.commands['executed_preferred'])]]) - eq('function', exec_lua[[return type(vim.lsp.commands['filtered_type_annotate_foo'])]]) - eq('function', exec_lua[[return type(vim.lsp.commands['executed_type_annotate'])]]) + eq('function', exec_lua [[return type(vim.lsp.commands['executed_preferred'])]]) + eq('function', exec_lua [[return type(vim.lsp.commands['filtered_type_annotate_foo'])]]) + eq('function', exec_lua [[return type(vim.lsp.commands['executed_type_annotate'])]]) client.stop() end - end + end, } end) - it("Fallback to command execution on resolve error", function() + it('Fallback to command execution on resolve error', function() clear() exec_lua(create_server_definition) local result = exec_lua([[ @@ -3476,9 +3641,9 @@ describe('LSP', function() vim.lsp.stop_client(client_id) return server.messages ]]) - eq("codeAction/resolve", result[4].method) - eq("workspace/executeCommand", result[5].method) - eq("command:1", result[5].params.command) + eq('codeAction/resolve', result[4].method) + eq('workspace/executeCommand', result[5].method) + eq('command:1', result[5].params.command) end) end) describe('vim.lsp.commands', function() @@ -3499,25 +3664,25 @@ describe('LSP', function() it('uses client commands', function() local client local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } test_rpc_server { test_name = 'clientside_commands', on_init = function(client_) client = client_ end, - on_setup = function() - end, + on_setup = function() end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}) + eq(table.remove(expected_handlers), { err, result, ctx }) if ctx.method == 'start' then - local fake_uri = "file:///fake/uri" - local cmd = exec_lua([[ + local fake_uri = 'file:///fake/uri' + local cmd = exec_lua( + [[ fake_uri = ... local bufnr = vim.uri_to_bufnr(fake_uri) vim.fn.bufload(bufnr) @@ -3539,20 +3704,22 @@ describe('LSP', function() vim.api.nvim_set_current_buf(bufnr) vim.lsp.codelens.run() return cmd_called - ]], fake_uri) - eq({ command = 'Dummy', title = 'Lens1' }, cmd) - elseif ctx.method == 'shutdown' then - client.stop() + ]], + fake_uri + ) + eq({ command = 'Dummy', title = 'Lens1' }, cmd) + elseif ctx.method == 'shutdown' then + client.stop() end - end + end, } end) it('releases buffer refresh lock', function() local client local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } test_rpc_server { test_name = 'codelens_refresh_lock', @@ -3576,11 +3743,11 @@ describe('LSP', function() ]=]) end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}) + eq(table.remove(expected_handlers), { err, result, ctx }) if ctx.method == 'start' then -- 1. first codelens request errors local response = exec_lua([=[ @@ -3589,7 +3756,7 @@ describe('LSP', function() vim.wait(100, function () return CALLED end) return RESPONSE ]=]) - eq( { err = { code = -32002, message = "ServerNotInitialized" } }, response) + eq({ err = { code = -32002, message = 'ServerNotInitialized' } }, response) -- 2. second codelens request runs response = exec_lua([=[ @@ -3604,7 +3771,7 @@ describe('LSP', function() vim.wait(100, function () return cmd_called end) return cmd_called ]=]) - eq( { command = "Dummy", title = "Lens1" }, response) + eq({ command = 'Dummy', title = 'Lens1' }, response) -- 3. third codelens request runs response = exec_lua([=[ @@ -3619,20 +3786,20 @@ describe('LSP', function() vim.wait(100, function () return cmd_called end) return cmd_called ]=]) - eq( { command = "Dummy", title = "Lens2" }, response) - elseif ctx.method == 'shutdown' then - client.stop() + eq({ command = 'Dummy', title = 'Lens2' }, response) + elseif ctx.method == 'shutdown' then + client.stop() end - end + end, } end) end) - describe("vim.lsp.buf.format", function() - it("Aborts with notify if no client matches filter", function() + describe('vim.lsp.buf.format', function() + it('Aborts with notify if no client matches filter', function() local client test_rpc_server { - test_name = "basic_init", + test_name = 'basic_init', on_init = function(c) client = c end, @@ -3649,25 +3816,25 @@ describe('LSP', function() vim.notify = notify return notify_msg ]]) - eq("[LSP] Format request failed, no matching language servers.", notify_msg) + eq('[LSP] Format request failed, no matching language servers.', notify_msg) client.stop() end, } end) - it("Sends textDocument/formatting request to format buffer", function() + it('Sends textDocument/formatting request to format buffer', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_formatting", + test_name = 'basic_formatting', on_init = function(c) client = c end, on_handler = function(_, _, ctx) table.remove(expected_handlers) - if ctx.method == "start" then + if ctx.method == 'start' then local notify_msg = exec_lua([[ local bufnr = vim.api.nvim_get_current_buf() vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID) @@ -3681,7 +3848,7 @@ describe('LSP', function() return notify_msg ]]) eq(NIL, notify_msg) - elseif ctx.method == "shutdown" then + elseif ctx.method == 'shutdown' then client.stop() end end, @@ -3689,18 +3856,18 @@ describe('LSP', function() end) it('Can format async', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_formatting", + test_name = 'basic_formatting', on_init = function(c) client = c end, on_handler = function(_, _, ctx) table.remove(expected_handlers) - if ctx.method == "start" then + if ctx.method == 'start' then local result = exec_lua([[ local bufnr = vim.api.nvim_get_current_buf() vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID) @@ -3724,8 +3891,8 @@ describe('LSP', function() vim.lsp.handlers['textDocument/formatting'] = handler return {notify = notify_msg, handler_called = handler_called} ]]) - eq({handler_called=true}, result) - elseif ctx.method == "shutdown" then + eq({ handler_called = true }, result) + elseif ctx.method == 'shutdown' then client.stop() end end, @@ -3749,7 +3916,7 @@ describe('LSP', function() vim.lsp.stop_client(client_id) return server.messages ]]) - eq("textDocument/rangeFormatting", result[3].method) + eq('textDocument/rangeFormatting', result[3].method) local expected_range = { start = { line = 0, character = 0 }, ['end'] = { line = 1, character = 4 }, @@ -3784,16 +3951,21 @@ describe('LSP', function() return server.messages ]]) local expected_methods = { - "initialize", - "initialized", - "textDocument/rangeFormatting", - "$/cancelRequest", - "textDocument/rangeFormatting", - "$/cancelRequest", - "shutdown", - "exit", + 'initialize', + 'initialized', + 'textDocument/rangeFormatting', + '$/cancelRequest', + 'textDocument/rangeFormatting', + '$/cancelRequest', + 'shutdown', + 'exit', } - eq(expected_methods, vim.tbl_map(function(x) return x.method end, result)) + eq( + expected_methods, + vim.tbl_map(function(x) + return x.method + end, result) + ) -- uses first column of start line and last column of end line local expected_range = { start = { line = 0, character = 0 }, @@ -3809,10 +3981,11 @@ describe('LSP', function() notify_msg = msg end ]]) - local fail_msg = "[LSP] Format request failed, no matching language servers." + local fail_msg = '[LSP] Format request failed, no matching language servers.' local function check_notify(name, formatting, range_formatting) - local timeout_msg = "[LSP][" .. name .. "] timeout" - exec_lua([[ + local timeout_msg = '[LSP][' .. name .. '] timeout' + exec_lua( + [[ local formatting, range_formatting, name = ... local server = _create_server({ capabilities = { documentFormattingProvider = formatting, @@ -3821,7 +3994,11 @@ describe('LSP', function() vim.lsp.start({ name = name, cmd = server.cmd }) notify_msg = nil vim.lsp.buf.format({ name = name, timeout_ms = 1 }) - ]], formatting, range_formatting, name) + ]], + formatting, + range_formatting, + name + ) eq(formatting and timeout_msg or fail_msg, exec_lua('return notify_msg')) exec_lua([[ notify_msg = nil @@ -3829,10 +4006,10 @@ describe('LSP', function() ]]) eq(range_formatting and timeout_msg or fail_msg, exec_lua('return notify_msg')) end - check_notify("none", false, false) - check_notify("formatting", true, false) - check_notify("rangeFormatting", false, true) - check_notify("both", true, true) + check_notify('none', false, false) + check_notify('formatting', true, false) + check_notify('rangeFormatting', false, true) + check_notify('both', true, true) end) end) describe('cmd', function() @@ -3859,17 +4036,18 @@ describe('LSP', function() server:shutdown() return vim.json.decode(init) ]] - eq(result.method, "initialize") + eq(result.method, 'initialize') end) it('can connect to lsp server via rpc.domain_socket_connect', function() local tmpfile - if is_os("win") then - tmpfile = "\\\\.\\\\pipe\\pipe.test" - else + if is_os('win') then + tmpfile = '\\\\.\\\\pipe\\pipe.test' + else tmpfile = helpers.tmpname() os.remove(tmpfile) end - local result = exec_lua([[ + local result = exec_lua( + [[ local SOCK = ... local uv = vim.uv local server = uv.new_pipe(false) @@ -3891,8 +4069,10 @@ describe('LSP', function() server:close() server:shutdown() return vim.json.decode(init) - ]], tmpfile) - eq(result.method, "initialize") + ]], + tmpfile + ) + eq(result.method, 'initialize') end) end) @@ -3959,9 +4139,9 @@ describe('LSP', function() { id = 10, jsonrpc = '2.0', - result = false - } - } + result = false, + }, + }, } eq(expected, result) end) @@ -3980,7 +4160,8 @@ describe('LSP', function() end exec_lua(create_server_definition) - local result = exec_lua([[ + local result = exec_lua( + [[ local root_dir, tmpfile = ... local server = _create_server() @@ -4063,26 +4244,30 @@ describe('LSP', function() check("textDocument/completion") return result - ]], root_dir, tmpfile) + ]], + root_dir, + tmpfile + ) eq(5, #result) - eq({method = 'textDocument/formatting', supported = false}, result[1]) - eq({method = 'textDocument/formatting', supported = true, fname = tmpfile}, result[2]) - eq({method = 'textDocument/rangeFormatting', supported = true}, result[3]) - eq({method = 'textDocument/rangeFormatting', supported = true, fname = tmpfile}, result[4]) - eq({method = 'textDocument/completion', supported = false}, result[5]) + eq({ method = 'textDocument/formatting', supported = false }, result[1]) + eq({ method = 'textDocument/formatting', supported = true, fname = tmpfile }, result[2]) + eq({ method = 'textDocument/rangeFormatting', supported = true }, result[3]) + eq({ method = 'textDocument/rangeFormatting', supported = true, fname = tmpfile }, result[4]) + eq({ method = 'textDocument/completion', supported = false }, result[5]) end) end) describe('vim.lsp._watchfiles', function() it('sends notifications when files change', function() - skip(is_os('bsd'), "bsd only reports rename on folders if file inside change") + skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change') local root_dir = helpers.tmpname() os.remove(root_dir) mkdir(root_dir) exec_lua(create_server_definition) - local result = exec_lua([[ + local result = exec_lua( + [[ local root_dir = ... local server = _create_server() @@ -4143,13 +4328,19 @@ describe('LSP', function() wait_for_messages() return server.messages - ]], root_dir) + ]], + root_dir + ) local function watched_uri(fname) - return exec_lua([[ + return exec_lua( + [[ local root_dir, fname = ... return vim.uri_from_fname(root_dir .. '/' .. fname) - ]], root_dir, fname) + ]], + root_dir, + fname + ) end eq(4, #result) @@ -4176,7 +4367,8 @@ describe('LSP', function() it('correctly registers and unregisters', function() local root_dir = '/some_dir' exec_lua(create_server_definition) - local result = exec_lua([[ + local result = exec_lua( + [[ local root_dir = ... local server = _create_server() @@ -4267,13 +4459,19 @@ describe('LSP', function() wait_for_messages() return server.messages - ]], root_dir) + ]], + root_dir + ) local function watched_uri(fname) - return exec_lua([[ + return exec_lua( + [[ local root_dir, fname = ... return vim.uri_from_fname(root_dir .. '/' .. fname) - ]], root_dir, fname) + ]], + root_dir, + fname + ) end eq(4, #result) @@ -4300,7 +4498,8 @@ describe('LSP', function() it('correctly handles the registered watch kind', function() local root_dir = 'some_dir' exec_lua(create_server_definition) - local result = exec_lua([[ + local result = exec_lua( + [[ local root_dir = ... local server = _create_server() @@ -4373,13 +4572,18 @@ describe('LSP', function() wait_for_messages() return server.messages - ]], root_dir) + ]], + root_dir + ) local function watched_uri(fname) - return exec_lua([[ + return exec_lua( + [[ local fname = ... return vim.uri_from_fname('/dir/' .. fname) - ]], fname) + ]], + fname + ) end eq(3, #result) @@ -4441,7 +4645,8 @@ describe('LSP', function() it('prunes duplicate events', function() local root_dir = 'some_dir' exec_lua(create_server_definition) - local result = exec_lua([[ + local result = exec_lua( + [[ local root_dir = ... local server = _create_server() @@ -4499,12 +4704,17 @@ describe('LSP', function() wait_for_messages() return server.messages - ]], root_dir) + ]], + root_dir + ) local function watched_uri(fname) - return exec_lua([[ + return exec_lua( + [[ return vim.uri_from_fname(...) - ]], fname) + ]], + fname + ) end eq(3, #result) @@ -4539,7 +4749,8 @@ describe('LSP', function() ]]) local function check_registered(capabilities) - return exec_lua([[ + return exec_lua( + [[ watching = false local client_id = vim.lsp.start({ name = 'watchfiles-test', @@ -4578,31 +4789,41 @@ describe('LSP', function() vim.lsp.stop_client(client_id, true) return watching - ]], capabilities) + ]], + capabilities + ) end - eq(true, check_registered(nil)) -- start{_client}() defaults to make_client_capabilities(). + eq(true, check_registered(nil)) -- start{_client}() defaults to make_client_capabilities(). eq(false, check_registered(vim.empty_dict())) - eq(false, check_registered({ + eq( + false, + check_registered({ workspace = { ignoreMe = true, }, - })) - eq(false, check_registered({ + }) + ) + eq( + false, + check_registered({ workspace = { didChangeWatchedFiles = { dynamicRegistration = false, }, }, - })) - eq(true, check_registered({ + }) + ) + eq( + true, + check_registered({ workspace = { didChangeWatchedFiles = { dynamicRegistration = true, }, }, - })) + }) + ) end) end) end) - diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index f16fca51f9..ed9f21edf3 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -49,7 +49,7 @@ describe(':Man', function() before_each(function() command('syntax on') command('set filetype=man') - command('syntax off') -- Ignore syntax groups + command('syntax off') -- Ignore syntax groups screen = Screen.new(52, 5) screen:set_default_attr_ids({ b = { bold = true }, @@ -58,24 +58,28 @@ describe(':Man', function() bi = { bold = true, italic = true }, biu = { bold = true, italic = true, underline = true }, c = { foreground = Screen.colors.Blue }, -- control chars - eob = { bold = true, foreground = Screen.colors.Blue } -- empty line '~'s + eob = { bold = true, foreground = Screen.colors.Blue }, -- empty line '~'s }) screen:attach() end) it('clears backspaces from text and adds highlights', function() - rawfeed([[ + rawfeed( + [[ ithis iiss aa test - with _o_v_e_r_s_t_r_u_c_k text]]) + with _o_v_e_r_s_t_r_u_c_k text]] + ) - screen:expect{grid=[[ + screen:expect { + grid = [[ this i{c:^H}is{c:^H}s a{c:^H}a test | with _{c:^H}o_{c:^H}v_{c:^H}e_{c:^H}r_{c:^H}s_{c:^H}t_{c:^H}r_{c:^H}u_{c:^H}c_{c:^H}k tex^t | {eob:~ }|*2 | - ]]} + ]], + } - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^this {b:is} {b:a} test | @@ -86,18 +90,22 @@ describe(':Man', function() end) it('clears escape sequences from text and adds highlights', function() - rawfeed([[ + rawfeed( + [[ ithis [1mis [3ma [4mtest[0m - [4mwith[24m [4mescaped[24m [4mtext[24m]]) + [4mwith[24m [4mescaped[24m [4mtext[24m]] + ) - screen:expect{grid=[=[ + screen:expect { + grid = [=[ this {c:^[}[1mis {c:^[}[3ma {c:^[}[4mtest{c:^[}[0m | {c:^[}[4mwith{c:^[}[24m {c:^[}[4mescaped{c:^[}[24m {c:^[}[4mtext{c:^[}[24^m | {eob:~ }|*2 | - ]=]} + ]=], + } - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^this {b:is }{bi:a }{biu:test} | @@ -108,10 +116,12 @@ describe(':Man', function() end) it('highlights multibyte text', function() - rawfeed([[ + rawfeed( + [[ ithis iiss ああ test - with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]]) - exec_lua[[require'man'.init_pager()]] + with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]] + ) + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^this {b:is} {b:あ} test | @@ -122,11 +132,13 @@ describe(':Man', function() end) it('highlights underscores based on context', function() - rawfeed([[ + rawfeed( + [[ i__bbeeggiinnss mmiidd__ddllee - _m_i_d___d_l_e]]) - exec_lua[[require'man'.init_pager()]] + _m_i_d___d_l_e]] + ) + exec_lua [[require'man'.init_pager()]] screen:expect([[ {b:^_begins} | @@ -142,7 +154,7 @@ describe(':Man', function() i· ·· +o ++oo double]]) - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^· {b:·} | @@ -159,7 +171,7 @@ describe(':Man', function() [44m 4 [45m 5 [46m 6 [47m 7 [100m 8 [101m 9 [102m 10 [103m 11 [104m 12 [105m 13 [106m 14 [107m 15 [48:5:16m 16 ]]) - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^ 0 1 2 3 | @@ -173,8 +185,14 @@ describe(':Man', function() it('q quits in "$MANPAGER mode" (:Man!) #18281', function() -- This will hang if #18281 regresses. - local args = {nvim_prog, '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', '+call nvim_input("q")'} - matches('quit works!!', funcs.system(args, {'manpage contents'})) + local args = { + nvim_prog, + '--headless', + '+autocmd VimLeave * echo "quit works!!"', + '+Man!', + '+call nvim_input("q")', + } + matches('quit works!!', funcs.system(args, { 'manpage contents' })) end) it('reports non-existent man pages for absolute paths', function() @@ -183,41 +201,44 @@ describe(':Man', function() -- actual_file must be an absolute path to an existent file for us to test against it matches('^/.+', actual_file) write_file(actual_file, '') - local args = {nvim_prog, '--headless', '+:Man ' .. actual_file, '+q'} - matches(('Error detected while processing command line:\r\n' .. - 'man.lua: "no manual entry for %s"'):format(pesc(actual_file)), - funcs.system(args, {''})) + local args = { nvim_prog, '--headless', '+:Man ' .. actual_file, '+q' } + matches( + ('Error detected while processing command line:\r\n' .. 'man.lua: "no manual entry for %s"'):format( + pesc(actual_file) + ), + funcs.system(args, { '' }) + ) os.remove(actual_file) end) it('tries variants with spaces, underscores #22503', function() eq({ - {'', 'NAME WITH SPACES'}, - {'', 'NAME_WITH_SPACES'}, - }, get_search_history('NAME WITH SPACES')) + { '', 'NAME WITH SPACES' }, + { '', 'NAME_WITH_SPACES' }, + }, get_search_history('NAME WITH SPACES')) eq({ - {'3', 'some other man'}, - {'3', 'some_other_man'}, - }, get_search_history('3 some other man')) + { '3', 'some other man' }, + { '3', 'some_other_man' }, + }, get_search_history('3 some other man')) eq({ - {'3x', 'some other man'}, - {'3x', 'some_other_man'}, - }, get_search_history('3X some other man')) + { '3x', 'some other man' }, + { '3x', 'some_other_man' }, + }, get_search_history('3X some other man')) eq({ - {'3tcl', 'some other man'}, - {'3tcl', 'some_other_man'}, - }, get_search_history('3tcl some other man')) + { '3tcl', 'some other man' }, + { '3tcl', 'some_other_man' }, + }, get_search_history('3tcl some other man')) eq({ - {'n', 'some other man'}, - {'n', 'some_other_man'}, - }, get_search_history('n some other man')) + { 'n', 'some other man' }, + { 'n', 'some_other_man' }, + }, get_search_history('n some other man')) eq({ - {'', '123some other man'}, - {'', '123some_other_man'}, - }, get_search_history('123some other man')) + { '', '123some other man' }, + { '', '123some_other_man' }, + }, get_search_history('123some other man')) eq({ - {'1', 'other_man'}, - {'1', 'other_man'}, - }, get_search_history('other_man(1)')) + { '1', 'other_man' }, + { '1', 'other_man' }, + }, get_search_history('other_man(1)')) end) end) diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 2670734c1a..1c4e11d30b 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -11,13 +11,13 @@ describe('matchparen', function() local screen before_each(function() - clear{args={'-u', 'NORC'}} - screen = Screen.new(20,5) + clear { args = { '-u', 'NORC' } } + screen = Screen.new(20, 5) screen:attach() - screen:set_default_attr_ids( { - [0] = {bold=true, foreground=255}, - [1] = {bold=true}, - } ) + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = 255 }, + [1] = { bold = true }, + }) end) it('uses correct column after i_. Vim patch 7.4.1296', function() @@ -39,6 +39,5 @@ describe('matchparen', function() } | {1:-- INSERT --} | ]]) - end) end) diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index d841cb8ce0..01dd253384 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -8,7 +8,7 @@ local NIL = helpers.NIL describe('autoload/msgpack.vim', function() before_each(function() - clear{args={'-u', 'NORC'}} + clear { args = { '-u', 'NORC' } } end) local sp = function(typ, val) @@ -16,16 +16,15 @@ describe('autoload/msgpack.vim', function() end local mapsp = function(...) local val = '' - for i=1,(select('#', ...)/2) do - val = ('%s[%s,%s],'):format(val, select(i * 2 - 1, ...), - select(i * 2, ...)) + for i = 1, (select('#', ...) / 2) do + val = ('%s[%s,%s],'):format(val, select(i * 2 - 1, ...), select(i * 2, ...)) end return sp('map', '[' .. val .. ']') end - local nan = -(1.0/0.0-1.0/0.0) - local inf = 1.0/0.0 - local minus_inf = -(1.0/0.0) + local nan = -(1.0 / 0.0 - 1.0 / 0.0) + local inf = 1.0 / 0.0 + local minus_inf = -(1.0 / 0.0) describe('function msgpack#equal', function() local msgpack_eq = function(expected, a, b) @@ -39,10 +38,8 @@ describe('autoload/msgpack.vim', function() msgpack_eq(0, '1', '0') end) it('compares integer specials correctly', function() - msgpack_eq(1, sp('integer', '[-1, 1, 0, 0]'), - sp('integer', '[-1, 1, 0, 0]')) - msgpack_eq(0, sp('integer', '[-1, 1, 0, 0]'), - sp('integer', '[ 1, 1, 0, 0]')) + msgpack_eq(1, sp('integer', '[-1, 1, 0, 0]'), sp('integer', '[-1, 1, 0, 0]')) + msgpack_eq(0, sp('integer', '[-1, 1, 0, 0]'), sp('integer', '[ 1, 1, 0, 0]')) end) it('compares integer specials with raw integer correctly', function() msgpack_eq(1, sp('integer', '[-1, 0, 0, 1]'), '-1') @@ -58,27 +55,21 @@ describe('autoload/msgpack.vim', function() msgpack_eq(0, '"abc\\ndef"', '"abc\\nghi"') end) it('compares binary specials correctly', function() - msgpack_eq(1, sp('binary', '["abc\\n", "def"]'), - sp('binary', '["abc\\n", "def"]')) - msgpack_eq(0, sp('binary', '["abc", "def"]'), - sp('binary', '["abc\\n", "def"]')) + msgpack_eq(1, sp('binary', '["abc\\n", "def"]'), sp('binary', '["abc\\n", "def"]')) + msgpack_eq(0, sp('binary', '["abc", "def"]'), sp('binary', '["abc\\n", "def"]')) end) it('compares binary specials with raw binaries correctly', function() msgpack_eq(1, sp('binary', '["abc", "def"]'), '"abc\\ndef"') msgpack_eq(0, sp('binary', '["abc", "def"]'), '"abcdef"') end) it('compares string specials correctly', function() - msgpack_eq(1, sp('string', '["abc\\n", "def"]'), - sp('string', '["abc\\n", "def"]')) - msgpack_eq(0, sp('string', '["abc", "def"]'), - sp('string', '["abc\\n", "def"]')) + msgpack_eq(1, sp('string', '["abc\\n", "def"]'), sp('string', '["abc\\n", "def"]')) + msgpack_eq(0, sp('string', '["abc", "def"]'), sp('string', '["abc\\n", "def"]')) end) it('compares string specials with binary correctly', function() - msgpack_eq(0, sp('string', '["abc\\n", "def"]'), - sp('binary', '["abc\\n", "def"]')) + msgpack_eq(0, sp('string', '["abc\\n", "def"]'), sp('binary', '["abc\\n", "def"]')) msgpack_eq(0, sp('string', '["abc", "def"]'), '"abc\\ndef"') - msgpack_eq(0, sp('binary', '["abc\\n", "def"]'), - sp('string', '["abc\\n", "def"]')) + msgpack_eq(0, sp('binary', '["abc\\n", "def"]'), sp('string', '["abc\\n", "def"]')) msgpack_eq(0, '"abc\\ndef"', sp('string', '["abc", "def"]')) end) it('compares ext specials correctly', function() @@ -97,44 +88,54 @@ describe('autoload/msgpack.vim', function() end) it('compares map specials correctly', function() msgpack_eq(1, mapsp(), mapsp()) - msgpack_eq(1, mapsp(sp('binary', '[""]'), '""'), - mapsp(sp('binary', '[""]'), '""')) - msgpack_eq(1, mapsp(mapsp('1', '1'), mapsp('1', '1')), - mapsp(mapsp('1', '1'), mapsp('1', '1'))) + msgpack_eq(1, mapsp(sp('binary', '[""]'), '""'), mapsp(sp('binary', '[""]'), '""')) + msgpack_eq( + 1, + mapsp(mapsp('1', '1'), mapsp('1', '1')), + mapsp(mapsp('1', '1'), mapsp('1', '1')) + ) msgpack_eq(0, mapsp(), mapsp('1', '1')) - msgpack_eq(0, mapsp(sp('binary', '["a"]'), '""'), - mapsp(sp('binary', '[""]'), '""')) - msgpack_eq(0, mapsp(sp('binary', '[""]'), '"a"'), - mapsp(sp('binary', '[""]'), '""')) - msgpack_eq(0, mapsp(sp('binary', '["a"]'), '"a"'), - mapsp(sp('binary', '[""]'), '""')) - msgpack_eq(0, mapsp(mapsp('1', '1'), mapsp('1', '1')), - mapsp(sp('binary', '[""]'), mapsp('1', '1'))) - msgpack_eq(0, mapsp(mapsp('1', '1'), mapsp('1', '1')), - mapsp(mapsp('2', '1'), mapsp('1', '1'))) - msgpack_eq(0, mapsp(mapsp('1', '1'), mapsp('1', '1')), - mapsp(mapsp('1', '2'), mapsp('1', '1'))) - msgpack_eq(0, mapsp(mapsp('1', '1'), mapsp('1', '1')), - mapsp(mapsp('1', '1'), mapsp('2', '1'))) - msgpack_eq(0, mapsp(mapsp('1', '1'), mapsp('1', '1')), - mapsp(mapsp('1', '1'), mapsp('1', '2'))) - msgpack_eq(1, mapsp(mapsp('2', '1'), mapsp('1', '1'), - mapsp('1', '1'), mapsp('1', '1')), - mapsp(mapsp('1', '1'), mapsp('1', '1'), - mapsp('2', '1'), mapsp('1', '1'))) + msgpack_eq(0, mapsp(sp('binary', '["a"]'), '""'), mapsp(sp('binary', '[""]'), '""')) + msgpack_eq(0, mapsp(sp('binary', '[""]'), '"a"'), mapsp(sp('binary', '[""]'), '""')) + msgpack_eq(0, mapsp(sp('binary', '["a"]'), '"a"'), mapsp(sp('binary', '[""]'), '""')) + msgpack_eq( + 0, + mapsp(mapsp('1', '1'), mapsp('1', '1')), + mapsp(sp('binary', '[""]'), mapsp('1', '1')) + ) + msgpack_eq( + 0, + mapsp(mapsp('1', '1'), mapsp('1', '1')), + mapsp(mapsp('2', '1'), mapsp('1', '1')) + ) + msgpack_eq( + 0, + mapsp(mapsp('1', '1'), mapsp('1', '1')), + mapsp(mapsp('1', '2'), mapsp('1', '1')) + ) + msgpack_eq( + 0, + mapsp(mapsp('1', '1'), mapsp('1', '1')), + mapsp(mapsp('1', '1'), mapsp('2', '1')) + ) + msgpack_eq( + 0, + mapsp(mapsp('1', '1'), mapsp('1', '1')), + mapsp(mapsp('1', '1'), mapsp('1', '2')) + ) + msgpack_eq( + 1, + mapsp(mapsp('2', '1'), mapsp('1', '1'), mapsp('1', '1'), mapsp('1', '1')), + mapsp(mapsp('1', '1'), mapsp('1', '1'), mapsp('2', '1'), mapsp('1', '1')) + ) end) it('compares map specials with raw maps correctly', function() msgpack_eq(1, mapsp(), '{}') msgpack_eq(1, mapsp(sp('string', '["1"]'), '1'), '{"1": 1}') - msgpack_eq(1, mapsp(sp('string', '["1"]'), sp('integer', '[1, 0, 0, 1]')), - '{"1": 1}') - msgpack_eq(0, mapsp(sp('integer', '[1, 0, 0, 1]'), sp('string', '["1"]')), - '{1: "1"}') - msgpack_eq(0, mapsp('"1"', sp('integer', '[1, 0, 0, 1]')), - '{"1": 1}') - msgpack_eq(0, - mapsp(sp('string', '["1"]'), '1', sp('string', '["2"]'), '2'), - '{"1": 1}') + msgpack_eq(1, mapsp(sp('string', '["1"]'), sp('integer', '[1, 0, 0, 1]')), '{"1": 1}') + msgpack_eq(0, mapsp(sp('integer', '[1, 0, 0, 1]'), sp('string', '["1"]')), '{1: "1"}') + msgpack_eq(0, mapsp('"1"', sp('integer', '[1, 0, 0, 1]')), '{"1": 1}') + msgpack_eq(0, mapsp(sp('string', '["1"]'), '1', sp('string', '["2"]'), '2'), '{"1": 1}') msgpack_eq(0, mapsp(sp('string', '["1"]'), '1'), '{"1": 1, "2": 2}') end) it('compares raw arrays correctly', function() @@ -195,8 +196,7 @@ describe('autoload/msgpack.vim', function() end) it('compares float specials correctly', function() msgpack_eq(1, sp('float', '0.0'), sp('float', '0.0')) - msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), - sp('float', '(1.0/0.0-1.0/0.0)')) + msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '(1.0/0.0-1.0/0.0)')) msgpack_eq(1, sp('float', '1.0/0.0'), sp('float', '1.0/0.0')) msgpack_eq(1, sp('float', '-(1.0/0.0)'), sp('float', '-(1.0/0.0)')) msgpack_eq(1, sp('float', '0.0'), sp('float', '0.0')) @@ -206,10 +206,8 @@ describe('autoload/msgpack.vim', function() msgpack_eq(0, sp('float', '0.0'), sp('float', '-(1.0/0.0)')) msgpack_eq(0, sp('float', '1.0/0.0'), sp('float', '-(1.0/0.0)')) msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0)')) - msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), - sp('float', '-(1.0/0.0-1.0/0.0)')) - msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), - sp('float', '-(1.0/0.0-1.0/0.0)')) + msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0-1.0/0.0)')) + msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0-1.0/0.0)')) msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '1.0/0.0')) end) it('compares boolean specials correctly', function() @@ -219,8 +217,7 @@ describe('autoload/msgpack.vim', function() it('compares nil specials correctly', function() msgpack_eq(1, sp('nil', '1'), sp('nil', '0')) end) - it('compares nil, boolean and integer values with each other correctly', - function() + it('compares nil, boolean and integer values with each other correctly', function() msgpack_eq(0, sp('boolean', '1'), '1') msgpack_eq(0, sp('boolean', '1'), sp('nil', '0')) msgpack_eq(0, sp('boolean', '1'), sp('nil', '1')) @@ -238,16 +235,11 @@ describe('autoload/msgpack.vim', function() it('works', function() eq(1, nvim_eval('msgpack#is_int(1)')) eq(1, nvim_eval('msgpack#is_int(-1)')) - eq(1, nvim_eval(('msgpack#is_int(%s)'):format( - sp('integer', '[1, 0, 0, 1]')))) - eq(1, nvim_eval(('msgpack#is_int(%s)'):format( - sp('integer', '[-1, 0, 0, 1]')))) - eq(0, nvim_eval(('msgpack#is_int(%s)'):format( - sp('float', '0.0')))) - eq(0, nvim_eval(('msgpack#is_int(%s)'):format( - sp('boolean', '0')))) - eq(0, nvim_eval(('msgpack#is_int(%s)'):format( - sp('nil', '0')))) + eq(1, nvim_eval(('msgpack#is_int(%s)'):format(sp('integer', '[1, 0, 0, 1]')))) + eq(1, nvim_eval(('msgpack#is_int(%s)'):format(sp('integer', '[-1, 0, 0, 1]')))) + eq(0, nvim_eval(('msgpack#is_int(%s)'):format(sp('float', '0.0')))) + eq(0, nvim_eval(('msgpack#is_int(%s)'):format(sp('boolean', '0')))) + eq(0, nvim_eval(('msgpack#is_int(%s)'):format(sp('nil', '0')))) eq(0, nvim_eval('msgpack#is_int("")')) end) end) @@ -256,16 +248,11 @@ describe('autoload/msgpack.vim', function() it('works', function() eq(1, nvim_eval('msgpack#is_uint(1)')) eq(0, nvim_eval('msgpack#is_uint(-1)')) - eq(1, nvim_eval(('msgpack#is_uint(%s)'):format( - sp('integer', '[1, 0, 0, 1]')))) - eq(0, nvim_eval(('msgpack#is_uint(%s)'):format( - sp('integer', '[-1, 0, 0, 1]')))) - eq(0, nvim_eval(('msgpack#is_uint(%s)'):format( - sp('float', '0.0')))) - eq(0, nvim_eval(('msgpack#is_uint(%s)'):format( - sp('boolean', '0')))) - eq(0, nvim_eval(('msgpack#is_uint(%s)'):format( - sp('nil', '0')))) + eq(1, nvim_eval(('msgpack#is_uint(%s)'):format(sp('integer', '[1, 0, 0, 1]')))) + eq(0, nvim_eval(('msgpack#is_uint(%s)'):format(sp('integer', '[-1, 0, 0, 1]')))) + eq(0, nvim_eval(('msgpack#is_uint(%s)'):format(sp('float', '0.0')))) + eq(0, nvim_eval(('msgpack#is_uint(%s)'):format(sp('boolean', '0')))) + eq(0, nvim_eval(('msgpack#is_uint(%s)'):format(sp('nil', '0')))) eq(0, nvim_eval('msgpack#is_uint("")')) end) end) @@ -274,18 +261,20 @@ describe('autoload/msgpack.vim', function() it('works', function() local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) eq(epoch, nvim_eval('msgpack#strftime("%Y-%m-%dT%H:%M:%S", 0)')) - eq(epoch, nvim_eval( - ('msgpack#strftime("%%Y-%%m-%%dT%%H:%%M:%%S", %s)'):format(sp( - 'integer', '[1, 0, 0, 0]')))) + eq( + epoch, + nvim_eval( + ('msgpack#strftime("%%Y-%%m-%%dT%%H:%%M:%%S", %s)'):format(sp('integer', '[1, 0, 0, 0]')) + ) + ) end) end) describe('function msgpack#strptime', function() it('works', function() - for _, v in ipairs({0, 10, 100000, 204, 1000000000}) do + for _, v in ipairs({ 0, 10, 100000, 204, 1000000000 }) do local time = os.date('%Y-%m-%dT%H:%M:%S', v) - eq(v, nvim_eval('msgpack#strptime("%Y-%m-%dT%H:%M:%S", ' - .. '"' .. time .. '")')) + eq(v, nvim_eval('msgpack#strptime("%Y-%m-%dT%H:%M:%S", ' .. '"' .. time .. '")')) end end) end) @@ -367,25 +356,27 @@ describe('autoload/msgpack.vim', function() string_eq('[[[[{}]]]]', sp('array', '[[[[{}]]]]')) string_eq('{}', sp('map', '[]')) string_eq('{2: 10}', sp('map', '[[2, 10]]')) - string_eq('{{1: 1}: {1: 1}, {2: 1}: {1: 1}}', - mapsp(mapsp('2', '1'), mapsp('1', '1'), - mapsp('1', '1'), mapsp('1', '1'))) - string_eq('{{1: 1}: {1: 1}, {2: 1}: {1: 1}}', - mapsp(mapsp('1', '1'), mapsp('1', '1'), - mapsp('2', '1'), mapsp('1', '1'))) - string_eq('{[1, 2, {{1: 2}: 1}]: [1, 2, {{1: 2}: 1}]}', - mapsp(('[1, 2, %s]'):format(mapsp(mapsp('1', '2'), '1')), - ('[1, 2, %s]'):format(mapsp(mapsp('1', '2'), '1')))) + string_eq( + '{{1: 1}: {1: 1}, {2: 1}: {1: 1}}', + mapsp(mapsp('2', '1'), mapsp('1', '1'), mapsp('1', '1'), mapsp('1', '1')) + ) + string_eq( + '{{1: 1}: {1: 1}, {2: 1}: {1: 1}}', + mapsp(mapsp('1', '1'), mapsp('1', '1'), mapsp('2', '1'), mapsp('1', '1')) + ) + string_eq( + '{[1, 2, {{1: 2}: 1}]: [1, 2, {{1: 2}: 1}]}', + mapsp( + ('[1, 2, %s]'):format(mapsp(mapsp('1', '2'), '1')), + ('[1, 2, %s]'):format(mapsp(mapsp('1', '2'), '1')) + ) + ) string_eq('0x0000000000000000', sp('integer', '[1, 0, 0, 0]')) string_eq('-0x0000000100000000', sp('integer', '[-1, 0, 2, 0]')) - string_eq('0x123456789abcdef0', - sp('integer', '[ 1, 0, 610839793, 448585456]')) - string_eq('-0x123456789abcdef0', - sp('integer', '[-1, 0, 610839793, 448585456]')) - string_eq('0xf23456789abcdef0', - sp('integer', '[ 1, 3, 1684581617, 448585456]')) - string_eq('-0x723456789abcdef0', - sp('integer', '[-1, 1, 1684581617, 448585456]')) + string_eq('0x123456789abcdef0', sp('integer', '[ 1, 0, 610839793, 448585456]')) + string_eq('-0x123456789abcdef0', sp('integer', '[-1, 0, 610839793, 448585456]')) + string_eq('0xf23456789abcdef0', sp('integer', '[ 1, 3, 1684581617, 448585456]')) + string_eq('-0x723456789abcdef0', sp('integer', '[-1, 1, 1684581617, 448585456]')) string_eq('0.0', sp('float', '0.0')) string_eq('inf', sp('float', '(1.0/0.0)')) string_eq('-inf', sp('float', '-(1.0/0.0)')) @@ -466,15 +457,15 @@ describe('autoload/msgpack.vim', function() nvim_command('let spbln._VAL = 1') nvim_command('let spnil._VAL = 1') - eq({_TYPE={}, _VAL={{{}}}}, nvim_eval('sparr2')) - eq({_TYPE={}, _VAL={{'abc', {{}}}}}, nvim_eval('spmap2')) - eq({_TYPE={}, _VAL={1, 0, 0, 0}}, nvim_eval('spint2')) - eq({_TYPE={}, _VAL=1.0}, nvim_eval('spflt2')) - eq({_TYPE={}, _VAL={2, {'abc', 'def'}}}, nvim_eval('spext2')) - eq({_TYPE={}, _VAL={'abc', 'def'}}, nvim_eval('spstr2')) - eq({_TYPE={}, _VAL={'abc', 'def'}}, nvim_eval('spbin2')) - eq({_TYPE={}, _VAL=0}, nvim_eval('spbln2')) - eq({_TYPE={}, _VAL=0}, nvim_eval('spnil2')) + eq({ _TYPE = {}, _VAL = { { {} } } }, nvim_eval('sparr2')) + eq({ _TYPE = {}, _VAL = { { 'abc', { {} } } } }, nvim_eval('spmap2')) + eq({ _TYPE = {}, _VAL = { 1, 0, 0, 0 } }, nvim_eval('spint2')) + eq({ _TYPE = {}, _VAL = 1.0 }, nvim_eval('spflt2')) + eq({ _TYPE = {}, _VAL = { 2, { 'abc', 'def' } } }, nvim_eval('spext2')) + eq({ _TYPE = {}, _VAL = { 'abc', 'def' } }, nvim_eval('spstr2')) + eq({ _TYPE = {}, _VAL = { 'abc', 'def' } }, nvim_eval('spbin2')) + eq({ _TYPE = {}, _VAL = 0 }, nvim_eval('spbln2')) + eq({ _TYPE = {}, _VAL = 0 }, nvim_eval('spnil2')) nvim_command('let sparr._TYPE = []') nvim_command('let spmap._TYPE = []') @@ -525,8 +516,8 @@ describe('autoload/msgpack.vim', function() nvim_command('let flt = 3.0') nvim_command('let bin = ""') - eq({{{}}}, nvim_eval('arr2')) - eq({['1']={}}, nvim_eval('map2')) + eq({ { {} } }, nvim_eval('arr2')) + eq({ ['1'] = {} }, nvim_eval('map2')) eq(1, nvim_eval('int2')) eq(2.0, nvim_eval('flt2')) eq('abc', nvim_eval('bin2')) @@ -549,14 +540,16 @@ describe('autoload/msgpack.vim', function() describe('function msgpack#eval', function() local eval_eq = function(expected_type, expected_val, str, ...) - nvim_command(('let g:__val = msgpack#eval(\'%s\', %s)'):format(str:gsub( - '\'', '\'\''), select(1, ...) or '{}')) + nvim_command( + ("let g:__val = msgpack#eval('%s', %s)"):format(str:gsub("'", "''"), select(1, ...) or '{}') + ) eq(expected_type, nvim_eval('msgpack#type(g:__val)')) local expected_val_full = expected_val - if (not (({float=true, integer=true})[expected_type] - and type(expected_val) ~= 'table') - and expected_type ~= 'array') then - expected_val_full = {_TYPE={}, _VAL=expected_val_full} + if + not (({ float = true, integer = true })[expected_type] and type(expected_val) ~= 'table') + and expected_type ~= 'array' + then + expected_val_full = { _TYPE = {}, _VAL = expected_val_full } end if expected_val_full == expected_val_full then eq(expected_val_full, nvim_eval('g:__val')) @@ -570,68 +563,65 @@ describe('autoload/msgpack.vim', function() end it('correctly loads binary strings', function() - eval_eq('binary', {'abcdef'}, '"abcdef"') - eval_eq('binary', {'abc', 'def'}, '"abc\\ndef"') - eval_eq('binary', {'abc\ndef'}, '"abc\\0def"') - eval_eq('binary', {'\nabc\ndef\n'}, '"\\0abc\\0def\\0"') - eval_eq('binary', {'abc\n\n\ndef'}, '"abc\\0\\0\\0def"') - eval_eq('binary', {'abc\n', '\ndef'}, '"abc\\0\\n\\0def"') - eval_eq('binary', {'abc', '', '', 'def'}, '"abc\\n\\n\\ndef"') - eval_eq('binary', {'abc', '', '', 'def', ''}, '"abc\\n\\n\\ndef\\n"') - eval_eq('binary', {'', 'abc', '', '', 'def'}, '"\\nabc\\n\\n\\ndef"') - eval_eq('binary', {''}, '""') - eval_eq('binary', {'"'}, '"\\""') - eval_eq('binary', {'py3 print(sys.version_info)'}, - '"py3 print(sys.version_info)"') + eval_eq('binary', { 'abcdef' }, '"abcdef"') + eval_eq('binary', { 'abc', 'def' }, '"abc\\ndef"') + eval_eq('binary', { 'abc\ndef' }, '"abc\\0def"') + eval_eq('binary', { '\nabc\ndef\n' }, '"\\0abc\\0def\\0"') + eval_eq('binary', { 'abc\n\n\ndef' }, '"abc\\0\\0\\0def"') + eval_eq('binary', { 'abc\n', '\ndef' }, '"abc\\0\\n\\0def"') + eval_eq('binary', { 'abc', '', '', 'def' }, '"abc\\n\\n\\ndef"') + eval_eq('binary', { 'abc', '', '', 'def', '' }, '"abc\\n\\n\\ndef\\n"') + eval_eq('binary', { '', 'abc', '', '', 'def' }, '"\\nabc\\n\\n\\ndef"') + eval_eq('binary', { '' }, '""') + eval_eq('binary', { '"' }, '"\\""') + eval_eq('binary', { 'py3 print(sys.version_info)' }, '"py3 print(sys.version_info)"') end) it('correctly loads strings', function() - eval_eq('string', {'abcdef'}, '="abcdef"') - eval_eq('string', {'abc', 'def'}, '="abc\\ndef"') - eval_eq('string', {'abc\ndef'}, '="abc\\0def"') - eval_eq('string', {'\nabc\ndef\n'}, '="\\0abc\\0def\\0"') - eval_eq('string', {'abc\n\n\ndef'}, '="abc\\0\\0\\0def"') - eval_eq('string', {'abc\n', '\ndef'}, '="abc\\0\\n\\0def"') - eval_eq('string', {'abc', '', '', 'def'}, '="abc\\n\\n\\ndef"') - eval_eq('string', {'abc', '', '', 'def', ''}, '="abc\\n\\n\\ndef\\n"') - eval_eq('string', {'', 'abc', '', '', 'def'}, '="\\nabc\\n\\n\\ndef"') - eval_eq('string', {''}, '=""') - eval_eq('string', {'"'}, '="\\""') - eval_eq('string', {'py3 print(sys.version_info)'}, - '="py3 print(sys.version_info)"') + eval_eq('string', { 'abcdef' }, '="abcdef"') + eval_eq('string', { 'abc', 'def' }, '="abc\\ndef"') + eval_eq('string', { 'abc\ndef' }, '="abc\\0def"') + eval_eq('string', { '\nabc\ndef\n' }, '="\\0abc\\0def\\0"') + eval_eq('string', { 'abc\n\n\ndef' }, '="abc\\0\\0\\0def"') + eval_eq('string', { 'abc\n', '\ndef' }, '="abc\\0\\n\\0def"') + eval_eq('string', { 'abc', '', '', 'def' }, '="abc\\n\\n\\ndef"') + eval_eq('string', { 'abc', '', '', 'def', '' }, '="abc\\n\\n\\ndef\\n"') + eval_eq('string', { '', 'abc', '', '', 'def' }, '="\\nabc\\n\\n\\ndef"') + eval_eq('string', { '' }, '=""') + eval_eq('string', { '"' }, '="\\""') + eval_eq('string', { 'py3 print(sys.version_info)' }, '="py3 print(sys.version_info)"') end) it('correctly loads ext values', function() - eval_eq('ext', {0, {'abcdef'}}, '+(0)"abcdef"') - eval_eq('ext', {0, {'abc', 'def'}}, '+(0)"abc\\ndef"') - eval_eq('ext', {0, {'abc\ndef'}}, '+(0)"abc\\0def"') - eval_eq('ext', {0, {'\nabc\ndef\n'}}, '+(0)"\\0abc\\0def\\0"') - eval_eq('ext', {0, {'abc\n\n\ndef'}}, '+(0)"abc\\0\\0\\0def"') - eval_eq('ext', {0, {'abc\n', '\ndef'}}, '+(0)"abc\\0\\n\\0def"') - eval_eq('ext', {0, {'abc', '', '', 'def'}}, '+(0)"abc\\n\\n\\ndef"') - eval_eq('ext', {0, {'abc', '', '', 'def', ''}}, - '+(0)"abc\\n\\n\\ndef\\n"') - eval_eq('ext', {0, {'', 'abc', '', '', 'def'}}, - '+(0)"\\nabc\\n\\n\\ndef"') - eval_eq('ext', {0, {''}}, '+(0)""') - eval_eq('ext', {0, {'"'}}, '+(0)"\\""') - - eval_eq('ext', {-1, {'abcdef'}}, '+(-1)"abcdef"') - eval_eq('ext', {-1, {'abc', 'def'}}, '+(-1)"abc\\ndef"') - eval_eq('ext', {-1, {'abc\ndef'}}, '+(-1)"abc\\0def"') - eval_eq('ext', {-1, {'\nabc\ndef\n'}}, '+(-1)"\\0abc\\0def\\0"') - eval_eq('ext', {-1, {'abc\n\n\ndef'}}, '+(-1)"abc\\0\\0\\0def"') - eval_eq('ext', {-1, {'abc\n', '\ndef'}}, '+(-1)"abc\\0\\n\\0def"') - eval_eq('ext', {-1, {'abc', '', '', 'def'}}, '+(-1)"abc\\n\\n\\ndef"') - eval_eq('ext', {-1, {'abc', '', '', 'def', ''}}, - '+(-1)"abc\\n\\n\\ndef\\n"') - eval_eq('ext', {-1, {'', 'abc', '', '', 'def'}}, - '+(-1)"\\nabc\\n\\n\\ndef"') - eval_eq('ext', {-1, {''}}, '+(-1)""') - eval_eq('ext', {-1, {'"'}}, '+(-1)"\\""') - - eval_eq('ext', {42, {'py3 print(sys.version_info)'}}, - '+(42)"py3 print(sys.version_info)"') + eval_eq('ext', { 0, { 'abcdef' } }, '+(0)"abcdef"') + eval_eq('ext', { 0, { 'abc', 'def' } }, '+(0)"abc\\ndef"') + eval_eq('ext', { 0, { 'abc\ndef' } }, '+(0)"abc\\0def"') + eval_eq('ext', { 0, { '\nabc\ndef\n' } }, '+(0)"\\0abc\\0def\\0"') + eval_eq('ext', { 0, { 'abc\n\n\ndef' } }, '+(0)"abc\\0\\0\\0def"') + eval_eq('ext', { 0, { 'abc\n', '\ndef' } }, '+(0)"abc\\0\\n\\0def"') + eval_eq('ext', { 0, { 'abc', '', '', 'def' } }, '+(0)"abc\\n\\n\\ndef"') + eval_eq('ext', { 0, { 'abc', '', '', 'def', '' } }, '+(0)"abc\\n\\n\\ndef\\n"') + eval_eq('ext', { 0, { '', 'abc', '', '', 'def' } }, '+(0)"\\nabc\\n\\n\\ndef"') + eval_eq('ext', { 0, { '' } }, '+(0)""') + eval_eq('ext', { 0, { '"' } }, '+(0)"\\""') + + eval_eq('ext', { -1, { 'abcdef' } }, '+(-1)"abcdef"') + eval_eq('ext', { -1, { 'abc', 'def' } }, '+(-1)"abc\\ndef"') + eval_eq('ext', { -1, { 'abc\ndef' } }, '+(-1)"abc\\0def"') + eval_eq('ext', { -1, { '\nabc\ndef\n' } }, '+(-1)"\\0abc\\0def\\0"') + eval_eq('ext', { -1, { 'abc\n\n\ndef' } }, '+(-1)"abc\\0\\0\\0def"') + eval_eq('ext', { -1, { 'abc\n', '\ndef' } }, '+(-1)"abc\\0\\n\\0def"') + eval_eq('ext', { -1, { 'abc', '', '', 'def' } }, '+(-1)"abc\\n\\n\\ndef"') + eval_eq('ext', { -1, { 'abc', '', '', 'def', '' } }, '+(-1)"abc\\n\\n\\ndef\\n"') + eval_eq('ext', { -1, { '', 'abc', '', '', 'def' } }, '+(-1)"\\nabc\\n\\n\\ndef"') + eval_eq('ext', { -1, { '' } }, '+(-1)""') + eval_eq('ext', { -1, { '"' } }, '+(-1)"\\""') + + eval_eq( + 'ext', + { 42, { 'py3 print(sys.version_info)' } }, + '+(42)"py3 print(sys.version_info)"' + ) end) it('correctly loads floats', function() @@ -650,17 +640,17 @@ describe('autoload/msgpack.vim', function() it('correctly loads integers', function() eval_eq('integer', 10, '10') eval_eq('integer', -10, '-10') - eval_eq('integer', { 1, 0, 610839793, 448585456}, ' 0x123456789ABCDEF0') - eval_eq('integer', {-1, 0, 610839793, 448585456}, '-0x123456789ABCDEF0') - eval_eq('integer', { 1, 3, 1684581617, 448585456}, ' 0xF23456789ABCDEF0') - eval_eq('integer', {-1, 1, 1684581617, 448585456}, '-0x723456789ABCDEF0') - eval_eq('integer', { 1, 0, 0, 0x100}, '0x100') - eval_eq('integer', {-1, 0, 0, 0x100}, '-0x100') + eval_eq('integer', { 1, 0, 610839793, 448585456 }, ' 0x123456789ABCDEF0') + eval_eq('integer', { -1, 0, 610839793, 448585456 }, '-0x123456789ABCDEF0') + eval_eq('integer', { 1, 3, 1684581617, 448585456 }, ' 0xF23456789ABCDEF0') + eval_eq('integer', { -1, 1, 1684581617, 448585456 }, '-0x723456789ABCDEF0') + eval_eq('integer', { 1, 0, 0, 0x100 }, '0x100') + eval_eq('integer', { -1, 0, 0, 0x100 }, '-0x100') - eval_eq('integer', ('a'):byte(), '\'a\'') - eval_eq('integer', 0xAB, '\'«\'') - eval_eq('integer', 0, '\'\\0\'') - eval_eq('integer', 10246567, '\'\\10246567\'') + eval_eq('integer', ('a'):byte(), "'a'") + eval_eq('integer', 0xAB, "'«'") + eval_eq('integer', 0, "'\\0'") + eval_eq('integer', 10246567, "'\\10246567'") end) it('correctly loads constants', function() @@ -668,71 +658,94 @@ describe('autoload/msgpack.vim', function() eval_eq('boolean', 0, 'FALSE') eval_eq('nil', 0, 'NIL') eval_eq('nil', 0, 'NIL', '{"NIL": 1, "nan": 2, "T": 3}') - eval_eq('float', nan, 'nan', - '{"NIL": "1", "nan": "2", "T": "3"}') + eval_eq('float', nan, 'nan', '{"NIL": "1", "nan": "2", "T": "3"}') eval_eq('integer', 3, 'T', '{"NIL": "1", "nan": "2", "T": "3"}') - eval_eq('integer', {1, 0, 0, 0}, 'T', - ('{"NIL": "1", "nan": "2", "T": \'%s\'}'):format( - sp('integer', '[1, 0, 0, 0]'))) + eval_eq( + 'integer', + { 1, 0, 0, 0 }, + 'T', + ('{"NIL": "1", "nan": "2", "T": \'%s\'}'):format(sp('integer', '[1, 0, 0, 0]')) + ) end) it('correctly loads maps', function() eval_eq('map', {}, '{}') - eval_eq('map', {{{_TYPE={}, _VAL={{1, 2}}}, {_TYPE={}, _VAL={{3, 4}}}}}, - '{{1: 2}: {3: 4}}') - eval_eq('map', {{{_TYPE={}, _VAL={{1, 2}}}, {_TYPE={}, _VAL={{3, 4}}}}, - {1, 2}}, - '{{1: 2}: {3: 4}, 1: 2}') - - eval_eq('map', {{{_TYPE={}, _VAL={ - {{_TYPE={}, _VAL={'py3 print(sys.version_info)'}}, - 2}}}, - {_TYPE={}, _VAL={{3, 4}}}}, - {1, 2}}, - '{{"py3 print(sys.version_info)": 2}: {3: 4}, 1: 2}') + eval_eq( + 'map', + { { { _TYPE = {}, _VAL = { { 1, 2 } } }, { _TYPE = {}, _VAL = { { 3, 4 } } } } }, + '{{1: 2}: {3: 4}}' + ) + eval_eq( + 'map', + { { { _TYPE = {}, _VAL = { { 1, 2 } } }, { _TYPE = {}, _VAL = { { 3, 4 } } } }, { 1, 2 } }, + '{{1: 2}: {3: 4}, 1: 2}' + ) + + eval_eq('map', { + { + { + _TYPE = {}, + _VAL = { + { { _TYPE = {}, _VAL = { 'py3 print(sys.version_info)' } }, 2 }, + }, + }, + { _TYPE = {}, _VAL = { { 3, 4 } } }, + }, + { 1, 2 }, + }, '{{"py3 print(sys.version_info)": 2}: {3: 4}, 1: 2}') end) it('correctly loads arrays', function() eval_eq('array', {}, '[]') - eval_eq('array', {1}, '[1]') - eval_eq('array', {{_TYPE={}, _VAL=1}}, '[TRUE]') - eval_eq('array', {{{_TYPE={}, _VAL={{1, 2}}}}, {_TYPE={}, _VAL={{3, 4}}}}, - '[[{1: 2}], {3: 4}]') + eval_eq('array', { 1 }, '[1]') + eval_eq('array', { { _TYPE = {}, _VAL = 1 } }, '[TRUE]') + eval_eq( + 'array', + { { { _TYPE = {}, _VAL = { { 1, 2 } } } }, { _TYPE = {}, _VAL = { { 3, 4 } } } }, + '[[{1: 2}], {3: 4}]' + ) - eval_eq('array', {{_TYPE={}, _VAL={'py3 print(sys.version_info)'}}}, - '["py3 print(sys.version_info)"]') + eval_eq( + 'array', + { { _TYPE = {}, _VAL = { 'py3 print(sys.version_info)' } } }, + '["py3 print(sys.version_info)"]' + ) end) it('errors out when needed', function() - eq('empty:Parsed string is empty', - exc_exec('call msgpack#eval("", {})')) - eq('unknown:Invalid non-space character: ^', - exc_exec('call msgpack#eval("^", {})')) - eq('char-invalid:Invalid integer character literal format: \'\'', - exc_exec('call msgpack#eval("\'\'", {})')) - eq('char-invalid:Invalid integer character literal format: \'ab\'', - exc_exec('call msgpack#eval("\'ab\'", {})')) - eq('char-invalid:Invalid integer character literal format: \'', - exc_exec('call msgpack#eval("\'", {})')) - eq('"-invalid:Invalid string: "', - exc_exec('call msgpack#eval("\\"", {})')) - eq('"-invalid:Invalid string: ="', - exc_exec('call msgpack#eval("=\\"", {})')) - eq('"-invalid:Invalid string: +(0)"', - exc_exec('call msgpack#eval("+(0)\\"", {})')) - eq('0.-nodigits:Decimal dot must be followed by digit(s): .e1', - exc_exec('call msgpack#eval("0.e1", {})')) - eq('0x-long:Must have at most 16 hex digits: FEDCBA98765432100', - exc_exec('call msgpack#eval("0xFEDCBA98765432100", {})')) - eq('0x-empty:Must have number after 0x: ', - exc_exec('call msgpack#eval("0x", {})')) - eq('name-unknown:Unknown name FOO: FOO', - exc_exec('call msgpack#eval("FOO", {})')) - - eq('name-unknown:Unknown name py3: py3 print(sys.version_info)', - exc_exec('call msgpack#eval("py3 print(sys.version_info)", {})')) - eq('name-unknown:Unknown name o: o', - exc_exec('call msgpack#eval("-info", {})')) + eq('empty:Parsed string is empty', exc_exec('call msgpack#eval("", {})')) + eq('unknown:Invalid non-space character: ^', exc_exec('call msgpack#eval("^", {})')) + eq( + "char-invalid:Invalid integer character literal format: ''", + exc_exec('call msgpack#eval("\'\'", {})') + ) + eq( + "char-invalid:Invalid integer character literal format: 'ab'", + exc_exec('call msgpack#eval("\'ab\'", {})') + ) + eq( + "char-invalid:Invalid integer character literal format: '", + exc_exec('call msgpack#eval("\'", {})') + ) + eq('"-invalid:Invalid string: "', exc_exec('call msgpack#eval("\\"", {})')) + eq('"-invalid:Invalid string: ="', exc_exec('call msgpack#eval("=\\"", {})')) + eq('"-invalid:Invalid string: +(0)"', exc_exec('call msgpack#eval("+(0)\\"", {})')) + eq( + '0.-nodigits:Decimal dot must be followed by digit(s): .e1', + exc_exec('call msgpack#eval("0.e1", {})') + ) + eq( + '0x-long:Must have at most 16 hex digits: FEDCBA98765432100', + exc_exec('call msgpack#eval("0xFEDCBA98765432100", {})') + ) + eq('0x-empty:Must have number after 0x: ', exc_exec('call msgpack#eval("0x", {})')) + eq('name-unknown:Unknown name FOO: FOO', exc_exec('call msgpack#eval("FOO", {})')) + + eq( + 'name-unknown:Unknown name py3: py3 print(sys.version_info)', + exc_exec('call msgpack#eval("py3 print(sys.version_info)", {})') + ) + eq('name-unknown:Unknown name o: o', exc_exec('call msgpack#eval("-info", {})')) end) end) end) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 8d37100607..ef3fef1897 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -2,8 +2,15 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = - helpers.eq, helpers.meths, helpers.eval, helpers.command, helpers.nvim, helpers.exc_exec, - helpers.funcs, helpers.feed, helpers.curbuf + helpers.eq, + helpers.meths, + helpers.eval, + helpers.command, + helpers.nvim, + helpers.exc_exec, + helpers.funcs, + helpers.feed, + helpers.curbuf local neq = helpers.neq local read_file = helpers.read_file @@ -13,11 +20,11 @@ local shada_helpers = require('test.functional.shada.helpers') local get_shada_rw = shada_helpers.get_shada_rw local function reset(shada_file) - clear{ args={'-u', 'NORC', '-i', shada_file or 'NONE', }} + clear { args = { '-u', 'NORC', '-i', shada_file or 'NONE' } } end local mpack_eq = function(expected, mpack_result) - local mpack_keys = {'type', 'timestamp', 'length', 'value'} + local mpack_keys = { 'type', 'timestamp', 'length', 'value' } local unpack = mpack.Unpacker() local actual = {} @@ -44,8 +51,7 @@ end local wshada, _, fname = get_shada_rw('Xtest-functional-plugin-shada.shada') -local wshada_tmp, _, fname_tmp = - get_shada_rw('Xtest-functional-plugin-shada.shada.tmp.f') +local wshada_tmp, _, fname_tmp = get_shada_rw('Xtest-functional-plugin-shada.shada.tmp.f') describe('autoload/shada.vim', function() local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) @@ -89,22 +95,31 @@ describe('autoload/shada.vim', function() it('works', function() eq({}, nvim_eval(mpack2sd('[]'))) - eq({{type=1, timestamp=5, length=1, data=7}}, - nvim_eval(mpack2sd('[1, 5, 1, 7]'))) - eq({{type=1, timestamp=5, length=1, data=7}, - {type=1, timestamp=10, length=1, data=5}}, - nvim_eval(mpack2sd('[1, 5, 1, 7, 1, 10, 1, 5]'))) - eq('zero-uint:Entry 1 has type element which is zero', - exc_exec('call ' .. mpack2sd('[0, 5, 1, 7]'))) - eq('zero-uint:Entry 1 has type element which is zero', - exc_exec('call ' .. mpack2sd(('[%s, 5, 1, 7]'):format( - sp('integer', '[1, 0, 0, 0]'))))) - eq('not-uint:Entry 1 has timestamp element which is not an unsigned integer', - exc_exec('call ' .. mpack2sd('[1, -1, 1, 7]'))) - eq('not-uint:Entry 1 has length element which is not an unsigned integer', - exc_exec('call ' .. mpack2sd('[1, 1, -1, 7]'))) - eq('not-uint:Entry 1 has type element which is not an unsigned integer', - exc_exec('call ' .. mpack2sd('["", 1, -1, 7]'))) + eq({ { type = 1, timestamp = 5, length = 1, data = 7 } }, nvim_eval(mpack2sd('[1, 5, 1, 7]'))) + eq({ + { type = 1, timestamp = 5, length = 1, data = 7 }, + { type = 1, timestamp = 10, length = 1, data = 5 }, + }, nvim_eval(mpack2sd('[1, 5, 1, 7, 1, 10, 1, 5]'))) + eq( + 'zero-uint:Entry 1 has type element which is zero', + exc_exec('call ' .. mpack2sd('[0, 5, 1, 7]')) + ) + eq( + 'zero-uint:Entry 1 has type element which is zero', + exc_exec('call ' .. mpack2sd(('[%s, 5, 1, 7]'):format(sp('integer', '[1, 0, 0, 0]')))) + ) + eq( + 'not-uint:Entry 1 has timestamp element which is not an unsigned integer', + exc_exec('call ' .. mpack2sd('[1, -1, 1, 7]')) + ) + eq( + 'not-uint:Entry 1 has length element which is not an unsigned integer', + exc_exec('call ' .. mpack2sd('[1, 1, -1, 7]')) + ) + eq( + 'not-uint:Entry 1 has type element which is not an unsigned integer', + exc_exec('call ' .. mpack2sd('["", 1, -1, 7]')) + ) end) end) @@ -124,15 +139,18 @@ describe('autoload/shada.vim', function() it('works with unknown items', function() sd2strings_eq({ 'Unknown (0x64) with timestamp ' .. epoch .. ':', - ' = 100' - }, {{type=100, timestamp=0, length=1, data=100}}) - - sd2strings_eq({ - 'Unknown (0x4000001180000006) with timestamp ' .. epoch .. ':', - ' = 100' - }, ('[{"type": %s, "timestamp": 0, "length": 1, "data": 100}]'):format( - sp('integer', '[1, 1, 35, 6]') - )) + ' = 100', + }, { { type = 100, timestamp = 0, length = 1, data = 100 } }) + + sd2strings_eq( + { + 'Unknown (0x4000001180000006) with timestamp ' .. epoch .. ':', + ' = 100', + }, + ('[{"type": %s, "timestamp": 0, "length": 1, "data": 100}]'):format( + sp('integer', '[1, 1, 35, 6]') + ) + ) end) it('works with multiple unknown items', function() @@ -141,8 +159,10 @@ describe('autoload/shada.vim', function() ' = 100', 'Unknown (0x65) with timestamp ' .. epoch .. ':', ' = 500', - }, {{type=100, timestamp=0, length=1, data=100}, - {type=101, timestamp=0, length=1, data=500}}) + }, { + { type = 100, timestamp = 0, length = 1, data = 100 }, + { type = 101, timestamp = 0, length = 1, data = 500 }, + }) end) it('works with header items', function() @@ -150,7 +170,7 @@ describe('autoload/shada.vim', function() 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', - }, {{type=1, timestamp=0, data={generator='test'}}}) + }, { { type = 1, timestamp = 0, data = { generator = 'test' } } }) sd2strings_eq({ 'Header with timestamp ' .. epoch .. ':', ' % Key Description Value', @@ -158,42 +178,44 @@ describe('autoload/shada.vim', function() ' + b 2', ' + c column 3', ' + d 4', - }, {{type=1, timestamp=0, data={a=1, b=2, c=3, d=4}}}) + }, { { type = 1, timestamp = 0, data = { a = 1, b = 2, c = 3, d = 4 } } }) sd2strings_eq({ 'Header with timestamp ' .. epoch .. ':', ' % Key Value', ' + t "test"', - }, {{type=1, timestamp=0, data={t='test'}}}) + }, { { type = 1, timestamp = 0, data = { t = 'test' } } }) sd2strings_eq({ 'Header with timestamp ' .. epoch .. ':', ' # Unexpected type: array instead of map', ' = [1, 2, 3]', - }, {{type=1, timestamp=0, data={1, 2, 3}}}) + }, { { type = 1, timestamp = 0, data = { 1, 2, 3 } } }) end) it('processes standard keys correctly, even in header', function() - sd2strings_eq({ - 'Header with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' + c column 0', - ' + f file name "/tmp/foo"', - ' + l line number 10', - ' + n name \'@\'', - ' + rc contents ["abc", "def"]', - ' + rt type CHARACTERWISE', - ' + ru is_unnamed FALSE', - ' + rw block width 10', - ' + sb search backward TRUE', - ' + sc smartcase value FALSE', - ' + se place cursor at end TRUE', - ' + sh v:hlsearch value TRUE', - ' + sl has line offset FALSE', - ' + sm magic value TRUE', - ' + so offset value 10', - ' + sp pattern "100"', - ' + ss is :s pattern TRUE', - ' + su is last used FALSE', - }, ([[ [{'type': 1, 'timestamp': 0, 'data': { + sd2strings_eq( + { + 'Header with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' + c column 0', + ' + f file name "/tmp/foo"', + ' + l line number 10', + " + n name '@'", + ' + rc contents ["abc", "def"]', + ' + rt type CHARACTERWISE', + ' + ru is_unnamed FALSE', + ' + rw block width 10', + ' + sb search backward TRUE', + ' + sc smartcase value FALSE', + ' + se place cursor at end TRUE', + ' + sh v:hlsearch value TRUE', + ' + sl has line offset FALSE', + ' + sm magic value TRUE', + ' + so offset value 10', + ' + sp pattern "100"', + ' + ss is :s pattern TRUE', + ' + su is last used FALSE', + }, + ([[ [{'type': 1, 'timestamp': 0, 'data': { 'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1}, 'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, 'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, @@ -212,34 +234,37 @@ describe('autoload/shada.vim', function() 'l': 10, 'c': 0, 'f': '/tmp/foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Header with timestamp ' .. epoch .. ':', - ' % Key Description____ Value', - ' # Expected integer', - ' + c column "abc"', - ' # Expected no NUL bytes', - ' + f file name "abc\\0def"', - ' # Value is negative', - ' + l line number -10', - ' # Value is negative', - ' + n name -64', - ' # Expected array value', - ' + rc contents "10"', - ' # Unexpected enum value: expected one of ' - .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)', - ' + rt type 10', - ' # Expected boolean', - ' + ru is_unnamed 10', - ' # Expected boolean', - ' + sc smartcase value NIL', - ' # Expected boolean', - ' + sm magic value "TRUE"', - ' # Expected integer', - ' + so offset value "TRUE"', - ' # Expected binary string', - ' + sp pattern ="abc"', - }, ([[ [{'type': 1, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Header with timestamp ' .. epoch .. ':', + ' % Key Description____ Value', + ' # Expected integer', + ' + c column "abc"', + ' # Expected no NUL bytes', + ' + f file name "abc\\0def"', + ' # Value is negative', + ' + l line number -10', + ' # Value is negative', + ' + n name -64', + ' # Expected array value', + ' + rc contents "10"', + ' # Unexpected enum value: expected one of ' + .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)', + ' + rt type 10', + ' # Expected boolean', + ' + ru is_unnamed 10', + ' # Expected boolean', + ' + sc smartcase value NIL', + ' # Expected boolean', + ' + sm magic value "TRUE"', + ' # Expected integer', + ' + so offset value "TRUE"', + ' # Expected binary string', + ' + sp pattern ="abc"', + }, + ([[ [{'type': 1, 'timestamp': 0, 'data': { 'sm': 'TRUE', 'sc': {'_TYPE': v:msgpack_types.nil, '_VAL': 0}, 'so': 'TRUE', @@ -251,29 +276,36 @@ describe('autoload/shada.vim', function() 'l': -10, 'c': 'abc', 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Header with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected no NUL bytes', - ' + f file name "abc\\0def"', - ' # Expected array of binary strings', - ' + rc contents ["abc", ="abc"]', - ' # Expected integer', - ' + rt type "ABC"', - }, ([[ [{'type': 1, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Header with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected no NUL bytes', + ' + f file name "abc\\0def"', + ' # Expected array of binary strings', + ' + rc contents ["abc", ="abc"]', + ' # Expected integer', + ' + rt type "ABC"', + }, + ([[ [{'type': 1, 'timestamp': 0, 'data': { 'rt': 'ABC', 'rc': ["abc", {'_TYPE': v:msgpack_types.string, '_VAL': ["abc"]}], 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Header with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected no NUL bytes', - ' + rc contents ["abc", "a\\nd\\0"]', - }, ([[ [{'type': 1, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Header with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected no NUL bytes', + ' + rc contents ["abc", "a\\nd\\0"]', + }, + ([[ [{'type': 1, 'timestamp': 0, 'data': { 'rc': ["abc", {'_TYPE': v:msgpack_types.binary, '_VAL': ["a", "d\n"]}], - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) it('works with search pattern items', function() @@ -281,59 +313,67 @@ describe('autoload/shada.vim', function() 'Search pattern with timestamp ' .. epoch .. ':', ' # Unexpected type: array instead of map', ' = [1, 2, 3]', - }, {{type=2, timestamp=0, data={1, 2, 3}}}) - sd2strings_eq({ - 'Search pattern with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' + sp pattern "abc"', - ' + sh v:hlsearch value FALSE', - ' + ss is :s pattern FALSE', - ' + sb search backward FALSE', - ' + sm magic value TRUE', - ' + sc smartcase value FALSE', - ' + sl has line offset FALSE', - ' + se place cursor at end FALSE', - ' + so offset value 0', - ' + su is last used TRUE', - }, ([[ [{'type': 2, 'timestamp': 0, 'data': { + }, { { type = 2, timestamp = 0, data = { 1, 2, 3 } } }) + sd2strings_eq( + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' + sp pattern "abc"', + ' + sh v:hlsearch value FALSE', + ' + ss is :s pattern FALSE', + ' + sb search backward FALSE', + ' + sm magic value TRUE', + ' + sc smartcase value FALSE', + ' + sl has line offset FALSE', + ' + se place cursor at end FALSE', + ' + so offset value 0', + ' + su is last used TRUE', + }, + ([[ [{'type': 2, 'timestamp': 0, 'data': { 'sp': 'abc', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Search pattern with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' + sp pattern "abc"', - ' + sh v:hlsearch value FALSE', - ' + ss is :s pattern FALSE', - ' + sb search backward FALSE', - ' + sm magic value TRUE', - ' + sc smartcase value FALSE', - ' + sl has line offset FALSE', - ' + se place cursor at end FALSE', - ' + so offset value 0', - ' + su is last used TRUE', - ' + sX NIL', - ' + sY NIL', - ' + sZ NIL', - }, ([[ [{'type': 2, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' + sp pattern "abc"', + ' + sh v:hlsearch value FALSE', + ' + ss is :s pattern FALSE', + ' + sb search backward FALSE', + ' + sm magic value TRUE', + ' + sc smartcase value FALSE', + ' + sl has line offset FALSE', + ' + se place cursor at end FALSE', + ' + so offset value 0', + ' + su is last used TRUE', + ' + sX NIL', + ' + sY NIL', + ' + sZ NIL', + }, + ([[ [{'type': 2, 'timestamp': 0, 'data': { 'sp': 'abc', 'sZ': {'_TYPE': v:msgpack_types.nil, '_VAL': 0}, 'sY': {'_TYPE': v:msgpack_types.nil, '_VAL': 0}, 'sX': {'_TYPE': v:msgpack_types.nil, '_VAL': 0}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Search pattern with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' + sp pattern "abc"', - ' + sh v:hlsearch value FALSE', - ' + ss is :s pattern FALSE', - ' + sb search backward FALSE', - ' + sm magic value TRUE', - ' + sc smartcase value FALSE', - ' + sl has line offset FALSE', - ' + se place cursor at end FALSE', - ' + so offset value 0', - ' + su is last used TRUE', - }, ([[ [{'type': 2, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' + sp pattern "abc"', + ' + sh v:hlsearch value FALSE', + ' + ss is :s pattern FALSE', + ' + sb search backward FALSE', + ' + sm magic value TRUE', + ' + sc smartcase value FALSE', + ' + sl has line offset FALSE', + ' + se place cursor at end FALSE', + ' + so offset value 0', + ' + su is last used TRUE', + }, + ([[ [{'type': 2, 'timestamp': 0, 'data': { 'sp': 'abc', 'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, 'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, @@ -344,36 +384,42 @@ describe('autoload/shada.vim', function() 'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, 'so': 0, 'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Search pattern with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' # Required key missing: sp', - ' + sh v:hlsearch value FALSE', - ' + ss is :s pattern FALSE', - ' + sb search backward FALSE', - ' + sm magic value TRUE', - ' + sc smartcase value FALSE', - ' + sl has line offset FALSE', - ' + se place cursor at end FALSE', - ' + so offset value 0', - ' + su is last used TRUE', - }, ([[ [{'type': 2, 'timestamp': 0, 'data': { - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Search pattern with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' + sp pattern ""', - ' + sh v:hlsearch value TRUE', - ' + ss is :s pattern TRUE', - ' + sb search backward TRUE', - ' + sm magic value FALSE', - ' + sc smartcase value TRUE', - ' + sl has line offset TRUE', - ' + se place cursor at end TRUE', - ' + so offset value -10', - ' + su is last used FALSE', - }, ([[ [{'type': 2, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' # Required key missing: sp', + ' + sh v:hlsearch value FALSE', + ' + ss is :s pattern FALSE', + ' + sb search backward FALSE', + ' + sm magic value TRUE', + ' + sc smartcase value FALSE', + ' + sl has line offset FALSE', + ' + se place cursor at end FALSE', + ' + so offset value 0', + ' + su is last used TRUE', + }, + ([[ [{'type': 2, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' + sp pattern ""', + ' + sh v:hlsearch value TRUE', + ' + ss is :s pattern TRUE', + ' + sb search backward TRUE', + ' + sm magic value FALSE', + ' + sc smartcase value TRUE', + ' + sl has line offset TRUE', + ' + se place cursor at end TRUE', + ' + so offset value -10', + ' + su is last used FALSE', + }, + ([[ [{'type': 2, 'timestamp': 0, 'data': { 'sp': '', 'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1}, 'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1}, @@ -384,31 +430,34 @@ describe('autoload/shada.vim', function() 'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1}, 'so': -10, 'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Search pattern with timestamp ' .. epoch .. ':', - ' % Key Description________ Value', - ' # Expected binary string', - ' + sp pattern 0', - ' # Expected boolean', - ' + sh v:hlsearch value 0', - ' # Expected boolean', - ' + ss is :s pattern 0', - ' # Expected boolean', - ' + sb search backward 0', - ' # Expected boolean', - ' + sm magic value 0', - ' # Expected boolean', - ' + sc smartcase value 0', - ' # Expected boolean', - ' + sl has line offset 0', - ' # Expected boolean', - ' + se place cursor at end 0', - ' # Expected integer', - ' + so offset value ""', - ' # Expected boolean', - ' + su is last used 0', - }, ([[ [{'type': 2, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' % Key Description________ Value', + ' # Expected binary string', + ' + sp pattern 0', + ' # Expected boolean', + ' + sh v:hlsearch value 0', + ' # Expected boolean', + ' + ss is :s pattern 0', + ' # Expected boolean', + ' + sb search backward 0', + ' # Expected boolean', + ' + sm magic value 0', + ' # Expected boolean', + ' + sc smartcase value 0', + ' # Expected boolean', + ' + sl has line offset 0', + ' # Expected boolean', + ' + se place cursor at end 0', + ' # Expected integer', + ' + so offset value ""', + ' # Expected boolean', + ' + su is last used 0', + }, + ([[ [{'type': 2, 'timestamp': 0, 'data': { 'sp': 0, 'sh': 0, 'ss': 0, @@ -419,7 +468,8 @@ describe('autoload/shada.vim', function() 'se': 0, 'so': '', 'su': 0, - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) it('works with replacement string items', function() @@ -427,45 +477,60 @@ describe('autoload/shada.vim', function() 'Replacement string with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', - }, {{type=3, timestamp=0, data={a={10}}}}) - sd2strings_eq({ - 'Replacement string with timestamp ' .. epoch .. ':', - ' @ Description__________ Value', - ' # Expected more elements in list' - }, ([[ [{'type': 3, 'timestamp': 0, 'data': [ - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Replacement string with timestamp ' .. epoch .. ':', - ' @ Description__________ Value', - ' # Expected binary string', - ' - :s replacement string 0', - }, ([[ [{'type': 3, 'timestamp': 0, 'data': [ + }, { { type = 3, timestamp = 0, data = { a = { 10 } } } }) + sd2strings_eq( + { + 'Replacement string with timestamp ' .. epoch .. ':', + ' @ Description__________ Value', + ' # Expected more elements in list', + }, + ([[ [{'type': 3, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Replacement string with timestamp ' .. epoch .. ':', + ' @ Description__________ Value', + ' # Expected binary string', + ' - :s replacement string 0', + }, + ([[ [{'type': 3, 'timestamp': 0, 'data': [ 0, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Replacement string with timestamp ' .. epoch .. ':', - ' @ Description__________ Value', - ' # Expected no NUL bytes', - ' - :s replacement string "abc\\0def"', - }, ([[ [{'type': 3, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Replacement string with timestamp ' .. epoch .. ':', + ' @ Description__________ Value', + ' # Expected no NUL bytes', + ' - :s replacement string "abc\\0def"', + }, + ([[ [{'type': 3, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]}, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Replacement string with timestamp ' .. epoch .. ':', - ' @ Description__________ Value', - ' - :s replacement string "abc\\ndef"', - }, ([[ [{'type': 3, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Replacement string with timestamp ' .. epoch .. ':', + ' @ Description__________ Value', + ' - :s replacement string "abc\\ndef"', + }, + ([[ [{'type': 3, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc", "def"]}, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Replacement string with timestamp ' .. epoch .. ':', - ' @ Description__________ Value', - ' - :s replacement string "abc\\ndef"', - ' - 0', - }, ([[ [{'type': 3, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Replacement string with timestamp ' .. epoch .. ':', + ' @ Description__________ Value', + ' - :s replacement string "abc\\ndef"', + ' - 0', + }, + ([[ [{'type': 3, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc", "def"]}, 0, - ]}] ]]):gsub('\n', '')) + ]}] ]]):gsub('\n', '') + ) end) it('works with history entry items', function() @@ -473,161 +538,206 @@ describe('autoload/shada.vim', function() 'History entry with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', - }, {{type=4, timestamp=0, data={a={10}}}}) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' # Expected more elements in list' - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' # Expected integer', - ' - history type ""', - ' # Expected more elements in list' - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + }, { { type = 4, timestamp = 0, data = { a = { 10 } } } }) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' # Expected more elements in list', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' # Expected integer', + ' - history type ""', + ' # Expected more elements in list', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ '', - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)', - ' - history type 5', - ' - contents ""', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ' - history type 5', + ' - contents ""', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 5, '' - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)', - ' - history type 5', - ' - contents ""', - ' - 32', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ' - history type 5', + ' - contents ""', + ' - 32', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 5, '', 0x20 - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type CMD', - ' - contents ""', - ' - 32', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type CMD', + ' - contents ""', + ' - 32', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 0, '', 0x20 - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type SEARCH', - ' - contents ""', - ' - separator \' \'', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents ""', + " - separator ' '", + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 1, '', 0x20 - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type SEARCH', - ' - contents ""', - ' # Expected more elements in list', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents ""', + ' # Expected more elements in list', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 1, '', - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type EXPR', - ' - contents ""', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type EXPR', + ' - contents ""', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 2, '', - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type INPUT', - ' - contents ""', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type INPUT', + ' - contents ""', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 3, '', - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type DEBUG', - ' - contents ""', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type DEBUG', + ' - contents ""', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 4, '', - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type DEBUG', - ' # Expected binary string', - ' - contents 10', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type DEBUG', + ' # Expected binary string', + ' - contents 10', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 4, 10, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type DEBUG', - ' # Expected no NUL bytes', - ' - contents "abc\\0def"', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type DEBUG', + ' # Expected no NUL bytes', + ' - contents "abc\\0def"', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 4, {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]}, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type SEARCH', - ' - contents "abc"', - ' # Expected integer', - ' - separator ""', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents "abc"', + ' # Expected integer', + ' - separator ""', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 1, 'abc', '', - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type SEARCH', - ' - contents "abc"', - ' # Value is negative', - ' - separator -1', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents "abc"', + ' # Value is negative', + ' - separator -1', + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 1, 'abc', -1, - ]}] ]]):gsub('\n', '')) + ]}] ]]):gsub('\n', '') + ) -- Regression: NUL separator must be properly supported - sd2strings_eq({ - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type SEARCH', - ' - contents ""', - ' - separator \'\\0\'', - }, ([[ [{'type': 4, 'timestamp': 0, 'data': [ + sd2strings_eq( + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents ""', + " - separator '\\0'", + }, + ([[ [{'type': 4, 'timestamp': 0, 'data': [ 1, '', 0x0 - ]}] ]]):gsub('\n', '')) + ]}] ]]):gsub('\n', '') + ) end) it('works with register items', function() @@ -635,145 +745,172 @@ describe('autoload/shada.vim', function() 'Register with timestamp ' .. epoch .. ':', ' # Unexpected type: array instead of map', ' = [1, 2, 3]', - }, {{type=5, timestamp=0, data={1, 2, 3}}}) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: n', - ' # Required key missing: rc', - ' + rw block width 0', - ' + rt type CHARACTERWISE', - ' + ru is_unnamed FALSE', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' # Required key missing: rc', - ' + rw block width 0', - ' + rt type CHARACTERWISE', - ' + ru is_unnamed FALSE', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }, { { type = 5, timestamp = 0, data = { 1, 2, 3 } } }) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: n', + ' # Required key missing: rc', + ' + rw block width 0', + ' + rt type CHARACTERWISE', + ' + ru is_unnamed FALSE', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' # Required key missing: rc', + ' + rw block width 0', + ' + rt type CHARACTERWISE', + ' + ru is_unnamed FALSE', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' + rc contents ["abc", "def"]', - ' + rw block width 0', - ' + rt type CHARACTERWISE', - ' + ru is_unnamed FALSE', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' + rc contents ["abc", "def"]', + ' + rw block width 0', + ' + rt type CHARACTERWISE', + ' + ru is_unnamed FALSE', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': ["abc", "def"], 'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' + rc contents @', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' + rw block width 0', - ' + rt type CHARACTERWISE', - ' + ru is_unnamed TRUE', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' + rc contents @', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' + rw block width 0', + ' + rt type CHARACTERWISE', + ' + ru is_unnamed TRUE', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'], 'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' + rc contents @', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' + rw block width 0', - ' + rt type CHARACTERWISE', - ' + ru is_unnamed FALSE', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' + rc contents @', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' + rw block width 0', + ' + rt type CHARACTERWISE', + ' + ru is_unnamed FALSE', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'], 'rw': 0, 'rt': 0, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' + rc contents @', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' + rw block width 5', - ' + rt type LINEWISE', - ' + ru is_unnamed FALSE', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' + rc contents @', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' + rw block width 5', + ' + rt type LINEWISE', + ' + ru is_unnamed FALSE', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'], 'rw': 5, 'rt': 1, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' + rc contents @', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' # Expected integer', - ' + rw block width ""', - ' + rt type BLOCKWISE', - ' # Expected boolean', - ' + ru is_unnamed ""', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' + rc contents @', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' # Expected integer', + ' + rw block width ""', + ' + rt type BLOCKWISE', + ' # Expected boolean', + ' + ru is_unnamed ""', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'], 'rw': "", 'rt': 2, 'ru': "" - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' # Expected array value', - ' + rc contents 0', - ' # Value is negative', - ' + rw block width -1', - ' # Unexpected enum value: expected one of 0 (CHARACTERWISE), ' - .. '1 (LINEWISE), 2 (BLOCKWISE)', - ' + rt type 10', - ' # Expected boolean', - ' + ru is_unnamed ["abc", "def"]', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' # Expected array value', + ' + rc contents 0', + ' # Value is negative', + ' + rw block width -1', + ' # Unexpected enum value: expected one of 0 (CHARACTERWISE), ' + .. '1 (LINEWISE), 2 (BLOCKWISE)', + ' + rt type 10', + ' # Expected boolean', + ' + ru is_unnamed ["abc", "def"]', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': 0, 'rw': -1, 'rt': 10, 'ru': ['abc', 'def'], - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Register with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \' \'', - ' + rc contents @', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' | - "abcdefghijklmnopqrstuvwxyz"', - ' + rw block width 5', - ' + rt type LINEWISE', - ' # Expected boolean', - ' + ru is_unnamed 0', - }, ([[ [{'type': 5, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Register with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name ' '", + ' + rc contents @', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' | - "abcdefghijklmnopqrstuvwxyz"', + ' + rw block width 5', + ' + rt type LINEWISE', + ' # Expected boolean', + ' + ru is_unnamed 0', + }, + ([[ [{'type': 5, 'timestamp': 0, 'data': { 'n': 0x20, 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'], 'rw': 5, 'rt': 1, 'ru': 0, - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) it('works with variable items', function() @@ -781,59 +918,77 @@ describe('autoload/shada.vim', function() 'Variable with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', - }, {{type=6, timestamp=0, data={a={10}}}}) - sd2strings_eq({ - 'Variable with timestamp ' .. epoch .. ':', - ' @ Description Value', - ' # Expected more elements in list' - }, ([[ [{'type': 6, 'timestamp': 0, 'data': [ - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Variable with timestamp ' .. epoch .. ':', - ' @ Description Value', - ' # Expected binary string', - ' - name 1', - ' # Expected more elements in list', - }, ([[ [{'type': 6, 'timestamp': 0, 'data': [ + }, { { type = 6, timestamp = 0, data = { a = { 10 } } } }) + sd2strings_eq( + { + 'Variable with timestamp ' .. epoch .. ':', + ' @ Description Value', + ' # Expected more elements in list', + }, + ([[ [{'type': 6, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Variable with timestamp ' .. epoch .. ':', + ' @ Description Value', + ' # Expected binary string', + ' - name 1', + ' # Expected more elements in list', + }, + ([[ [{'type': 6, 'timestamp': 0, 'data': [ 1 - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Variable with timestamp ' .. epoch .. ':', - ' @ Description Value', - ' # Expected no NUL bytes', - ' - name "\\0"', - ' # Expected more elements in list', - }, ([[ [{'type': 6, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Variable with timestamp ' .. epoch .. ':', + ' @ Description Value', + ' # Expected no NUL bytes', + ' - name "\\0"', + ' # Expected more elements in list', + }, + ([[ [{'type': 6, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Variable with timestamp ' .. epoch .. ':', - ' @ Description Value', - ' - name "foo"', - ' # Expected more elements in list', - }, ([[ [{'type': 6, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Variable with timestamp ' .. epoch .. ':', + ' @ Description Value', + ' - name "foo"', + ' # Expected more elements in list', + }, + ([[ [{'type': 6, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["foo"]}, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Variable with timestamp ' .. epoch .. ':', - ' @ Description Value', - ' - name "foo"', - ' - value NIL', - }, ([[ [{'type': 6, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Variable with timestamp ' .. epoch .. ':', + ' @ Description Value', + ' - name "foo"', + ' - value NIL', + }, + ([[ [{'type': 6, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["foo"]}, {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]}, - ]}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Variable with timestamp ' .. epoch .. ':', - ' @ Description Value', - ' - name "foo"', - ' - value NIL', - ' - NIL', - }, ([[ [{'type': 6, 'timestamp': 0, 'data': [ + ]}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Variable with timestamp ' .. epoch .. ':', + ' @ Description Value', + ' - name "foo"', + ' - value NIL', + ' - NIL', + }, + ([[ [{'type': 6, 'timestamp': 0, 'data': [ {'_TYPE': v:msgpack_types.binary, '_VAL': ["foo"]}, {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]}, {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]}, - ]}] ]]):gsub('\n', '')) + ]}] ]]):gsub('\n', '') + ) end) it('works with global mark items', function() @@ -841,110 +996,134 @@ describe('autoload/shada.vim', function() 'Global mark with timestamp ' .. epoch .. ':', ' # Unexpected type: array instead of map', ' = [1, 2, 3]', - }, {{type=7, timestamp=0, data={1, 2, 3}}}) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: n', - ' # Required key missing: f', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected integer', - ' + n name "foo"', - ' # Required key missing: f', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }, { { type = 7, timestamp = 0, data = { 1, 2, 3 } } }) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: n', + ' # Required key missing: f', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected integer', + ' + n name "foo"', + ' # Required key missing: f', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'n': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: n', - ' + f file name "foo"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: n', + ' + f file name "foo"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'f': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Value is negative', - ' + n name -10', - ' # Expected no NUL bytes', - ' + f file name "\\0"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Value is negative', + ' + n name -10', + ' # Expected no NUL bytes', + ' + f file name "\\0"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'n': -10, 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \'\\20\'', - ' + f file name "foo"', - ' # Value is negative', - ' + l line number -10', - ' # Value is negative', - ' + c column -10', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name '\\20'", + ' + f file name "foo"', + ' # Value is negative', + ' + l line number -10', + ' # Value is negative', + ' + c column -10', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'n': 20, 'f': 'foo', 'l': -10, 'c': -10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name 128', - ' + f file name "foo"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + n name 128', + ' + f file name "foo"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'n': 128, 'f': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + n name \'\\20\'', - ' + f file name "foo"', - ' # Expected integer', - ' + l line number "FOO"', - ' # Expected integer', - ' + c column "foo"', - ' + mX 10', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + " + n name '\\20'", + ' + f file name "foo"', + ' # Expected integer', + ' + l line number "FOO"', + ' # Expected integer', + ' + c column "foo"', + ' + mX 10', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'n': 20, 'f': 'foo', 'l': 'FOO', 'c': 'foo', 'mX': 10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Global mark with timestamp ' .. epoch .. ':', - ' % Key________ Description Value', - ' + n name \'A\'', - ' + f file name "foo"', - ' + l line number 2', - ' + c column 200', - ' + mX 10', - ' + mYYYYYYYYYY 10', - }, ([[ [{'type': 7, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Global mark with timestamp ' .. epoch .. ':', + ' % Key________ Description Value', + " + n name 'A'", + ' + f file name "foo"', + ' + l line number 2', + ' + c column 200', + ' + mX 10', + ' + mYYYYYYYYYY 10', + }, + ([[ [{'type': 7, 'timestamp': 0, 'data': { 'n': char2nr('A'), 'f': 'foo', 'l': 2, 'c': 200, 'mX': 10, 'mYYYYYYYYYY': 10, - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) it('works with jump items', function() @@ -952,93 +1131,114 @@ describe('autoload/shada.vim', function() 'Jump with timestamp ' .. epoch .. ':', ' # Unexpected type: array instead of map', ' = [1, 2, 3]', - }, {{type=8, timestamp=0, data={1, 2, 3}}}) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' + l line number 1', - ' + c column 0', - ' # Expected integer', - ' + n name "foo"', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { + }, { { type = 8, timestamp = 0, data = { 1, 2, 3 } } }) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' + l line number 1', + ' + c column 0', + ' # Expected integer', + ' + n name "foo"', + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { 'n': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { 'f': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected no NUL bytes', - ' + f file name "\\0"', - ' + l line number 1', - ' + c column 0', - ' # Value is negative', - ' + n name -10', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected no NUL bytes', + ' + f file name "\\0"', + ' + l line number 1', + ' + c column 0', + ' # Value is negative', + ' + n name -10', + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { 'n': -10, 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' # Value is negative', - ' + l line number -10', - ' # Value is negative', - ' + c column -10', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + ' # Value is negative', + ' + l line number -10', + ' # Value is negative', + ' + c column -10', + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { 'f': 'foo', 'l': -10, 'c': -10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' # Expected integer', - ' + l line number "FOO"', - ' # Expected integer', - ' + c column "foo"', - ' + mX 10', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + ' # Expected integer', + ' + l line number "FOO"', + ' # Expected integer', + ' + c column "foo"', + ' + mX 10', + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { 'f': 'foo', 'l': 'FOO', 'c': 'foo', 'mX': 10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Jump with timestamp ' .. epoch .. ':', - ' % Key________ Description Value', - ' + f file name "foo"', - ' + l line number 2', - ' + c column 200', - ' + mX 10', - ' + mYYYYYYYYYY 10', - ' + n name \' \'', - }, ([[ [{'type': 8, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Jump with timestamp ' .. epoch .. ':', + ' % Key________ Description Value', + ' + f file name "foo"', + ' + l line number 2', + ' + c column 200', + ' + mX 10', + ' + mYYYYYYYYYY 10', + " + n name ' '", + }, + ([[ [{'type': 8, 'timestamp': 0, 'data': { 'n': 0x20, 'f': 'foo', 'l': 2, 'c': 200, 'mX': 10, 'mYYYYYYYYYY': 10, - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) it('works with buffer list items', function() @@ -1046,17 +1246,17 @@ describe('autoload/shada.vim', function() 'Buffer list with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', - }, {{type=9, timestamp=0, data={a={10}}}}) + }, { { type = 9, timestamp = 0, data = { a = { 10 } } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' # Expected array of maps', ' = [[], []]', - }, {{type=9, timestamp=0, data={{}, {}}}}) + }, { { type = 9, timestamp = 0, data = { {}, {} } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' # Expected array of maps', ' = [{="a": 10}, []]', - }, {{type=9, timestamp=0, data={{a=10}, {}}}}) + }, { { type = 9, timestamp = 0, data = { { a = 10 }, {} } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', @@ -1064,7 +1264,7 @@ describe('autoload/shada.vim', function() ' + l line number 1', ' + c column 0', ' + a 10', - }, {{type=9, timestamp=0, data={{a=10}}}}) + }, { { type = 9, timestamp = 0, data = { { a = 10 } } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', @@ -1074,7 +1274,7 @@ describe('autoload/shada.vim', function() ' # Expected integer', ' + c column "10"', ' + a 10', - }, {{type=9, timestamp=0, data={{l='10', c='10', a=10}}}}) + }, { { type = 9, timestamp = 0, data = { { l = '10', c = '10', a = 10 } } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', @@ -1082,7 +1282,7 @@ describe('autoload/shada.vim', function() ' + l line number 10', ' + c column 10', ' + a 10', - }, {{type=9, timestamp=0, data={{l=10, c=10, a=10}}}}) + }, { { type = 9, timestamp = 0, data = { { l = 10, c = 10, a = 10 } } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', @@ -1091,14 +1291,14 @@ describe('autoload/shada.vim', function() ' + l line number -10', ' # Value is negative', ' + c column -10', - }, {{type=9, timestamp=0, data={{l=-10, c=-10}}}}) + }, { { type = 9, timestamp = 0, data = { { l = -10, c = -10 } } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' + f file name "abc"', ' + l line number 1', ' + c column 0', - }, {{type=9, timestamp=0, data={{f='abc'}}}}) + }, { { type = 9, timestamp = 0, data = { { f = 'abc' } } } }) sd2strings_eq({ 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', @@ -1109,127 +1309,151 @@ describe('autoload/shada.vim', function() '', ' % Key Description Value', ' # Expected binary string', - ' + f file name 20', - ' + l line number 1', - ' + c column 0', - }, {{type=9, timestamp=0, data={{f=10}, {f=20}}}}) - sd2strings_eq({ - 'Buffer list with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected binary string', - ' + f file name 10', - ' + l line number 1', - ' + c column 0', - '', - ' % Key Description Value', - ' # Expected no NUL bytes', - ' + f file name "\\0"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 9, 'timestamp': 0, 'data': [ - {'f': 10}, - {'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}}, - ]}] ]]):gsub('\n', '')) - end) - - it('works with local mark items', function() - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }, {{type=10, timestamp=0, data={1, 2, 3}}}) - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' + n name \'"\'', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' # Expected integer', - ' + n name "foo"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { - 'n': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' + n name \'"\'', + ' + f file name 20', ' + l line number 1', ' + c column 0', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { - 'f': 'foo', - }}] ]]):gsub('\n', '')) + }, { { type = 9, timestamp = 0, data = { { f = 10 }, { f = 20 } } } }) + sd2strings_eq( + { + 'Buffer list with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected binary string', + ' + f file name 10', + ' + l line number 1', + ' + c column 0', + '', + ' % Key Description Value', + ' # Expected no NUL bytes', + ' + f file name "\\0"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 9, 'timestamp': 0, 'data': [ + {'f': 10}, + {'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}}, + ]}] ]]):gsub('\n', '') + ) + end) + + it('works with local mark items', function() sd2strings_eq({ 'Local mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected no NUL bytes', - ' + f file name "\\0"', - ' # Value is negative', - ' + n name -10', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + }, { { type = 10, timestamp = 0, data = { 1, 2, 3 } } }) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + " + n name '\"'", + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' # Expected integer', + ' + n name "foo"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { + 'n': 'foo', + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + " + n name '\"'", + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { + 'f': 'foo', + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected no NUL bytes', + ' + f file name "\\0"', + ' # Value is negative', + ' + n name -10', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { 'n': -10, 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' + n name \'\\20\'', - ' # Value is negative', - ' + l line number -10', - ' # Value is negative', - ' + c column -10', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + " + n name '\\20'", + ' # Value is negative', + ' + l line number -10', + ' # Value is negative', + ' + c column -10', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { 'n': 20, 'f': 'foo', 'l': -10, 'c': -10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' + n name \'\\20\'', - ' # Expected integer', - ' + l line number "FOO"', - ' # Expected integer', - ' + c column "foo"', - ' + mX 10', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + " + n name '\\20'", + ' # Expected integer', + ' + l line number "FOO"', + ' # Expected integer', + ' + c column "foo"', + ' + mX 10', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { 'n': 20, 'f': 'foo', 'l': 'FOO', 'c': 'foo', 'mX': 10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Local mark with timestamp ' .. epoch .. ':', - ' % Key________ Description Value', - ' + f file name "foo"', - ' + n name \'a\'', - ' + l line number 2', - ' + c column 200', - ' + mX 10', - ' + mYYYYYYYYYY 10', - }, ([[ [{'type': 10, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Local mark with timestamp ' .. epoch .. ':', + ' % Key________ Description Value', + ' + f file name "foo"', + " + n name 'a'", + ' + l line number 2', + ' + c column 200', + ' + mX 10', + ' + mYYYYYYYYYY 10', + }, + ([[ [{'type': 10, 'timestamp': 0, 'data': { 'n': char2nr('a'), 'f': 'foo', 'l': 2, 'c': 200, 'mX': 10, 'mYYYYYYYYYY': 10, - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) it('works with change items', function() @@ -1237,93 +1461,114 @@ describe('autoload/shada.vim', function() 'Change with timestamp ' .. epoch .. ':', ' # Unexpected type: array instead of map', ' = [1, 2, 3]', - }, {{type=11, timestamp=0, data={1, 2, 3}}}) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' + l line number 1', - ' + c column 0', - ' # Expected integer', - ' + n name "foo"', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { + }, { { type = 11, timestamp = 0, data = { 1, 2, 3 } } }) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' + l line number 1', + ' + c column 0', + ' # Expected integer', + ' + n name "foo"', + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { 'n': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' + l line number 1', - ' + c column 0', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + ' + l line number 1', + ' + c column 0', + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { 'f': 'foo', - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Expected no NUL bytes', - ' + f file name "\\0"', - ' + l line number 1', - ' + c column 0', - ' # Value is negative', - ' + n name -10', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Expected no NUL bytes', + ' + f file name "\\0"', + ' + l line number 1', + ' + c column 0', + ' # Value is negative', + ' + n name -10', + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { 'n': -10, 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' # Value is negative', - ' + l line number -10', - ' # Value is negative', - ' + c column -10', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + ' # Value is negative', + ' + l line number -10', + ' # Value is negative', + ' + c column -10', + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { 'f': 'foo', 'l': -10, 'c': -10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' + f file name "foo"', - ' # Expected integer', - ' + l line number "FOO"', - ' # Expected integer', - ' + c column "foo"', - ' + mX 10', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' + f file name "foo"', + ' # Expected integer', + ' + l line number "FOO"', + ' # Expected integer', + ' + c column "foo"', + ' + mX 10', + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { 'f': 'foo', 'l': 'FOO', 'c': 'foo', 'mX': 10, - }}] ]]):gsub('\n', '')) - sd2strings_eq({ - 'Change with timestamp ' .. epoch .. ':', - ' % Key________ Description Value', - ' + f file name "foo"', - ' + l line number 2', - ' + c column 200', - ' + mX 10', - ' + mYYYYYYYYYY 10', - ' + n name \' \'', - }, ([[ [{'type': 11, 'timestamp': 0, 'data': { + }}] ]]):gsub('\n', '') + ) + sd2strings_eq( + { + 'Change with timestamp ' .. epoch .. ':', + ' % Key________ Description Value', + ' + f file name "foo"', + ' + l line number 2', + ' + c column 200', + ' + mX 10', + ' + mYYYYYYYYYY 10', + " + n name ' '", + }, + ([[ [{'type': 11, 'timestamp': 0, 'data': { 'n': 0x20, 'f': 'foo', 'l': 2, 'c': 200, 'mX': 10, 'mYYYYYYYYYY': 10, - }}] ]]):gsub('\n', '')) + }}] ]]):gsub('\n', '') + ) end) end) @@ -1337,12 +1582,13 @@ describe('autoload/shada.vim', function() end) describe('function shada#strings_to_sd', function() - local strings2sd_eq = function(expected, input) nvim('set_var', '__input', input) - nvim_command('let g:__actual = map(shada#strings_to_sd(g:__input), ' - .. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' - .. '&& v:key isnot# \'length\'\\")")') + nvim_command( + 'let g:__actual = map(shada#strings_to_sd(g:__input), ' + .. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' + .. '&& v:key isnot# \'length\'\\")")' + ) -- print() if type(expected) == 'table' then nvim('set_var', '__expected', expected) @@ -1360,29 +1606,36 @@ describe('autoload/shada.vim', function() end it('works with multiple items', function() - strings2sd_eq({{ - type=11, timestamp=0, data={ - f='foo', - l=2, - c=200, - mX=10, - mYYYYYYYYYY=10, - n=(' '):byte(), - } + strings2sd_eq({ + { + type = 11, + timestamp = 0, + data = { + f = 'foo', + l = 2, + c = 200, + mX = 10, + mYYYYYYYYYY = 10, + n = (' '):byte(), + }, + }, + { + type = 1, + timestamp = 0, + data = { + c = 'abc', + f = { '!binary', { 'abc\ndef' } }, + l = -10, + n = -64, + rc = '10', + rt = 10, + sc = { '!nil', 0 }, + sm = 'TRUE', + so = 'TRUE', + sp = { '!string', { 'abc' } }, + }, + }, }, { - type=1, timestamp=0, data={ - c='abc', - f={'!binary', {'abc\ndef'}}, - l=-10, - n=-64, - rc='10', - rt=10, - sc={'!nil', 0}, - sm='TRUE', - so='TRUE', - sp={'!string', {'abc'}}, - } - }}, { 'Change with timestamp ' .. epoch .. ':', ' % Key________ Description Value', ' + f file name "foo"', @@ -1390,7 +1643,7 @@ describe('autoload/shada.vim', function() ' + c column 200', ' + mX 10', ' + mYYYYYYYYYY 10', - ' + n name \' \'', + " + n name ' '", 'Header with timestamp ' .. epoch .. ':', ' % Key Description____ Value', ' # Expected integer', @@ -1404,7 +1657,7 @@ describe('autoload/shada.vim', function() ' # Expected array value', ' + rc contents "10"', ' # Unexpected enum value: expected one of ' - .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)', + .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)', ' + rt type 10', ' # Expected boolean', ' + sc smartcase value NIL', @@ -1422,23 +1675,37 @@ describe('autoload/shada.vim', function() end) it('works with header items', function() - strings2sd_eq({{type=1, timestamp=0, data={ - generator='test', - }}}, { + strings2sd_eq({ { type = 1, timestamp = 0, data = { + generator = 'test', + } } }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', }) - strings2sd_eq({{type=1, timestamp=0, data={ - 1, 2, 3, - }}}, { - 'Header with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=1, timestamp=0, data={ - a=1, b=2, c=3, d=4, - }}}, { + strings2sd_eq( + { { type = 1, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Header with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ + { + type = 1, + timestamp = 0, + data = { + a = 1, + b = 2, + c = 3, + d = 4, + }, + }, + }, { 'Header with timestamp ' .. epoch .. ':', ' % Key Description Value', ' + a 1', @@ -1446,18 +1713,24 @@ describe('autoload/shada.vim', function() ' + c column 3', ' + d 4', }) - strings2sd_eq({{type=1, timestamp=0, data={ - c='abc', - f={'!binary', {'abc\ndef'}}, - l=-10, - n=-64, - rc='10', - rt=10, - sc={'!nil', 0}, - sm='TRUE', - so='TRUE', - sp={'!string', {'abc'}}, - }}}, { + strings2sd_eq({ + { + type = 1, + timestamp = 0, + data = { + c = 'abc', + f = { '!binary', { 'abc\ndef' } }, + l = -10, + n = -64, + rc = '10', + rt = 10, + sc = { '!nil', 0 }, + sm = 'TRUE', + so = 'TRUE', + sp = { '!string', { 'abc' } }, + }, + }, + }, { 'Header with timestamp ' .. epoch .. ':', ' % Key Description____ Value', ' # Expected integer', @@ -1471,7 +1744,7 @@ describe('autoload/shada.vim', function() ' # Expected array value', ' + rc contents "10"', ' # Unexpected enum value: expected one of ' - .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)', + .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)', ' + rt type 10', ' # Expected boolean', ' + sc smartcase value NIL', @@ -1485,16 +1758,21 @@ describe('autoload/shada.vim', function() end) it('works with search pattern items', function() - strings2sd_eq({{type=2, timestamp=0, data={ - 1, 2, 3 - }}}, { - 'Search pattern with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=2, timestamp=0, data={ - sp='abc', - }}}, { + strings2sd_eq( + { { type = 2, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Search pattern with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ { type = 2, timestamp = 0, data = { + sp = 'abc', + } } }, { 'Search pattern with timestamp ' .. epoch .. ':', ' % Key Description________ Value', ' + sp pattern "abc"', @@ -1507,12 +1785,18 @@ describe('autoload/shada.vim', function() ' + so offset value 0', ' + su is last used TRUE', }) - strings2sd_eq({{type=2, timestamp=0, data={ - sp='abc', - sX={'!nil', 0}, - sY={'!nil', 0}, - sZ={'!nil', 0}, - }}}, { + strings2sd_eq({ + { + type = 2, + timestamp = 0, + data = { + sp = 'abc', + sX = { '!nil', 0 }, + sY = { '!nil', 0 }, + sZ = { '!nil', 0 }, + }, + }, + }, { 'Search pattern with timestamp ' .. epoch .. ':', ' % Key Description________ Value', ' + sp pattern "abc"', @@ -1528,8 +1812,7 @@ describe('autoload/shada.vim', function() ' + sY NIL', ' + sZ NIL', }) - strings2sd_eq({{type=2, timestamp=0, data={'!map', { - }}}}, { + strings2sd_eq({ { type = 2, timestamp = 0, data = { '!map', {} } } }, { 'Search pattern with timestamp ' .. epoch .. ':', ' % Key Description________ Value', ' # Required key missing: sp', @@ -1542,17 +1825,23 @@ describe('autoload/shada.vim', function() ' + so offset value 0', ' + su is last used TRUE', }) - strings2sd_eq({{type=2, timestamp=0, data={ - sp='', - sh={'!boolean', 1}, - ss={'!boolean', 1}, - sc={'!boolean', 1}, - sl={'!boolean', 1}, - se={'!boolean', 1}, - sm={'!boolean', 0}, - su={'!boolean', 0}, - so=-10, - }}}, { + strings2sd_eq({ + { + type = 2, + timestamp = 0, + data = { + sp = '', + sh = { '!boolean', 1 }, + ss = { '!boolean', 1 }, + sc = { '!boolean', 1 }, + sl = { '!boolean', 1 }, + se = { '!boolean', 1 }, + sm = { '!boolean', 0 }, + su = { '!boolean', 0 }, + so = -10, + }, + }, + }, { 'Search pattern with timestamp ' .. epoch .. ':', ' % Key Description________ Value', ' + sp pattern ""', @@ -1565,17 +1854,23 @@ describe('autoload/shada.vim', function() ' + so offset value -10', ' + su is last used FALSE', }) - strings2sd_eq({{type=2, timestamp=0, data={ - sp=0, - sh=0, - ss=0, - sc=0, - sl=0, - se=0, - sm=0, - su=0, - so='', - }}}, { + strings2sd_eq({ + { + type = 2, + timestamp = 0, + data = { + sp = 0, + sh = 0, + ss = 0, + sc = 0, + sl = 0, + se = 0, + sm = 0, + su = 0, + so = '', + }, + }, + }, { 'Search pattern with timestamp ' .. epoch .. ':', ' % Key Description________ Value', ' # Expected binary string', @@ -1600,38 +1895,41 @@ describe('autoload/shada.vim', function() end) it('works with replacement string items', function() - strings2sd_eq({{type=3, timestamp=0, data={ - a={10} - }}}, { + strings2sd_eq({ { type = 3, timestamp = 0, data = { + a = { 10 }, + } } }, { 'Replacement string with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', }) - strings2sd_eq({{type=3, timestamp=0, data={ - }}}, { + strings2sd_eq({ { type = 3, timestamp = 0, data = {} } }, { 'Replacement string with timestamp ' .. epoch .. ':', ' @ Description__________ Value', - ' # Expected more elements in list' + ' # Expected more elements in list', }) - strings2sd_eq({{type=3, timestamp=0, data={ - 0 - }}}, { + strings2sd_eq({ { type = 3, timestamp = 0, data = { + 0, + } } }, { 'Replacement string with timestamp ' .. epoch .. ':', ' @ Description__________ Value', ' # Expected binary string', ' - :s replacement string 0', }) - strings2sd_eq({{type=3, timestamp=0, data={ - 'abc\ndef', 0, - }}}, { - 'Replacement string with timestamp ' .. epoch .. ':', - ' @ Description__________ Value', - ' - :s replacement string "abc\\ndef"', - ' - 0', - }) - strings2sd_eq({{type=3, timestamp=0, data={ + strings2sd_eq( + { { type = 3, timestamp = 0, data = { + 'abc\ndef', + 0, + } } }, + { + 'Replacement string with timestamp ' .. epoch .. ':', + ' @ Description__________ Value', + ' - :s replacement string "abc\\ndef"', + ' - 0', + } + ) + strings2sd_eq({ { type = 3, timestamp = 0, data = { 'abc\ndef', - }}}, { + } } }, { 'Replacement string with timestamp ' .. epoch .. ':', ' @ Description__________ Value', ' - :s replacement string "abc\\ndef"', @@ -1639,95 +1937,114 @@ describe('autoload/shada.vim', function() end) it('works with history entry items', function() - strings2sd_eq({{type=4, timestamp=0, data={ - a={10}, - }}}, { + strings2sd_eq({ { type = 4, timestamp = 0, data = { + a = { 10 }, + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', }) - strings2sd_eq({{type=4, timestamp=0, data={ - }}}, { + strings2sd_eq({ { type = 4, timestamp = 0, data = {} } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', - ' # Expected more elements in list' + ' # Expected more elements in list', }) - strings2sd_eq({{type=4, timestamp=0, data={ + strings2sd_eq({ { type = 4, timestamp = 0, data = { '', - }}}, { + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', ' # Expected integer', ' - history type ""', - ' # Expected more elements in list' + ' # Expected more elements in list', }) - strings2sd_eq({{type=4, timestamp=0, data={ - 5, '', - }}}, { + strings2sd_eq({ { type = 4, timestamp = 0, data = { + 5, + '', + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' - .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)', + .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)', ' - history type 5', ' - contents ""', }) - strings2sd_eq({{type=4, timestamp=0, data={ - 5, '', 32, - }}}, { - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' + strings2sd_eq( + { { type = 4, timestamp = 0, data = { + 5, + '', + 32, + } } }, + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), ' .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)', - ' - history type 5', - ' - contents ""', - ' - 32', - }) - strings2sd_eq({{type=4, timestamp=0, data={ - 0, '', 32, - }}}, { - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type CMD', - ' - contents ""', - ' - 32', - }) - strings2sd_eq({{type=4, timestamp=0, data={ - 1, '', 32, - }}}, { - 'History entry with timestamp ' .. epoch .. ':', - ' @ Description_ Value', - ' - history type SEARCH', - ' - contents ""', - ' - separator \' \'', - }) - strings2sd_eq({{type=4, timestamp=0, data={ - 1, '', - }}}, { + ' - history type 5', + ' - contents ""', + ' - 32', + } + ) + strings2sd_eq( + { { type = 4, timestamp = 0, data = { + 0, + '', + 32, + } } }, + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type CMD', + ' - contents ""', + ' - 32', + } + ) + strings2sd_eq( + { { type = 4, timestamp = 0, data = { + 1, + '', + 32, + } } }, + { + 'History entry with timestamp ' .. epoch .. ':', + ' @ Description_ Value', + ' - history type SEARCH', + ' - contents ""', + " - separator ' '", + } + ) + strings2sd_eq({ { type = 4, timestamp = 0, data = { + 1, + '', + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', ' - history type SEARCH', ' - contents ""', ' # Expected more elements in list', }) - strings2sd_eq({{type=4, timestamp=0, data={ - 2, '', - }}}, { + strings2sd_eq({ { type = 4, timestamp = 0, data = { + 2, + '', + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', ' - history type EXPR', ' - contents ""', }) - strings2sd_eq({{type=4, timestamp=0, data={ - 3, '' - }}}, { + strings2sd_eq({ { type = 4, timestamp = 0, data = { + 3, + '', + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', ' - history type INPUT', ' - contents ""', }) - strings2sd_eq({{type=4, timestamp=0, data={ - 4, '' - }}}, { + strings2sd_eq({ { type = 4, timestamp = 0, data = { + 4, + '', + } } }, { 'History entry with timestamp ' .. epoch .. ':', ' @ Description_ Value', ' - history type DEBUG', @@ -1736,15 +2053,19 @@ describe('autoload/shada.vim', function() end) it('works with register items', function() - strings2sd_eq({{type=5, timestamp=0, data={ - 1, 2, 3 - }}}, { - 'Register with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=5, timestamp=0, data={'!map', { - }}}}, { + strings2sd_eq( + { { type = 5, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Register with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ { type = 5, timestamp = 0, data = { '!map', {} } } }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Required key missing: n', @@ -1752,121 +2073,166 @@ describe('autoload/shada.vim', function() ' + rw block width 0', ' + rt type CHARACTERWISE', }) - strings2sd_eq({{type=5, timestamp=0, data={ - n=(' '):byte() - }}}, { + strings2sd_eq({ { type = 5, timestamp = 0, data = { + n = (' '):byte(), + } } }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' # Required key missing: rc', ' + rw block width 0', ' + rt type CHARACTERWISE', }) - strings2sd_eq({{type=5, timestamp=0, data={ - n=(' '):byte(), rc={'abc', 'def'} - }}}, { + strings2sd_eq({ + { + type = 5, + timestamp = 0, + data = { + n = (' '):byte(), + rc = { 'abc', 'def' }, + }, + }, + }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' + rc contents ["abc", "def"]', ' + rw block width 0', ' + rt type CHARACTERWISE', }) - strings2sd_eq({{type=5, timestamp=0, data={ - n=(' '):byte(), - rc={'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'}, - }}}, { + strings2sd_eq({ + { + type = 5, + timestamp = 0, + data = { + n = (' '):byte(), + rc = { 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz' }, + }, + }, + }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' + rc contents @', ' | - "abcdefghijklmnopqrstuvwxyz"', ' | - "abcdefghijklmnopqrstuvwxyz"', ' + rw block width 0', ' + rt type CHARACTERWISE', }) - strings2sd_eq({{type=5, timestamp=0, data={ - n=(' '):byte(), - rc={'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'}, - rw=5, - rt=1, - }}}, { + strings2sd_eq({ + { + type = 5, + timestamp = 0, + data = { + n = (' '):byte(), + rc = { 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz' }, + rw = 5, + rt = 1, + }, + }, + }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' + rc contents @', ' | - "abcdefghijklmnopqrstuvwxyz"', ' | - "abcdefghijklmnopqrstuvwxyz"', ' + rw block width 5', ' + rt type LINEWISE', }) - strings2sd_eq({{type=5, timestamp=0, data={ - n=(' '):byte(), - rc={'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'}, - rw=5, - rt=2, - }}}, { + strings2sd_eq({ + { + type = 5, + timestamp = 0, + data = { + n = (' '):byte(), + rc = { 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz' }, + rw = 5, + rt = 2, + }, + }, + }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' + rc contents @', ' | - "abcdefghijklmnopqrstuvwxyz"', ' | - "abcdefghijklmnopqrstuvwxyz"', ' + rw block width 5', ' + rt type BLOCKWISE', }) - strings2sd_eq({{type=5, timestamp=0, data={ - n=(' '):byte(), - rc=0, - rw=-1, - rt=10, - }}}, { + strings2sd_eq({ + { + type = 5, + timestamp = 0, + data = { + n = (' '):byte(), + rc = 0, + rw = -1, + rt = 10, + }, + }, + }, { 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' # Expected array value', ' + rc contents 0', ' # Value is negative', ' + rw block width -1', ' # Unexpected enum value: expected one of 0 (CHARACTERWISE), ' - .. '1 (LINEWISE), 2 (BLOCKWISE)', + .. '1 (LINEWISE), 2 (BLOCKWISE)', ' + rt type 10', }) end) it('works with variable items', function() - strings2sd_eq({{type=6, timestamp=0, data={ - a={10} - }}}, { + strings2sd_eq({ { type = 6, timestamp = 0, data = { + a = { 10 }, + } } }, { 'Variable with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', }) - strings2sd_eq({{type=6, timestamp=0, data={ - }}}, { + strings2sd_eq({ { type = 6, timestamp = 0, data = {} } }, { 'Variable with timestamp ' .. epoch .. ':', ' @ Description Value', - ' # Expected more elements in list' + ' # Expected more elements in list', }) - strings2sd_eq({{type=6, timestamp=0, data={ + strings2sd_eq({ { type = 6, timestamp = 0, data = { 'foo', - }}}, { + } } }, { 'Variable with timestamp ' .. epoch .. ':', ' @ Description Value', ' - name "foo"', ' # Expected more elements in list', }) - strings2sd_eq({{type=6, timestamp=0, data={ - 'foo', {'!nil', 0}, - }}}, { + strings2sd_eq({ + { + type = 6, + timestamp = 0, + data = { + 'foo', + { '!nil', 0 }, + }, + }, + }, { 'Variable with timestamp ' .. epoch .. ':', ' @ Description Value', ' - name "foo"', ' - value NIL', }) - strings2sd_eq({{type=6, timestamp=0, data={ - 'foo', {'!nil', 0}, {'!nil', 0} - }}}, { + strings2sd_eq({ + { + type = 6, + timestamp = 0, + data = { + 'foo', + { '!nil', 0 }, + { '!nil', 0 }, + }, + }, + }, { 'Variable with timestamp ' .. epoch .. ':', ' @ Description Value', ' - name "foo"', @@ -1876,19 +2242,35 @@ describe('autoload/shada.vim', function() end) it('works with global mark items', function() - strings2sd_eq({{type=7, timestamp=0, data={ - 1, 2, 3 - }}}, { - 'Global mark with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=7, timestamp=0, data={ - n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10, - }}}, { + strings2sd_eq( + { { type = 7, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Global mark with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ + { + type = 7, + timestamp = 0, + data = { + n = ('A'):byte(), + f = 'foo', + l = 2, + c = 200, + mX = 10, + mYYYYYYYYYY = 10, + }, + }, + }, { 'Global mark with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name "foo"', ' + l line number 2', ' + c column 200', @@ -1898,19 +2280,35 @@ describe('autoload/shada.vim', function() end) it('works with jump items', function() - strings2sd_eq({{type=8, timestamp=0, data={ - 1, 2, 3 - }}}, { - 'Jump with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=8, timestamp=0, data={ - n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10, - }}}, { + strings2sd_eq( + { { type = 8, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Jump with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ + { + type = 8, + timestamp = 0, + data = { + n = ('A'):byte(), + f = 'foo', + l = 2, + c = 200, + mX = 10, + mYYYYYYYYYY = 10, + }, + }, + }, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name "foo"', ' + l line number 2', ' + c column 200', @@ -1920,23 +2318,27 @@ describe('autoload/shada.vim', function() end) it('works with buffer list items', function() - strings2sd_eq({{type=9, timestamp=0, data={ - a={10} - }}}, { + strings2sd_eq({ { type = 9, timestamp = 0, data = { + a = { 10 }, + } } }, { 'Buffer list with timestamp ' .. epoch .. ':', ' # Unexpected type: map instead of array', ' = {="a": [10]}', }) - strings2sd_eq({{type=9, timestamp=0, data={ - {a=10}, {} - }}}, { - 'Buffer list with timestamp ' .. epoch .. ':', - ' # Expected array of maps', - ' = [{="a": 10}, []]', - }) - strings2sd_eq({{type=9, timestamp=0, data={ - {a=10}, - }}}, { + strings2sd_eq( + { { type = 9, timestamp = 0, data = { + { a = 10 }, + {}, + } } }, + { + 'Buffer list with timestamp ' .. epoch .. ':', + ' # Expected array of maps', + ' = [{="a": 10}, []]', + } + ) + strings2sd_eq({ { type = 9, timestamp = 0, data = { + { a = 10 }, + } } }, { 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Required key missing: f', @@ -1944,9 +2346,15 @@ describe('autoload/shada.vim', function() ' + c column 0', ' + a 10', }) - strings2sd_eq({{type=9, timestamp=0, data={ - {l='10', c='10', a=10}, - }}}, { + strings2sd_eq({ + { + type = 9, + timestamp = 0, + data = { + { l = '10', c = '10', a = 10 }, + }, + }, + }, { 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Required key missing: f', @@ -1956,59 +2364,79 @@ describe('autoload/shada.vim', function() ' + c column "10"', ' + a 10', }) - strings2sd_eq({{type=9, timestamp=0, data={ - {l=10, c=10, a=10}, - }}}, { - 'Buffer list with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' + l line number 10', - ' + c column 10', - ' + a 10', - }) - strings2sd_eq({{type=9, timestamp=0, data={ - {l=-10, c=-10}, - }}}, { - 'Buffer list with timestamp ' .. epoch .. ':', - ' % Key Description Value', - ' # Required key missing: f', - ' # Value is negative', - ' + l line number -10', - ' # Value is negative', - ' + c column -10', - }) - strings2sd_eq({{type=9, timestamp=0, data={ - {f='abc'}, - }}}, { + strings2sd_eq( + { { type = 9, timestamp = 0, data = { + { l = 10, c = 10, a = 10 }, + } } }, + { + 'Buffer list with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' + l line number 10', + ' + c column 10', + ' + a 10', + } + ) + strings2sd_eq( + { { type = 9, timestamp = 0, data = { + { l = -10, c = -10 }, + } } }, + { + 'Buffer list with timestamp ' .. epoch .. ':', + ' % Key Description Value', + ' # Required key missing: f', + ' # Value is negative', + ' + l line number -10', + ' # Value is negative', + ' + c column -10', + } + ) + strings2sd_eq({ { type = 9, timestamp = 0, data = { + { f = 'abc' }, + } } }, { 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' + f file name "abc"', ' + l line number 1', ' + c column 0', }) - strings2sd_eq({{type=9, timestamp=0, data={ - {f=10}, {f=20}, - }}}, { + strings2sd_eq({ + { + type = 9, + timestamp = 0, + data = { + { f = 10 }, + { f = 20 }, + }, + }, + }, { 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Expected binary string', - ' + f file name \'\\10\'', + " + f file name '\\10'", ' + l line number 1', ' + c column 0', '', ' % Key Description Value', ' # Expected binary string', - ' + f file name \'\\20\'', + " + f file name '\\20'", ' + l line number 1', ' + c column 0', }) - strings2sd_eq({{type=9, timestamp=0, data={ - {f=10}, {f={'!binary', {'\n'}}}, - }}}, { + strings2sd_eq({ + { + type = 9, + timestamp = 0, + data = { + { f = 10 }, + { f = { '!binary', { '\n' } } }, + }, + }, + }, { 'Buffer list with timestamp ' .. epoch .. ':', ' % Key Description Value', ' # Expected binary string', - ' + f file name \'\\10\'', + " + f file name '\\10'", ' + l line number 1', ' + c column 0', '', @@ -2021,19 +2449,35 @@ describe('autoload/shada.vim', function() end) it('works with local mark items', function() - strings2sd_eq({{type=10, timestamp=0, data={ - 1, 2, 3 - }}}, { - 'Local mark with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=10, timestamp=0, data={ - n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10, - }}}, { + strings2sd_eq( + { { type = 10, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Local mark with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ + { + type = 10, + timestamp = 0, + data = { + n = ('A'):byte(), + f = 'foo', + l = 2, + c = 200, + mX = 10, + mYYYYYYYYYY = 10, + }, + }, + }, { 'Local mark with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name "foo"', ' + l line number 2', ' + c column 200', @@ -2043,19 +2487,35 @@ describe('autoload/shada.vim', function() end) it('works with change items', function() - strings2sd_eq({{type=11, timestamp=0, data={ - 1, 2, 3 - }}}, { - 'Change with timestamp ' .. epoch .. ':', - ' # Unexpected type: array instead of map', - ' = [1, 2, 3]', - }) - strings2sd_eq({{type=11, timestamp=0, data={ - n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10, - }}}, { + strings2sd_eq( + { { type = 11, timestamp = 0, data = { + 1, + 2, + 3, + } } }, + { + 'Change with timestamp ' .. epoch .. ':', + ' # Unexpected type: array instead of map', + ' = [1, 2, 3]', + } + ) + strings2sd_eq({ + { + type = 11, + timestamp = 0, + data = { + n = ('A'):byte(), + f = 'foo', + l = 2, + c = 200, + mX = 10, + mYYYYYYYYYY = 10, + }, + }, + }, { 'Change with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name "foo"', ' + l line number 2', ' + c column 200', @@ -2077,30 +2537,52 @@ describe('autoload/shada.vim', function() it('works', function() local version = nvim('get_vvar', 'version') - getbstrings_eq({{timestamp='current', type=1, value={ - generator='shada.vim', - version=version, - }}}, {}) getbstrings_eq({ - {timestamp='current', type=1, value={ - generator='shada.vim', version=version - }}, - {timestamp=0, type=1, value={generator='test'}} + { + timestamp = 'current', + type = 1, + value = { + generator = 'shada.vim', + version = version, + }, + }, + }, {}) + getbstrings_eq({ + { + timestamp = 'current', + type = 1, + value = { + generator = 'shada.vim', + version = version, + }, + }, + { timestamp = 0, type = 1, value = { generator = 'test' } }, }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', }) nvim('set_var', 'shada#add_own_header', 1) - getbstrings_eq({{timestamp='current', type=1, value={ - generator='shada.vim', - version=version, - }}}, {}) getbstrings_eq({ - {timestamp='current', type=1, value={ - generator='shada.vim', version=version - }}, - {timestamp=0, type=1, value={generator='test'}} + { + timestamp = 'current', + type = 1, + value = { + generator = 'shada.vim', + version = version, + }, + }, + }, {}) + getbstrings_eq({ + { + timestamp = 'current', + type = 1, + value = { + generator = 'shada.vim', + version = version, + }, + }, + { timestamp = 0, type = 1, value = { generator = 'test' } }, }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', @@ -2108,7 +2590,7 @@ describe('autoload/shada.vim', function() }) nvim('set_var', 'shada#add_own_header', 0) getbstrings_eq({}, {}) - getbstrings_eq({{timestamp=0, type=1, value={generator='test'}}}, { + getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', @@ -2120,9 +2602,9 @@ describe('autoload/shada.vim', function() ' + generator "test"', }) getbstrings_eq({ - {type=3, timestamp=0, value={'abc\ndef'}}, - {type=3, timestamp=0, value={'abc\ndef'}}, - {type=3, timestamp=0, value={'abc\ndef'}}, + { type = 3, timestamp = 0, value = { 'abc\ndef' } }, + { type = 3, timestamp = 0, value = { 'abc\ndef' } }, + { type = 3, timestamp = 0, value = { 'abc\ndef' } }, }, { 'Replacement string with timestamp ' .. epoch .. ':', ' @ Description__________ Value', @@ -2164,8 +2646,7 @@ describe('plugin/shada.vim', function() wshada('\004\000\009\147\000\196\002ab\196\001a') wshada_tmp('\004\000\009\147\000\196\002ab\196\001b') - - local bufread_commands = meths.get_autocmds({ group = "ShaDaCommands", event = "BufReadCmd" }) + local bufread_commands = meths.get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) eq(2, #bufread_commands--[[, vim.inspect(bufread_commands) ]]) -- Need to set nohidden so that the buffer containing 'fname' is not unloaded @@ -2259,13 +2740,13 @@ describe('plugin/shada.vim', function() curbuf('set_lines', 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', @@ -2277,35 +2758,41 @@ describe('plugin/shada.vim', function() eq(table.concat({ 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', }, eol) .. eol, read_file(fname .. '.tst')) - shada_eq({{ - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }, { - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }}, fname) - shada_eq({{ - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }, { - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }}, fname_tmp) + shada_eq({ + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + }, fname) + shada_eq({ + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + }, fname_tmp) end) it('event FileWriteCmd', function() @@ -2314,13 +2801,13 @@ describe('plugin/shada.vim', function() curbuf('set_lines', 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', @@ -2332,18 +2819,24 @@ describe('plugin/shada.vim', function() eq(table.concat({ 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", }, eol) .. eol, read_file(fname .. '.tst')) - shada_eq({{ - timestamp=0, - type=8, - value={n=('A'):byte()}, - }}, fname) - shada_eq({{ - timestamp=0, - type=8, - value={n=('A'):byte()}, - }}, fname_tmp) + shada_eq( + { { + timestamp = 0, + type = 8, + value = { n = ('A'):byte() }, + } }, + fname + ) + shada_eq( + { { + timestamp = 0, + type = 8, + value = { n = ('A'):byte() }, + } }, + fname_tmp + ) end) it('event FileAppendCmd', function() @@ -2352,20 +2845,20 @@ describe('plugin/shada.vim', function() curbuf('set_lines', 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', }) - funcs.writefile({''}, fname .. '.tst', 'b') - funcs.writefile({''}, fname, 'b') - funcs.writefile({''}, fname_tmp, 'b') + funcs.writefile({ '' }, fname .. '.tst', 'b') + funcs.writefile({ '' }, fname, 'b') + funcs.writefile({ '' }, fname_tmp, 'b') nvim_command('1,3w >> ' .. fname .. '.tst') nvim_command('1,3w >> ' .. fname) nvim_command('1,3w >> ' .. fname_tmp) @@ -2376,52 +2869,60 @@ describe('plugin/shada.vim', function() eq(table.concat({ 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', }, eol) .. eol, read_file(fname .. '.tst')) - shada_eq({{ - timestamp=0, - type=8, - value={n=('A'):byte()}, - }, { - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }, { - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }}, fname) - shada_eq({{ - timestamp=0, - type=8, - value={n=('A'):byte()}, - }, { - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }, { - timestamp=0, - type=8, - value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, - }}, fname_tmp) + shada_eq({ + { + timestamp = 0, + type = 8, + value = { n = ('A'):byte() }, + }, + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + }, fname) + shada_eq({ + { + timestamp = 0, + type = 8, + value = { n = ('A'):byte() }, + }, + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + { + timestamp = 0, + type = 8, + value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() }, + }, + }, fname_tmp) end) it('event SourceCmd', function() reset(fname) finally(function() - nvim_command('set shadafile=NONE') -- Avoid writing shada file on exit + nvim_command('set shadafile=NONE') -- Avoid writing shada file on exit end) wshada('\004\000\006\146\000\196\002ab') wshada_tmp('\004\001\006\146\000\196\002bc') @@ -2442,7 +2943,7 @@ describe('ftplugin/shada.vim', function() funcs.setline(1, { 'Jump with timestamp ' .. epoch .. ':', '% Key________ Description Value', - '+ n name \'A\'', + "+ n name 'A'", '+ f file name "foo"', '+ l line number 2', '+ c column 200', @@ -2450,7 +2951,7 @@ describe('ftplugin/shada.vim', function() '+ mYYYYYYYYYY 10', 'Register with timestamp ' .. epoch .. ':', '% Key Description Value', - '+ n name \' \'', + "+ n name ' '", '+ rc contents @', '| - "abcdefghijklmnopqrstuvwxyz"', '| - "abcdefghijklmnopqrstuvwxyz"', @@ -2479,7 +2980,7 @@ describe('ftplugin/shada.vim', function() eq({ 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name "foo"', ' + l line number 2', ' + c column 200', @@ -2487,7 +2988,7 @@ describe('ftplugin/shada.vim', function() ' + mYYYYYYYYYY 10', 'Register with timestamp ' .. epoch .. ':', ' % Key Description Value', - ' + n name \' \'', + " + n name ' '", ' + rc contents @', ' | - "abcdefghijklmnopqrstuvwxyz"', ' | - "abcdefghijklmnopqrstuvwxyz"', @@ -2530,15 +3031,15 @@ describe('ftplugin/shada.vim', function() nvim_feed('ggA:\027') eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1]) nvim_feed('o-\027') - eq({' -'}, curbuf('get_lines', 1, 2, true)) + eq({ ' -' }, curbuf('get_lines', 1, 2, true)) nvim_feed('ggO+\027') - eq({'+'}, curbuf('get_lines', 0, 1, true)) + eq({ '+' }, curbuf('get_lines', 0, 1, true)) nvim_feed('GO*\027') - eq({' *'}, curbuf('get_lines', 2, 3, true)) + eq({ ' *' }, curbuf('get_lines', 2, 3, true)) nvim_feed('ggO /\027') - eq({' /'}, curbuf('get_lines', 0, 1, true)) + eq({ ' /' }, curbuf('get_lines', 0, 1, true)) nvim_feed('ggOx\027') - eq({'x'}, curbuf('get_lines', 0, 1, true)) + eq({ 'x' }, curbuf('get_lines', 0, 1, true)) end) end) @@ -2552,14 +3053,14 @@ describe('syntax/shada.vim', function() nvim_command('set laststatus&') local screen = Screen.new(60, 37) screen:set_default_attr_ids { - [1] = {bold = true, foreground = Screen.colors.Brown}; - [2] = {foreground = tonumber('0x6a0dad')}; - [3] = {foreground = Screen.colors.Fuchsia}; - [4] = {foreground = Screen.colors.Blue1}; - [5] = {bold = true, foreground = Screen.colors.SeaGreen4}; - [6] = {foreground = Screen.colors.SlateBlue}; - [7] = {bold = true, reverse = true}; - [8] = {bold = true, foreground = Screen.colors.Blue}; + [1] = { bold = true, foreground = Screen.colors.Brown }, + [2] = { foreground = tonumber('0x6a0dad') }, + [3] = { foreground = Screen.colors.Fuchsia }, + [4] = { foreground = Screen.colors.Blue1 }, + [5] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [6] = { foreground = Screen.colors.SlateBlue }, + [7] = { bold = true, reverse = true }, + [8] = { bold = true, foreground = Screen.colors.Blue }, } screen:attach() @@ -2569,7 +3070,7 @@ describe('syntax/shada.vim', function() ' + t "test"', 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', - ' + n name \'A\'', + " + n name 'A'", ' + f file name ["foo"]', ' + l line number 2', ' + c column -200', @@ -2598,7 +3099,8 @@ describe('syntax/shada.vim', function() ' % Key Description________ Value', ' + se place cursor at end TRUE', }) - screen:expect{grid=[=[ + screen:expect { + grid = [=[ {1:^Header} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | {2: % Key Value} | {1: +} {3:t } {1:"}{3:test}{1:"} | @@ -2636,7 +3138,8 @@ describe('syntax/shada.vim', function() {8:~ }| {7:[No Name] [+] }| | - ]=]} + ]=], + } nvim_command([[ function GetSyntax() @@ -2657,15 +3160,20 @@ describe('syntax/shada.vim', function() return lines endfunction ]]) - local hname = function(s) return {{'ShaDaEntryHeader', 'ShaDaEntryName'}, - s} end - local h = function(s) return {{'ShaDaEntryHeader'}, s} end - local htsnum = function(s) return { - {'ShaDaEntryHeader', 'ShaDaEntryTimestamp', 'ShaDaEntryTimestampNumber'}, - s - } end + local hname = function(s) + return { { 'ShaDaEntryHeader', 'ShaDaEntryName' }, s } + end + local h = function(s) + return { { 'ShaDaEntryHeader' }, s } + end + local htsnum = function(s) + return { + { 'ShaDaEntryHeader', 'ShaDaEntryTimestamp', 'ShaDaEntryTimestampNumber' }, + s, + } + end local synhtssep = function(s) - return {{'ShaDaEntryHeader', 'ShaDaEntryTimestamp'}, s} + return { { 'ShaDaEntryHeader', 'ShaDaEntryTimestamp' }, s } end local synepoch = { year = htsnum(os.date('%Y', 0)), @@ -2675,255 +3183,435 @@ describe('syntax/shada.vim', function() minute = htsnum(os.date('%M', 0)), second = htsnum(os.date('%S', 0)), } - local msh = function(s) return {{'ShaDaEntryMapShort', - 'ShaDaEntryMapHeader'}, s} end - local mlh = function(s) return {{'ShaDaEntryMapLong', - 'ShaDaEntryMapHeader'}, s} end - local ah = function(s) return {{'ShaDaEntryArray', - 'ShaDaEntryArrayHeader'}, s} end + local msh = function(s) + return { + { 'ShaDaEntryMapShort', 'ShaDaEntryMapHeader' }, + s, + } + end + local mlh = function(s) + return { { 'ShaDaEntryMapLong', 'ShaDaEntryMapHeader' }, s } + end + local ah = function(s) + return { { 'ShaDaEntryArray', 'ShaDaEntryArrayHeader' }, s } + end -- luacheck: ignore - local mses = function(s) return {{'ShaDaEntryMapShort', - 'ShaDaEntryMapShortEntryStart'}, s} end - local mles = function(s) return {{'ShaDaEntryMapLong', - 'ShaDaEntryMapLongEntryStart'}, s} end + local mses = function(s) + return { + { + 'ShaDaEntryMapShort', + 'ShaDaEntryMapShortEntryStart', + }, + s, + } + end + local mles = function(s) + return { + { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongEntryStart' }, + s, + } + end local act = funcs.GetSyntax() local ms = function(syn) return { - {'ShaDaEntryMap' .. syn, 'ShaDaEntryMap' .. syn .. 'EntryStart'}, ' + ' + { 'ShaDaEntryMap' .. syn, 'ShaDaEntryMap' .. syn .. 'EntryStart' }, + ' + ', } end local as = function() - return {{'ShaDaEntryArray', 'ShaDaEntryArrayEntryStart'}, ' - '} + return { { 'ShaDaEntryArray', 'ShaDaEntryArrayEntryStart' }, ' - ' } + end + local ad = function(s) + return { + { 'ShaDaEntryArray', 'ShaDaEntryArrayDescription' }, + s, + } end - local ad = function(s) return {{'ShaDaEntryArray', - 'ShaDaEntryArrayDescription'}, s} end local mbas = function(syn) return { - {'ShaDaEntryMap' .. syn, 'ShaDaEntryMapBinArrayStart'}, - ' | - ' + { 'ShaDaEntryMap' .. syn, 'ShaDaEntryMapBinArrayStart' }, + ' | - ', + } + end + local msk = function(s) + return { + { 'ShaDaEntryMapShort', 'ShaDaEntryMapShortKey' }, + s, + } + end + local mlk = function(s) + return { + { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongKey' }, + s, + } + end + local mld = function(s) + return { + { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongDescription' }, + s, } end - local msk = function(s) return {{'ShaDaEntryMapShort', - 'ShaDaEntryMapShortKey'}, s} end - local mlk = function(s) return {{'ShaDaEntryMapLong', - 'ShaDaEntryMapLongKey'}, s} end - local mld = function(s) return {{'ShaDaEntryMapLong', - 'ShaDaEntryMapLongDescription'}, s} end - local c = function(s) return {{'ShaDaComment'}, s} end + local c = function(s) + return { { 'ShaDaComment' }, s } + end local exp = { { - hname('Header'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Header'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { msh(' % Key Value'), }, { - ms('Short'), msk('t '), - {{'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackStringQuotes'}, '"'}, - {{'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString'}, 'test'}, - {{'ShaDaEntryMapShort', 'ShaDaMsgpackStringQuotes'}, '"'}, + ms('Short'), + msk('t '), + { + { 'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString', 'ShaDaMsgpackStringQuotes' }, + '"', + }, + { { 'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString' }, 'test' }, + { { 'ShaDaEntryMapShort', 'ShaDaMsgpackStringQuotes' }, '"' }, }, { - hname('Jump'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Jump'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { mlh(' % Key________ Description Value'), }, { - ms('Long'), mlk('n '), mld('name '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackCharacter'}, '\'A\''}, + ms('Long'), + mlk('n '), + mld('name '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackCharacter' }, "'A'" }, }, { - ms('Long'), mlk('f '), mld('file name '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', - 'ShaDaMsgpackArrayBraces'}, '['}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackStringQuotes'}, '"'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString'}, - 'foo'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes'}, - '"'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackArrayBraces'}, ']'}, + ms('Long'), + mlk('f '), + mld('file name '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, '[' }, + { + { + 'ShaDaEntryMapLong', + 'ShaDaMsgpackArray', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackStringQuotes', + }, + '"', + }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString' }, 'foo' }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes' }, '"' }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArrayBraces' }, ']' }, }, { - ms('Long'), mlk('l '), mld('line number '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackInteger'}, '2'}, + ms('Long'), + mlk('l '), + mld('line number '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackInteger' }, '2' }, }, { - ms('Long'), mlk('c '), mld('column '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackInteger'}, '-200'}, + ms('Long'), + mlk('c '), + mld('column '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackInteger' }, '-200' }, }, { - hname('Register'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Register'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { mlh(' % Key Description Value'), }, { - ms('Long'), mlk('rc '), mld('contents '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMultilineArray'}, '@'}, + ms('Long'), + mlk('rc '), + mld('contents '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMultilineArray' }, '@' }, }, { mbas('Long'), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces'}, - '{'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackStringQuotes'}, '"'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'}, - 'abcdefghijklmnopqrstuvwxyz'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes'}, - '"'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon'}, ':'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap'}, ' '}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackFloat'}, '1.0'}, - {{'ShaDaEntryMapLong', 'ShaDaMsgpackMapBraces'}, '}'}, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces' }, '{' }, + { + { + 'ShaDaEntryMapLong', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackStringQuotes', + }, + '"', + }, + { + { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, + 'abcdefghijklmnopqrstuvwxyz', + }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes' }, '"' }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon' }, ':' }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap' }, ' ' }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackFloat' }, '1.0' }, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMapBraces' }, '}' }, }, { - ms('Long'), mlk('rt '), mld('type '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword'}, 'CHARACTERWISE'}, + ms('Long'), + mlk('rt '), + mld('type '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword' }, 'CHARACTERWISE' }, }, { - ms('Long'), mlk('rt '), mld('type '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword'}, 'LINEWISE'}, + ms('Long'), + mlk('rt '), + mld('type '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword' }, 'LINEWISE' }, }, { - ms('Long'), mlk('rt '), mld('type '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword'}, 'BLOCKWISE'}, + ms('Long'), + mlk('rt '), + mld('type '), + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword' }, 'BLOCKWISE' }, }, { - hname('Replacement string'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Replacement string'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { ah(' @ Description__________ Value'), }, { - as(), ad(':s replacement string '), - {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'CMD'}, + as(), + ad(':s replacement string '), + { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'CMD' }, }, { - as(), ad(':s replacement string '), - {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'SEARCH'}, + as(), + ad(':s replacement string '), + { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'SEARCH' }, }, { - as(), ad(':s replacement string '), - {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'EXPR'}, + as(), + ad(':s replacement string '), + { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'EXPR' }, }, { - as(), ad(':s replacement string '), - {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'INPUT'}, + as(), + ad(':s replacement string '), + { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'INPUT' }, }, { - as(), ad(':s replacement string '), - {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'DEBUG'}, + as(), + ad(':s replacement string '), + { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'DEBUG' }, }, { - hname('Buffer list'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Buffer list'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { c(' # Expected array of maps'), }, { - {{'ShaDaEntryRawMsgpack'}, ' = '}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces'}, '['}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces'}, - '{'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackString'}, '='}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackStringQuotes'}, '"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'}, - 'a'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes'}, - '"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon'}, ':'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap'}, ' '}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt'}, '+('}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt', - 'ShaDaMsgpackExtType'}, '10'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt'}, ')'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackStringQuotes'}, '"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'}, - 'ac'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackBinaryStringEscape'}, - '\\0'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'}, - 'df'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackBinaryStringEscape'}, - '\\n'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'}, - 'gi'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackBinaryStringEscape'}, - '\\"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'}, - 'tt\\.'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes'}, - '"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackComma'}, ','}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap'}, ' '}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword'}, - 'TRUE'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon'}, ':'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap'}, ' '}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword'}, - 'FALSE'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackMapBraces'}, '}'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackComma'}, ','}, - {{'ShaDaMsgpackArray'}, ' '}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces'}, - '['}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackKeyword'}, - 'NIL'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackComma'}, ','}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray'}, ' '}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt'}, '+('}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt', - 'ShaDaMsgpackExtType'}, '-10'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt'}, ')'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString', - 'ShaDaMsgpackStringQuotes'}, '"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes'}, - '"'}, - {{'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces'}, ']'}, - {{'ShaDaMsgpackArrayBraces'}, ']'}, + { { 'ShaDaEntryRawMsgpack' }, ' = ' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, '[' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces' }, '{' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackString' }, '=' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackStringQuotes', + }, + '"', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'a' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes' }, '"' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon' }, ':' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap' }, ' ' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt' }, '+(' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackExt', + 'ShaDaMsgpackExtType', + }, + '10', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt' }, ')' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackStringQuotes', + }, + '"', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'ac' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackBinaryStringEscape', + }, + '\\0', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'df' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackBinaryStringEscape', + }, + '\\n', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'gi' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackMap', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackBinaryStringEscape', + }, + '\\"', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'tt\\.' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes' }, '"' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackComma' }, ',' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap' }, ' ' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword' }, 'TRUE' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon' }, ':' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap' }, ' ' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword' }, 'FALSE' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMapBraces' }, '}' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackComma' }, ',' }, + { { 'ShaDaMsgpackArray' }, ' ' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, '[' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackKeyword' }, 'NIL' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackComma' }, ',' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray' }, ' ' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt' }, '+(' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackArray', + 'ShaDaMsgpackExt', + 'ShaDaMsgpackExtType', + }, + '-10', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt' }, ')' }, + { + { + 'ShaDaMsgpackArray', + 'ShaDaMsgpackArray', + 'ShaDaMsgpackBinaryString', + 'ShaDaMsgpackStringQuotes', + }, + '"', + }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes' }, '"' }, + { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, ']' }, + { { 'ShaDaMsgpackArrayBraces' }, ']' }, }, { - hname('Buffer list'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Buffer list'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { mlh(' % Key Description Value'), }, - { - }, + {}, { mlh(' % Key Description Value'), }, { - hname('Header'), h(' with timestamp '), - synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'), - synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'), - synepoch.minute, synhtssep(':'), synepoch.second, h(':'), + hname('Header'), + h(' with timestamp '), + synepoch.year, + synhtssep('-'), + synepoch.month, + synhtssep('-'), + synepoch.day, + synhtssep('T'), + synepoch.hour, + synhtssep(':'), + synepoch.minute, + synhtssep(':'), + synepoch.second, + h(':'), }, { mlh(' % Key Description________ Value'), @@ -2932,7 +3620,7 @@ describe('syntax/shada.vim', function() mles(' + '), mlk('se '), mld('place cursor at end '), - {{'ShaDaEntryMapLong', 'ShaDaMsgpackKeyword'}, 'TRUE'}, + { { 'ShaDaEntryMapLong', 'ShaDaMsgpackKeyword' }, 'TRUE' }, }, } eq(exp, act) diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index bd214e9c03..99538e1db0 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -25,7 +25,8 @@ describe(':Tutor', function() end) it('applies {unix:…,win:…} transform', function() - local expected = is_os('win') and [[ + local expected = is_os('win') + and [[ {0: }^ | {0: } 3. To verify that a file was retrieved, cursor back and notice that there | {0: } are now two copies of Lesson 5.3, the original and the retrieved version. | @@ -56,7 +57,8 @@ describe(':Tutor', function() {0: } 5. {2::r !dir} reads the output of the dir command and | {0: } puts it below the cursor position. | {0: } | - ]] or [[ + ]] + or [[ {0: }^ | {0: } 3. To verify that a file was retrieved, cursor back and notice that there | {0: } are now two copies of Lesson 5.3, the original and the retrieved version. | -- cgit From d33e1da9b7f7e886219cfdd20b9bbfaccdc43be9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:28:20 +0000 Subject: test: do not inject vim module into global helpers --- test/functional/plugin/lsp/helpers.lua | 2 +- test/functional/plugin/lsp_spec.lua | 47 +++++++++++++++++---------------- test/functional/plugin/man_spec.lua | 2 +- test/functional/plugin/msgpack_spec.lua | 8 +++--- 4 files changed, 31 insertions(+), 28 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index f641b42727..97fa108500 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local exec_lua = helpers.exec_lua local run = helpers.run local stop = helpers.stop -local NIL = helpers.NIL +local NIL = vim.NIL local M = {} diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 86b9be79e0..d794a34463 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -11,12 +11,12 @@ local eq = helpers.eq local eval = helpers.eval local matches = helpers.matches local pcall_err = helpers.pcall_err -local pesc = helpers.pesc +local pesc = vim.pesc local insert = helpers.insert local funcs = helpers.funcs local retry = helpers.retry local stop = helpers.stop -local NIL = helpers.NIL +local NIL = vim.NIL local read_file = require('test.helpers').read_file local write_file = require('test.helpers').write_file local is_ci = helpers.is_ci @@ -24,6 +24,7 @@ local meths = helpers.meths local is_os = helpers.is_os local skip = helpers.skip local mkdir = helpers.mkdir +local tmpname = helpers.tmpname local clear_notrace = lsp_helpers.clear_notrace local create_server_definition = lsp_helpers.create_server_definition @@ -728,8 +729,8 @@ describe('LSP', function() on_handler = function(err, result, ctx) eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'start' then - local tmpfile_old = helpers.tmpname() - local tmpfile_new = helpers.tmpname() + local tmpfile_old = tmpname() + local tmpfile_new = tmpname() os.remove(tmpfile_new) exec_lua( [=[ @@ -2278,7 +2279,7 @@ describe('LSP', function() ) end) it('Supports file creation with CreateFile payload', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) -- Should not exist, only interested in a tmpname local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2295,7 +2296,7 @@ describe('LSP', function() it( 'Supports file creation in folder that needs to be created with CreateFile payload', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) -- Should not exist, only interested in a tmpname tmpfile = tmpfile .. '/dummy/x/' local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) @@ -2312,7 +2313,7 @@ describe('LSP', function() end ) it('createFile does not touch file if it exists and ignoreIfExists is set', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Dummy content') local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2331,7 +2332,7 @@ describe('LSP', function() eq('Dummy content', read_file(tmpfile)) end) it('createFile overrides file if overwrite is set', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Dummy content') local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2351,7 +2352,7 @@ describe('LSP', function() eq('', read_file(tmpfile)) end) it('DeleteFile delete file and buffer', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Be gone') local uri = exec_lua( [[ @@ -2375,7 +2376,7 @@ describe('LSP', function() eq(false, exec_lua('return vim.api.nvim_buf_is_loaded(vim.fn.bufadd(...))', tmpfile)) end) it('DeleteFile fails if file does not exist and ignoreIfNotExists is false', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2398,9 +2399,9 @@ describe('LSP', function() local pathsep = helpers.get_pathsep() it('Can rename an existing file', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Test content') - local new = helpers.tmpname() + local new = tmpname() os.remove(new) -- only reserve the name, file must not exist for the test scenario local lines = exec_lua( [[ @@ -2424,9 +2425,9 @@ describe('LSP', function() os.remove(new) end) it('Kills old buffer after renaming an existing file', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Test content') - local new = helpers.tmpname() + local new = tmpname() os.remove(new) -- only reserve the name, file must not exist for the test scenario local lines = exec_lua( [[ @@ -2444,8 +2445,8 @@ describe('LSP', function() end) it('Can rename a directory', function() -- only reserve the name, file must not exist for the test scenario - local old_dir = helpers.tmpname() - local new_dir = helpers.tmpname() + local old_dir = tmpname() + local new_dir = tmpname() os.remove(old_dir) os.remove(new_dir) @@ -2479,9 +2480,9 @@ describe('LSP', function() it( 'Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Old File') - local new = helpers.tmpname() + local new = tmpname() write_file(new, 'New file') exec_lua( @@ -2514,9 +2515,9 @@ describe('LSP', function() end ) it('Does override target if overwrite is true', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Old file') - local new = helpers.tmpname() + local new = tmpname() write_file(new, 'New file') exec_lua( [[ @@ -4043,7 +4044,7 @@ describe('LSP', function() if is_os('win') then tmpfile = '\\\\.\\\\pipe\\pipe.test' else - tmpfile = helpers.tmpname() + tmpfile = tmpname() os.remove(tmpfile) end local result = exec_lua( @@ -4150,7 +4151,7 @@ describe('LSP', function() describe('#dynamic vim.lsp._dynamic', function() it('supports dynamic registration', function() ---@type string - local root_dir = helpers.tmpname() + local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) local tmpfile = root_dir .. '/dynamic.foo' @@ -4261,7 +4262,7 @@ describe('LSP', function() describe('vim.lsp._watchfiles', function() it('sends notifications when files change', function() skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change') - local root_dir = helpers.tmpname() + local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index ed9f21edf3..532210582a 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -9,7 +9,7 @@ local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname local eq = helpers.eq -local pesc = helpers.pesc +local pesc = vim.pesc local skip = helpers.skip local is_ci = helpers.is_ci diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 01dd253384..985252fd75 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,10 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local meths = helpers.meths -local eq, nvim_eval, nvim_command, exc_exec = - helpers.eq, helpers.eval, helpers.command, helpers.exc_exec +local eq = helpers.eq +local nvim_eval = helpers.eval +local nvim_command = helpers.command +local exc_exec = helpers.exc_exec local ok = helpers.ok -local NIL = helpers.NIL +local NIL = vim.NIL describe('autoload/msgpack.vim', function() before_each(function() -- cgit From 284e0ad26dd9de90c3a813dd1b357a425eca6bad Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:03:25 +0000 Subject: test: use vim.mpack and vim.uv directly --- test/functional/plugin/shada_spec.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index ef3fef1897..59ddd8f3ce 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -14,8 +14,6 @@ local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curb local neq = helpers.neq local read_file = helpers.read_file -local mpack = require('mpack') - local shada_helpers = require('test.functional.shada.helpers') local get_shada_rw = shada_helpers.get_shada_rw @@ -26,7 +24,7 @@ end local mpack_eq = function(expected, mpack_result) local mpack_keys = { 'type', 'timestamp', 'length', 'value' } - local unpack = mpack.Unpacker() + local unpack = vim.mpack.Unpacker() local actual = {} local cur, val local i = 0 -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/plugin/editorconfig_spec.lua | 10 +++++----- test/functional/plugin/lsp/incremental_sync_spec.lua | 2 +- test/functional/plugin/lsp_spec.lua | 4 ++-- test/functional/plugin/matchparen_spec.lua | 2 +- test/functional/plugin/msgpack_spec.lua | 12 ++++++------ test/functional/plugin/shada_spec.lua | 3 ++- 6 files changed, 17 insertions(+), 16 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index 2c9ce7ae1a..0689cd09d3 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -13,7 +13,7 @@ local function test_case(name, expected) local filename = testdir .. pathsep .. name command('edit ' .. filename) for opt, val in pairs(expected) do - eq(val, meths.get_option_value(opt, { buf = 0 }), name) + eq(val, meths.nvim_get_option_value(opt, { buf = 0 }), name) end end @@ -195,15 +195,15 @@ But not this one end) it('can be disabled globally', function() - meths.set_var('editorconfig', false) - meths.set_option_value('shiftwidth', 42, {}) + meths.nvim_set_var('editorconfig', false) + meths.nvim_set_option_value('shiftwidth', 42, {}) test_case('3_space.txt', { shiftwidth = 42 }) end) it('can be disabled per-buffer', function() - meths.set_option_value('shiftwidth', 42, {}) + meths.nvim_set_option_value('shiftwidth', 42, {}) local bufnr = funcs.bufadd(testdir .. pathsep .. '3_space.txt') - meths.buf_set_var(bufnr, 'editorconfig', false) + meths.nvim_buf_set_var(bufnr, 'editorconfig', false) test_case('3_space.txt', { shiftwidth = 42 }) test_case('4_space.py', { shiftwidth = 4 }) end) diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index 9b33f4451e..ec918ed514 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -62,7 +62,7 @@ local function test_edit( offset_encoding = offset_encoding or 'utf-16' line_ending = line_ending or '\n' - meths.buf_set_lines(0, 0, -1, true, prev_buffer) + meths.nvim_buf_set_lines(0, 0, -1, true, prev_buffer) exec_lua('return test_register(...)', 0, 'test1', offset_encoding, line_ending) for _, edit in ipairs(edit_operations) do diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index d794a34463..43bfb89e81 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -363,9 +363,9 @@ describe('LSP', function() end, on_handler = function(_, _, ctx) if ctx.method == 'finish' then - eq('basic_init', meths.get_var('lsp_attached')) + eq('basic_init', meths.nvim_get_var('lsp_attached')) exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') - eq('basic_init', meths.get_var('lsp_detached')) + eq('basic_init', meths.nvim_get_var('lsp_detached')) client.stop() end end, diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 1c4e11d30b..2bda41359b 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -22,7 +22,7 @@ describe('matchparen', function() it('uses correct column after i_. Vim patch 7.4.1296', function() command('set noautoindent nosmartindent nocindent laststatus=0') - eq(1, meths.get_var('loaded_matchparen')) + eq(1, meths.nvim_get_var('loaded_matchparen')) feed('ivoid f_test()') feed('{') feed('}') diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 985252fd75..bc1182afd3 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -526,17 +526,17 @@ describe('autoload/msgpack.vim', function() end) it('works for special v: values like v:true', function() - meths.set_var('true', true) - meths.set_var('false', false) - meths.set_var('nil', NIL) + meths.nvim_set_var('true', true) + meths.nvim_set_var('false', false) + meths.nvim_set_var('nil', NIL) nvim_command('let true2 = msgpack#deepcopy(true)') nvim_command('let false2 = msgpack#deepcopy(false)') nvim_command('let nil2 = msgpack#deepcopy(nil)') - eq(true, meths.get_var('true')) - eq(false, meths.get_var('false')) - eq(NIL, meths.get_var('nil')) + eq(true, meths.nvim_get_var('true')) + eq(false, meths.nvim_get_var('false')) + eq(NIL, meths.nvim_get_var('nil')) end) end) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 59ddd8f3ce..628ff968d7 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -2644,7 +2644,8 @@ describe('plugin/shada.vim', function() wshada('\004\000\009\147\000\196\002ab\196\001a') wshada_tmp('\004\000\009\147\000\196\002ab\196\001b') - local bufread_commands = meths.get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) + local bufread_commands = + meths.nvim_get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) eq(2, #bufread_commands--[[, vim.inspect(bufread_commands) ]]) -- Need to set nohidden so that the buffer containing 'fname' is not unloaded -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/plugin/shada_spec.lua | 74 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 628ff968d7..c037636025 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,16 +1,14 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear -local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = +local eq, meths, nvim_eval, nvim_command, exc_exec, funcs, nvim_feed = helpers.eq, helpers.meths, helpers.eval, helpers.command, - helpers.nvim, helpers.exc_exec, helpers.funcs, - helpers.feed, - helpers.curbuf + helpers.feed local neq = helpers.neq local read_file = helpers.read_file @@ -1581,7 +1579,7 @@ describe('autoload/shada.vim', function() describe('function shada#strings_to_sd', function() local strings2sd_eq = function(expected, input) - nvim('set_var', '__input', input) + meths.nvim_set_var('__input', input) nvim_command( 'let g:__actual = map(shada#strings_to_sd(g:__input), ' .. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' @@ -1589,7 +1587,7 @@ describe('autoload/shada.vim', function() ) -- print() if type(expected) == 'table' then - nvim('set_var', '__expected', expected) + meths.nvim_set_var('__expected', expected) nvim_command('let g:__expected = ModifyVal(g:__expected)') expected = 'g:__expected' -- print(nvim_eval('msgpack#string(g:__expected)')) @@ -2534,7 +2532,7 @@ describe('autoload/shada.vim', function() end it('works', function() - local version = nvim('get_vvar', 'version') + local version = meths.nvim_get_vvar('version') getbstrings_eq({ { timestamp = 'current', @@ -2560,7 +2558,7 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#add_own_header', 1) + meths.nvim_set_var('shada#add_own_header', 1) getbstrings_eq({ { timestamp = 'current', @@ -2586,14 +2584,14 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#add_own_header', 0) + meths.nvim_set_var('shada#add_own_header', 0) getbstrings_eq({}, {}) getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#keep_old_header', 0) + meths.nvim_set_var('shada#keep_old_header', 0) getbstrings_eq({}, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', @@ -2661,8 +2659,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(false, nvim('get_option_value', 'modified', {})) - eq('shada', nvim('get_option_value', 'filetype', {})) + eq(false, meths.nvim_get_option_value('modified', {})) + eq('shada', meths.nvim_get_option_value('filetype', {})) nvim_command('edit ' .. fname_tmp) eq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2671,8 +2669,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(false, nvim('get_option_value', 'modified', {})) - eq('shada', nvim('get_option_value', 'filetype', {})) + eq(false, meths.nvim_get_option_value('modified', {})) + eq('shada', meths.nvim_get_option_value('filetype', {})) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) neq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2681,7 +2679,7 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - neq(true, nvim('get_option_value', 'modified', {})) + neq(true, meths.nvim_get_option_value('modified', {})) end) it('event FileReadCmd', function() @@ -2697,8 +2695,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(true, nvim('get_option_value', 'modified', {})) - neq('shada', nvim('get_option_value', 'filetype', {})) + eq(true, meths.nvim_get_option_value('modified', {})) + neq('shada', meths.nvim_get_option_value('filetype', {})) nvim_command('1,$read ' .. fname_tmp) eq({ '', @@ -2713,9 +2711,9 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(true, nvim('get_option_value', 'modified', {})) - neq('shada', nvim('get_option_value', 'filetype', {})) - nvim('set_option_value', 'modified', false, {}) + eq(true, meths.nvim_get_option_value('modified', {})) + neq('shada', meths.nvim_get_option_value('filetype', {})) + meths.nvim_set_option_value('modified', false, {}) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq({ '', @@ -2730,13 +2728,13 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - neq(true, nvim('get_option_value', 'modified', {})) + neq(true, meths.nvim_get_option_value('modified', {})) end) it('event BufWriteCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + meths.nvim_set_var('shada#add_own_header', 0) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2796,8 +2794,8 @@ describe('plugin/shada.vim', function() it('event FileWriteCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + meths.nvim_set_var('shada#add_own_header', 0) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2840,8 +2838,8 @@ describe('plugin/shada.vim', function() it('event FileAppendCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + meths.nvim_set_var('shada#add_own_header', 0) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -3017,10 +3015,10 @@ describe('ftplugin/shada.vim', function() it('sets options correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - eq(true, nvim('get_option_value', 'expandtab', {})) - eq(2, nvim('get_option_value', 'tabstop', {})) - eq(2, nvim('get_option_value', 'softtabstop', {})) - eq(2, nvim('get_option_value', 'shiftwidth', {})) + eq(true, meths.nvim_get_option_value('expandtab', {})) + eq(2, meths.nvim_get_option_value('tabstop', {})) + eq(2, meths.nvim_get_option_value('softtabstop', {})) + eq(2, meths.nvim_get_option_value('shiftwidth', {})) end) it('sets indentkeys correctly', function() @@ -3028,17 +3026,17 @@ describe('ftplugin/shada.vim', function() nvim_command('setlocal filetype=shada') funcs.setline(1, ' Replacement with timestamp ' .. epoch) nvim_feed('ggA:\027') - eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1]) + eq('Replacement with timestamp ' .. epoch .. ':', meths.nvim_buf_get_lines(0, 0, 1, true)[1]) nvim_feed('o-\027') - eq({ ' -' }, curbuf('get_lines', 1, 2, true)) + eq({ ' -' }, meths.nvim_buf_get_lines(0, 1, 2, true)) nvim_feed('ggO+\027') - eq({ '+' }, curbuf('get_lines', 0, 1, true)) + eq({ '+' }, meths.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('GO*\027') - eq({ ' *' }, curbuf('get_lines', 2, 3, true)) + eq({ ' *' }, meths.nvim_buf_get_lines(0, 2, 3, true)) nvim_feed('ggO /\027') - eq({ ' /' }, curbuf('get_lines', 0, 1, true)) + eq({ ' /' }, meths.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('ggOx\027') - eq({ 'x' }, curbuf('get_lines', 0, 1, true)) + eq({ 'x' }, meths.nvim_buf_get_lines(0, 0, 1, true)) end) end) @@ -3063,7 +3061,7 @@ describe('syntax/shada.vim', function() } screen:attach() - curbuf('set_lines', 0, 1, true, { + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', ' % Key Value', ' + t "test"', -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/plugin/cfilter_spec.lua | 18 ++-- test/functional/plugin/editorconfig_spec.lua | 16 +-- test/functional/plugin/health_spec.lua | 2 +- .../plugin/lsp/incremental_sync_spec.lua | 4 +- test/functional/plugin/lsp_spec.lua | 112 ++++++++++----------- test/functional/plugin/man_spec.lua | 8 +- test/functional/plugin/matchparen_spec.lua | 4 +- test/functional/plugin/msgpack_spec.lua | 14 +-- test/functional/plugin/shada_spec.lua | 102 +++++++++---------- 9 files changed, 137 insertions(+), 143 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua index 8b1e75b495..37261d59df 100644 --- a/test/functional/plugin/cfilter_spec.lua +++ b/test/functional/plugin/cfilter_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn describe('cfilter.lua', function() before_each(function() @@ -13,16 +13,16 @@ describe('cfilter.lua', function() for _, list in ipairs({ { name = 'Cfilter', - get = funcs.getqflist, - set = funcs.setqflist, + get = fn.getqflist, + set = fn.setqflist, }, { name = 'Lfilter', get = function() - return funcs.getloclist(0) + return fn.getloclist(0) end, set = function(items) - return funcs.setloclist(0, items) + return fn.setloclist(0, items) end, }, }) do @@ -39,7 +39,7 @@ describe('cfilter.lua', function() describe((':%s'):format(list.name), function() it('does not error on empty list', function() filter('nothing') - eq({}, funcs.getqflist()) + eq({}, fn.getqflist()) end) it('requires an argument', function() @@ -66,7 +66,7 @@ describe('cfilter.lua', function() end local toname = function(qflist) - return funcs.map(qflist, 'v:val.text') + return fn.map(qflist, 'v:val.text') end test('filters with no matches', 'does not match', {}) @@ -83,7 +83,7 @@ describe('cfilter.lua', function() { filename = 'foo', lnum = 3, text = 'zed' }, }) - funcs.setreg('/', 'ba') + fn.setreg('/', 'ba') filter('/') eq({ 'bar', 'baz' }, toname(list.get())) @@ -96,7 +96,7 @@ describe('cfilter.lua', function() { filename = 'foo', lnum = 3, text = 'zed' }, }) - funcs.setreg('/', 'ba') + fn.setreg('/', 'ba') filter('/', true) eq({ 'zed' }, toname(list.get())) diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index 0689cd09d3..115c28fbf6 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -3,8 +3,8 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local pathsep = helpers.get_pathsep() -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exec_lua = helpers.exec_lua local testdir = 'Xtest-editorconfig' @@ -13,7 +13,7 @@ local function test_case(name, expected) local filename = testdir .. pathsep .. name command('edit ' .. filename) for opt, val in pairs(expected) do - eq(val, meths.nvim_get_option_value(opt, { buf = 0 }), name) + eq(val, api.nvim_get_option_value(opt, { buf = 0 }), name) end end @@ -195,15 +195,15 @@ But not this one end) it('can be disabled globally', function() - meths.nvim_set_var('editorconfig', false) - meths.nvim_set_option_value('shiftwidth', 42, {}) + api.nvim_set_var('editorconfig', false) + api.nvim_set_option_value('shiftwidth', 42, {}) test_case('3_space.txt', { shiftwidth = 42 }) end) it('can be disabled per-buffer', function() - meths.nvim_set_option_value('shiftwidth', 42, {}) - local bufnr = funcs.bufadd(testdir .. pathsep .. '3_space.txt') - meths.nvim_buf_set_var(bufnr, 'editorconfig', false) + api.nvim_set_option_value('shiftwidth', 42, {}) + local bufnr = fn.bufadd(testdir .. pathsep .. '3_space.txt') + api.nvim_buf_set_var(bufnr, 'editorconfig', false) test_case('3_space.txt', { shiftwidth = 42 }) test_case('4_space.py', { shiftwidth = 4 }) end) diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index f08f207d39..8564ec7c9b 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local curbuf_contents = helpers.curbuf_contents local command = helpers.command local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches -local getcompletion = helpers.funcs.getcompletion +local getcompletion = helpers.fn.getcompletion local insert = helpers.insert local source = helpers.source local exec_lua = helpers.exec_lua diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index ec918ed514..bd1842ceb5 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -1,7 +1,7 @@ -- Test suite for testing interactions with the incremental sync algorithms powering the LSP client local helpers = require('test.functional.helpers')(after_each) -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local eq = helpers.eq local exec_lua = helpers.exec_lua @@ -62,7 +62,7 @@ local function test_edit( offset_encoding = offset_encoding or 'utf-16' line_ending = line_ending or '\n' - meths.nvim_buf_set_lines(0, 0, -1, true, prev_buffer) + api.nvim_buf_set_lines(0, 0, -1, true, prev_buffer) exec_lua('return test_register(...)', 0, 'test1', offset_encoding, line_ending) for _, edit in ipairs(edit_operations) do diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 43bfb89e81..252931eccb 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -13,14 +13,14 @@ local matches = helpers.matches local pcall_err = helpers.pcall_err local pesc = vim.pesc local insert = helpers.insert -local funcs = helpers.funcs +local fn = helpers.fn local retry = helpers.retry local stop = helpers.stop local NIL = vim.NIL local read_file = require('test.helpers').read_file local write_file = require('test.helpers').write_file local is_ci = helpers.is_ci -local meths = helpers.meths +local api = helpers.api local is_os = helpers.is_os local skip = helpers.skip local mkdir = helpers.mkdir @@ -363,9 +363,9 @@ describe('LSP', function() end, on_handler = function(_, _, ctx) if ctx.method == 'finish' then - eq('basic_init', meths.nvim_get_var('lsp_attached')) + eq('basic_init', api.nvim_get_var('lsp_attached')) exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') - eq('basic_init', meths.nvim_get_var('lsp_detached')) + eq('basic_init', api.nvim_get_var('lsp_detached')) client.stop() end end, @@ -1877,7 +1877,7 @@ describe('LSP', function() describe('cursor position', function() it("don't fix the cursor if the range contains the cursor", function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 19, 'Second line of text'), } @@ -1889,11 +1889,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 6 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 6 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid col if the content was removed', function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(1, 6, 1, 19, ''), @@ -1906,11 +1906,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid row if the content was removed', function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(0, 18, 5, 0, ''), @@ -1919,11 +1919,11 @@ describe('LSP', function() eq({ 'First line of text', }, buf_lines(1)) - eq({ 1, 17 }, funcs.nvim_win_get_cursor(0)) + eq({ 1, 17 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor row', function() - funcs.nvim_win_set_cursor(0, { 3, 0 }) + fn.nvim_win_set_cursor(0, { 3, 0 }) local edits = { make_edit(1, 0, 2, 0, ''), } @@ -1934,14 +1934,14 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor col', function() -- append empty last line. See #22636 exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, { '' }) - funcs.nvim_win_set_cursor(0, { 2, 11 }) + fn.nvim_win_set_cursor(0, { 2, 11 }) local edits = { make_edit(1, 7, 1, 11, ''), } @@ -1954,11 +1954,11 @@ describe('LSP', function() 'å å ɧ 汉语 ↥ 🤦 🦄', '', }, buf_lines(1)) - eq({ 2, 7 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 7 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor row and col', function() - funcs.nvim_win_set_cursor(0, { 2, 12 }) + fn.nvim_win_set_cursor(0, { 2, 12 }) local edits = { make_edit(0, 11, 1, 12, ''), } @@ -1969,7 +1969,7 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 1, 11 }, funcs.nvim_win_get_cursor(0)) + eq({ 1, 11 }, fn.nvim_win_get_cursor(0)) end) end) @@ -2946,14 +2946,14 @@ describe('LSP', function() end) it('adds current position to jumplist before jumping', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + fn.nvim_win_set_buf(0, target_bufnr) + local mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_cursor(0, { 2, 3 }) jump(location(0, 9, 0, 9)) - mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 2, 3 }, mark) end) end) @@ -3047,101 +3047,101 @@ describe('LSP', function() end) it('does not add current position to jumplist if not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + fn.nvim_win_set_buf(0, target_bufnr) + local mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_cursor(0, { 2, 3 }) show_document(location(0, 9, 0, 9), false, true) show_document(location(0, 9, 0, 9, true), false, true) - mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) end) it('does not change cursor position if not focus and not reuse_win', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local cursor = funcs.nvim_win_get_cursor(0) + fn.nvim_win_set_buf(0, target_bufnr) + local cursor = fn.nvim_win_get_cursor(0) show_document(location(0, 9, 0, 9), false, false) - eq(cursor, funcs.nvim_win_get_cursor(0)) + eq(cursor, fn.nvim_win_get_cursor(0)) end) it('does not change window if not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local win = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr) + local win = fn.nvim_get_current_win() -- same document/bufnr show_document(location(0, 9, 0, 9), false, true) - eq(win, funcs.nvim_get_current_win()) + eq(win, fn.nvim_get_current_win()) -- different document/bufnr, new window/split show_document(location(0, 9, 0, 9, true), false, true) - eq(2, #funcs.nvim_list_wins()) - eq(win, funcs.nvim_get_current_win()) + eq(2, #fn.nvim_list_wins()) + eq(win, fn.nvim_get_current_win()) end) it("respects 'reuse_win' parameter", function() - funcs.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_buf(0, target_bufnr) -- does not create a new window if the buffer is already open show_document(location(0, 9, 0, 9), false, true) - eq(1, #funcs.nvim_list_wins()) + eq(1, #fn.nvim_list_wins()) -- creates a new window even if the buffer is already open show_document(location(0, 9, 0, 9), false, false) - eq(2, #funcs.nvim_list_wins()) + eq(2, #fn.nvim_list_wins()) end) it('correctly sets the cursor of the split if range is given without focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_buf(0, target_bufnr) show_document(location(0, 9, 0, 9, true), false, true) - local wins = funcs.nvim_list_wins() + local wins = fn.nvim_list_wins() eq(2, #wins) table.sort(wins) - eq({ 1, 0 }, funcs.nvim_win_get_cursor(wins[1])) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(wins[2])) + eq({ 1, 0 }, fn.nvim_win_get_cursor(wins[1])) + eq({ 1, 9 }, fn.nvim_win_get_cursor(wins[2])) end) it('does not change cursor of the split if not range and not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_cursor(0, { 2, 3 }) exec_lua([[vim.cmd.new()]]) - funcs.nvim_win_set_buf(0, target_bufnr2) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_buf(0, target_bufnr2) + fn.nvim_win_set_cursor(0, { 2, 3 }) show_document({ uri = 'file:///fake/uri2' }, false, true) - local wins = funcs.nvim_list_wins() + local wins = fn.nvim_list_wins() eq(2, #wins) - eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[1])) - eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[2])) + eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[1])) + eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[2])) end) it('respects existing buffers', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local win = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr) + local win = fn.nvim_get_current_win() exec_lua([[vim.cmd.new()]]) - funcs.nvim_win_set_buf(0, target_bufnr2) - funcs.nvim_win_set_cursor(0, { 2, 3 }) - local split = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr2) + fn.nvim_win_set_cursor(0, { 2, 3 }) + local split = fn.nvim_get_current_win() -- reuse win for open document/bufnr if called from split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) - eq(2, #funcs.nvim_list_wins()) + eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) + eq(2, #fn.nvim_list_wins()) - funcs.nvim_set_current_win(win) + fn.nvim_set_current_win(win) -- reuse win for open document/bufnr if called outside the split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) - eq(2, #funcs.nvim_list_wins()) + eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) + eq(2, #fn.nvim_list_wins()) end) end) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 532210582a..5bfa566729 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local command, rawfeed = helpers.command, helpers.rawfeed local clear = helpers.clear local exec_lua = helpers.exec_lua -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local matches = helpers.matches local write_file = helpers.write_file @@ -33,7 +33,7 @@ local function get_search_history(name) end clear() -if funcs.executable('man') == 0 then +if fn.executable('man') == 0 then pending('missing "man" command', function() end) return end @@ -192,7 +192,7 @@ describe(':Man', function() '+Man!', '+call nvim_input("q")', } - matches('quit works!!', funcs.system(args, { 'manpage contents' })) + matches('quit works!!', fn.system(args, { 'manpage contents' })) end) it('reports non-existent man pages for absolute paths', function() @@ -206,7 +206,7 @@ describe(':Man', function() ('Error detected while processing command line:\r\n' .. 'man.lua: "no manual entry for %s"'):format( pesc(actual_file) ), - funcs.system(args, { '' }) + fn.system(args, { '' }) ) os.remove(actual_file) end) diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 2bda41359b..530afd16e4 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command -local meths = helpers.meths +local api = helpers.api local feed = helpers.feed local eq = helpers.eq @@ -22,7 +22,7 @@ describe('matchparen', function() it('uses correct column after i_. Vim patch 7.4.1296', function() command('set noautoindent nosmartindent nocindent laststatus=0') - eq(1, meths.nvim_get_var('loaded_matchparen')) + eq(1, api.nvim_get_var('loaded_matchparen')) feed('ivoid f_test()') feed('{') feed('}') diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index bc1182afd3..8511e6c703 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear -local meths = helpers.meths +local api = helpers.api local eq = helpers.eq local nvim_eval = helpers.eval local nvim_command = helpers.command @@ -526,17 +526,17 @@ describe('autoload/msgpack.vim', function() end) it('works for special v: values like v:true', function() - meths.nvim_set_var('true', true) - meths.nvim_set_var('false', false) - meths.nvim_set_var('nil', NIL) + api.nvim_set_var('true', true) + api.nvim_set_var('false', false) + api.nvim_set_var('nil', NIL) nvim_command('let true2 = msgpack#deepcopy(true)') nvim_command('let false2 = msgpack#deepcopy(false)') nvim_command('let nil2 = msgpack#deepcopy(nil)') - eq(true, meths.nvim_get_var('true')) - eq(false, meths.nvim_get_var('false')) - eq(NIL, meths.nvim_get_var('nil')) + eq(true, api.nvim_get_var('true')) + eq(false, api.nvim_get_var('false')) + eq(NIL, api.nvim_get_var('nil')) end) end) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index c037636025..1c20548321 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,14 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear -local eq, meths, nvim_eval, nvim_command, exc_exec, funcs, nvim_feed = - helpers.eq, - helpers.meths, - helpers.eval, - helpers.command, - helpers.exc_exec, - helpers.funcs, - helpers.feed +local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed = + helpers.eq, helpers.api, helpers.eval, helpers.command, helpers.exc_exec, helpers.fn, helpers.feed local neq = helpers.neq local read_file = helpers.read_file @@ -122,7 +116,7 @@ describe('autoload/shada.vim', function() describe('function shada#sd_to_strings', function() local sd2strings_eq = function(expected, arg) if type(arg) == 'table' then - eq(expected, funcs['shada#sd_to_strings'](arg)) + eq(expected, fn['shada#sd_to_strings'](arg)) else eq(expected, nvim_eval(('shada#sd_to_strings(%s)'):format(arg))) end @@ -1579,7 +1573,7 @@ describe('autoload/shada.vim', function() describe('function shada#strings_to_sd', function() local strings2sd_eq = function(expected, input) - meths.nvim_set_var('__input', input) + api.nvim_set_var('__input', input) nvim_command( 'let g:__actual = map(shada#strings_to_sd(g:__input), ' .. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' @@ -1587,7 +1581,7 @@ describe('autoload/shada.vim', function() ) -- print() if type(expected) == 'table' then - meths.nvim_set_var('__expected', expected) + api.nvim_set_var('__expected', expected) nvim_command('let g:__expected = ModifyVal(g:__expected)') expected = 'g:__expected' -- print(nvim_eval('msgpack#string(g:__expected)')) @@ -2523,7 +2517,7 @@ describe('autoload/shada.vim', function() describe('function shada#get_binstrings', function() local getbstrings_eq = function(expected, input) - local result = funcs['shada#get_binstrings'](input) + local result = fn['shada#get_binstrings'](input) for i, s in ipairs(result) do result[i] = s:gsub('\n', '\0') end @@ -2532,7 +2526,7 @@ describe('autoload/shada.vim', function() end it('works', function() - local version = meths.nvim_get_vvar('version') + local version = api.nvim_get_vvar('version') getbstrings_eq({ { timestamp = 'current', @@ -2558,7 +2552,7 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - meths.nvim_set_var('shada#add_own_header', 1) + api.nvim_set_var('shada#add_own_header', 1) getbstrings_eq({ { timestamp = 'current', @@ -2584,14 +2578,14 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - meths.nvim_set_var('shada#add_own_header', 0) + api.nvim_set_var('shada#add_own_header', 0) getbstrings_eq({}, {}) getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', }) - meths.nvim_set_var('shada#keep_old_header', 0) + api.nvim_set_var('shada#keep_old_header', 0) getbstrings_eq({}, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', @@ -2643,7 +2637,7 @@ describe('plugin/shada.vim', function() wshada_tmp('\004\000\009\147\000\196\002ab\196\001b') local bufread_commands = - meths.nvim_get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) + api.nvim_get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) eq(2, #bufread_commands--[[, vim.inspect(bufread_commands) ]]) -- Need to set nohidden so that the buffer containing 'fname' is not unloaded @@ -2659,8 +2653,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(false, meths.nvim_get_option_value('modified', {})) - eq('shada', meths.nvim_get_option_value('filetype', {})) + eq(false, api.nvim_get_option_value('modified', {})) + eq('shada', api.nvim_get_option_value('filetype', {})) nvim_command('edit ' .. fname_tmp) eq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2669,8 +2663,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(false, meths.nvim_get_option_value('modified', {})) - eq('shada', meths.nvim_get_option_value('filetype', {})) + eq(false, api.nvim_get_option_value('modified', {})) + eq('shada', api.nvim_get_option_value('filetype', {})) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) neq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2679,7 +2673,7 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - neq(true, meths.nvim_get_option_value('modified', {})) + neq(true, api.nvim_get_option_value('modified', {})) end) it('event FileReadCmd', function() @@ -2695,8 +2689,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(true, meths.nvim_get_option_value('modified', {})) - neq('shada', meths.nvim_get_option_value('filetype', {})) + eq(true, api.nvim_get_option_value('modified', {})) + neq('shada', api.nvim_get_option_value('filetype', {})) nvim_command('1,$read ' .. fname_tmp) eq({ '', @@ -2711,9 +2705,9 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(true, meths.nvim_get_option_value('modified', {})) - neq('shada', meths.nvim_get_option_value('filetype', {})) - meths.nvim_set_option_value('modified', false, {}) + eq(true, api.nvim_get_option_value('modified', {})) + neq('shada', api.nvim_get_option_value('filetype', {})) + api.nvim_set_option_value('modified', false, {}) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq({ '', @@ -2728,13 +2722,13 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - neq(true, meths.nvim_get_option_value('modified', {})) + neq(true, api.nvim_get_option_value('modified', {})) end) it('event BufWriteCmd', function() reset() - meths.nvim_set_var('shada#add_own_header', 0) - meths.nvim_buf_set_lines(0, 0, 1, true, { + api.nvim_set_var('shada#add_own_header', 0) + api.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2794,8 +2788,8 @@ describe('plugin/shada.vim', function() it('event FileWriteCmd', function() reset() - meths.nvim_set_var('shada#add_own_header', 0) - meths.nvim_buf_set_lines(0, 0, 1, true, { + api.nvim_set_var('shada#add_own_header', 0) + api.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2838,8 +2832,8 @@ describe('plugin/shada.vim', function() it('event FileAppendCmd', function() reset() - meths.nvim_set_var('shada#add_own_header', 0) - meths.nvim_buf_set_lines(0, 0, 1, true, { + api.nvim_set_var('shada#add_own_header', 0) + api.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2853,9 +2847,9 @@ describe('plugin/shada.vim', function() ' + l line number 2', ' + c column -200', }) - funcs.writefile({ '' }, fname .. '.tst', 'b') - funcs.writefile({ '' }, fname, 'b') - funcs.writefile({ '' }, fname_tmp, 'b') + fn.writefile({ '' }, fname .. '.tst', 'b') + fn.writefile({ '' }, fname, 'b') + fn.writefile({ '' }, fname_tmp, 'b') nvim_command('1,3w >> ' .. fname .. '.tst') nvim_command('1,3w >> ' .. fname) nvim_command('1,3w >> ' .. fname_tmp) @@ -2925,8 +2919,8 @@ describe('plugin/shada.vim', function() wshada_tmp('\004\001\006\146\000\196\002bc') eq(0, exc_exec('source ' .. fname)) eq(0, exc_exec('source ' .. fname_tmp)) - eq('bc', funcs.histget(':', -1)) - eq('ab', funcs.histget(':', -2)) + eq('bc', fn.histget(':', -1)) + eq('ab', fn.histget(':', -2)) end) end) @@ -2937,7 +2931,7 @@ describe('ftplugin/shada.vim', function() it('sets indentexpr correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - funcs.setline(1, { + fn.setline(1, { 'Jump with timestamp ' .. epoch .. ':', '% Key________ Description Value', "+ n name 'A'", @@ -3009,34 +3003,34 @@ describe('ftplugin/shada.vim', function() ' + f file name 20', ' + l line number 1', ' + c column 0', - }, funcs.getline(1, funcs.line('$'))) + }, fn.getline(1, fn.line('$'))) end) it('sets options correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - eq(true, meths.nvim_get_option_value('expandtab', {})) - eq(2, meths.nvim_get_option_value('tabstop', {})) - eq(2, meths.nvim_get_option_value('softtabstop', {})) - eq(2, meths.nvim_get_option_value('shiftwidth', {})) + eq(true, api.nvim_get_option_value('expandtab', {})) + eq(2, api.nvim_get_option_value('tabstop', {})) + eq(2, api.nvim_get_option_value('softtabstop', {})) + eq(2, api.nvim_get_option_value('shiftwidth', {})) end) it('sets indentkeys correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - funcs.setline(1, ' Replacement with timestamp ' .. epoch) + fn.setline(1, ' Replacement with timestamp ' .. epoch) nvim_feed('ggA:\027') - eq('Replacement with timestamp ' .. epoch .. ':', meths.nvim_buf_get_lines(0, 0, 1, true)[1]) + eq('Replacement with timestamp ' .. epoch .. ':', api.nvim_buf_get_lines(0, 0, 1, true)[1]) nvim_feed('o-\027') - eq({ ' -' }, meths.nvim_buf_get_lines(0, 1, 2, true)) + eq({ ' -' }, api.nvim_buf_get_lines(0, 1, 2, true)) nvim_feed('ggO+\027') - eq({ '+' }, meths.nvim_buf_get_lines(0, 0, 1, true)) + eq({ '+' }, api.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('GO*\027') - eq({ ' *' }, meths.nvim_buf_get_lines(0, 2, 3, true)) + eq({ ' *' }, api.nvim_buf_get_lines(0, 2, 3, true)) nvim_feed('ggO /\027') - eq({ ' /' }, meths.nvim_buf_get_lines(0, 0, 1, true)) + eq({ ' /' }, api.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('ggOx\027') - eq({ 'x' }, meths.nvim_buf_get_lines(0, 0, 1, true)) + eq({ 'x' }, api.nvim_buf_get_lines(0, 0, 1, true)) end) end) @@ -3061,7 +3055,7 @@ describe('syntax/shada.vim', function() } screen:attach() - meths.nvim_buf_set_lines(0, 0, 1, true, { + api.nvim_buf_set_lines(0, 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', ' % Key Value', ' + t "test"', @@ -3208,7 +3202,7 @@ describe('syntax/shada.vim', function() s, } end - local act = funcs.GetSyntax() + local act = fn.GetSyntax() local ms = function(syn) return { { 'ShaDaEntryMap' .. syn, 'ShaDaEntryMap' .. syn .. 'EntryStart' }, -- cgit From 95cbedaa1798a7c1489b68dd60380a41443ed34b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 18 Jan 2024 00:14:48 -0800 Subject: docs: various #25289 Co-authored-by: Jongwook Choi Co-authored-by: Oliver Marriott Co-authored-by: Benoit de Chezelles Co-authored-by: Jongwook Choi --- test/functional/plugin/lsp_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 252931eccb..b602143443 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -4261,7 +4261,10 @@ describe('LSP', function() describe('vim.lsp._watchfiles', function() it('sends notifications when files change', function() - skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change') + skip( + is_os('bsd'), + 'kqueue only reports events on watched folder itself, not contained files #26110' + ) local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) -- cgit From b92b9be85d0a2e2e237e065b497b0ece95f7e6b4 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 3 Feb 2024 17:49:28 -0500 Subject: test(lsp): add test cases for vim.lsp.tagfunc Problem: There is no test case for vim.lsp.tagfunc; so CI was unable to catch the infinite loop bug (#27325). Solution: Add test cases for vim.lsp.tagfunc(). --- test/functional/plugin/lsp_spec.lua | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index b602143443..ce76861b9a 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -4013,6 +4013,105 @@ describe('LSP', function() check_notify('both', true, true) end) end) + + describe('vim.lsp.tagfunc', function() + before_each(function() + clear() + ---@type lsp.Location[] + local mock_locations = { + { + range = { + ['start'] = { line = 5, character = 23 }, + ['end'] = { line = 10, character = 0 }, + }, + uri = 'test://buf', + }, + { + range = { + ['start'] = { line = 42, character = 10 }, + ['end'] = { line = 44, character = 0 }, + }, + uri = 'test://another-file', + }, + } + exec_lua(create_server_definition) + exec_lua( + [[ + _G.mock_locations = ... + _G.server = _create_server({ + ---@type lsp.ServerCapabilities + capabilities = { + definitionProvider = true, + workspaceSymbolProvider = true, + }, + handlers = { + ---@return lsp.Location[] + ['textDocument/definition'] = function() + return { _G.mock_locations[1] } + end, + ---@return lsp.WorkspaceSymbol[] + ['workspace/symbol'] = function(_, request) + assert(request.query == 'foobar') + return { + { + name = 'foobar', + kind = 13, ---@type lsp.SymbolKind + location = _G.mock_locations[1], + }, + { + name = 'vim.foobar', + kind = 12, ---@type lsp.SymbolKind + location = _G.mock_locations[2], + } + } + end, + }, + }) + _G.client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]], + mock_locations + ) + end) + after_each(function() + exec_lua [[ + vim.lsp.stop_client(_G.client_id) + ]] + end) + + it('with flags=c, returns matching tags using textDocument/definition', function() + local result = exec_lua [[ + return vim.lsp.tagfunc('foobar', 'c') + ]] + eq({ + { + cmd = '/\\%6l\\%1c/', -- for location (5, 23) + filename = 'test://buf', + name = 'foobar', + }, + }, result) + end) + + it('without flags=c, returns all matching tags using workspace/symbol', function() + local result = exec_lua [[ + return vim.lsp.tagfunc('foobar', '') + ]] + eq({ + { + cmd = '/\\%6l\\%1c/', -- for location (5, 23) + filename = 'test://buf', + kind = 'Variable', + name = 'foobar', + }, + { + cmd = '/\\%43l\\%1c/', -- for location (42, 10) + filename = 'test://another-file', + kind = 'Function', + name = 'vim.foobar', + }, + }, result) + end) + end) + describe('cmd', function() it('can connect to lsp server via rpc.connect', function() local result = exec_lua [[ -- cgit From 451bc50d40ee43a40285d16039deb83c9bf05ff6 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 8 Feb 2024 12:11:47 +0000 Subject: feat(lsp): deprecate severity_limit Problem: `vim.lsp.diagnostic.on_diagnostic` accepts an undocumented severity_limit option which is widely used. Solution: Deprecate it in favour of `{min = severity}` used in `vim.diagnostic`. Since this is undocumented, the schedule for removal is accelerated to 0.11. --- test/functional/plugin/lsp/diagnostic_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index ee8dfc7a60..705c182df7 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -193,7 +193,7 @@ describe('vim.lsp.diagnostic', function() PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { underline = false, virtual_text = { - severity_limit = ... + severity = { min = ... } }, }) @@ -212,11 +212,11 @@ describe('vim.lsp.diagnostic', function() end -- No messages with Error or higher - eq(0, get_extmark_count_with_severity('Error')) + eq(0, get_extmark_count_with_severity('ERROR')) -- But now we don't filter it - eq(1, get_extmark_count_with_severity('Warning')) - eq(1, get_extmark_count_with_severity('Hint')) + eq(1, get_extmark_count_with_severity('WARN')) + eq(1, get_extmark_count_with_severity('HINT')) end) it('correctly handles UTF-16 offsets', function() -- cgit From ed1b66bd998b98ee8cf76b5a23c323352588dd56 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sun, 11 Feb 2024 12:37:20 +0000 Subject: refactor(lsp): move more code to client.lua The dispatchers used by the RPC client should be defined in the client, so they have been moved there. Due to this, it also made sense to move all code related to client configuration and the creation of the RPC client there too. Now vim.lsp.start_client is significantly simplified and now mostly contains logic for tracking open clients. - Renamed client.new -> client.start --- test/functional/plugin/lsp_spec.lua | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index ce76861b9a..fb153b83ca 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -139,30 +139,6 @@ describe('LSP', function() end) end) end) - - describe('lsp._cmd_parts test', function() - local function _cmd_parts(input) - return exec_lua( - [[ - lsp = require('vim.lsp') - return lsp._cmd_parts(...) - ]], - input - ) - end - it('should valid cmd argument', function() - eq(true, pcall(_cmd_parts, { 'nvim' })) - eq(true, pcall(_cmd_parts, { 'nvim', '--head' })) - end) - - it('should invalid cmd argument', function() - eq('.../lsp.lua:0: cmd: expected list, got nvim', pcall_err(_cmd_parts, 'nvim')) - eq( - '.../lsp.lua:0: cmd argument: expected string, got number', - pcall_err(_cmd_parts, { 'nvim', 1 }) - ) - end) - end) end) describe('LSP', function() -- cgit From 9f8c96240dc0318bd92a646966917e8fe0641144 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 12 Feb 2024 13:46:32 +0000 Subject: refactor(lsp): resolve the config-client entanglement Previously the LSP-Client object contained some fields that are also in the client config, but for a lot of other fields, the config was used directly making the two objects vaguely entangled with either not having a clear role. Now the config object is treated purely as config (read-only) from the client, and any fields the client needs from the config are now copied in as additional fields. This means: - the config object is no longet normalised and is left as the user provided it. - the client only reads the config on creation of the client and all other implementations now read the clients version of the fields. In addition, internal support for multiple callbacks has been added to the client so the client tracking logic (done in lua.lsp) can be done more robustly instead of wrapping the user callbacks which may error. --- test/functional/plugin/lsp_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index fb153b83ca..341ad014a6 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -523,7 +523,7 @@ describe('LSP', function() if ctx.method == 'start' then exec_lua([=[ local client = vim.lsp.get_client_by_id(TEST_RPC_CLIENT_ID) - client.config.settings = { + client.settings = { testSetting1 = true; testSetting2 = false; test = {Setting3 = 'nested' }; -- cgit From d09957e0a06f350443c750d9838b5f1016c0cccc Mon Sep 17 00:00:00 2001 From: Tomasz N Date: Wed, 14 Feb 2024 21:11:29 +0100 Subject: fix(lsp): rename: load and list new buffer if attached to window (#27408) --- test/functional/plugin/lsp_spec.lua | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 341ad014a6..be9a8342ff 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2419,6 +2419,68 @@ describe('LSP', function() eq(0, lines) os.remove(new) end) + it('new buffer remains unlisted and unloaded if the old was not in window before', function() + local old = tmpname() + write_file(old, 'Test content') + local new = tmpname() + os.remove(new) -- only reserve the name, file must not exist for the test scenario + local actual = exec_lua( + [[ + local old = select(1, ...) + local oldbufnr = vim.fn.bufadd(old) + local new = select(2, ...) + local newbufnr = vim.fn.bufadd(new) + vim.lsp.util.rename(old, new) + return { + buflisted = vim.bo[newbufnr].buflisted, + bufloaded = vim.api.nvim_buf_is_loaded(newbufnr) + } + ]], + old, + new + ) + + local expected = { + buflisted = false, + bufloaded = false, + } + + eq(expected, actual) + + os.remove(new) + end) + it('new buffer is listed and loaded if the old was in window before', function() + local old = tmpname() + write_file(old, 'Test content') + local new = tmpname() + os.remove(new) -- only reserve the name, file must not exist for the test scenario + local actual = exec_lua( + [[ + local win = vim.api.nvim_get_current_win() + local old = select(1, ...) + local oldbufnr = vim.fn.bufadd(old) + vim.api.nvim_win_set_buf(win, oldbufnr) + local new = select(2, ...) + vim.lsp.util.rename(old, new) + local newbufnr = vim.fn.bufadd(new) + return { + buflisted = vim.bo[newbufnr].buflisted, + bufloaded = vim.api.nvim_buf_is_loaded(newbufnr) + } + ]], + old, + new + ) + + local expected = { + buflisted = true, + bufloaded = true, + } + + eq(expected, actual) + + os.remove(new) + end) it('Can rename a directory', function() -- only reserve the name, file must not exist for the test scenario local old_dir = tmpname() -- cgit From 51ea753747c7df12a2d06ad45100db7797c11e1b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Feb 2024 13:27:42 +0800 Subject: fix(genvimvim): generate prefixed boolean options properly (#27487) --- test/functional/plugin/vim_syntax_spec.lua | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/functional/plugin/vim_syntax_spec.lua (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua new file mode 100644 index 0000000000..9396bbce5c --- /dev/null +++ b/test/functional/plugin/vim_syntax_spec.lua @@ -0,0 +1,40 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local exec = helpers.exec +local api = helpers.api + +describe('Vimscript syntax highlighting', function() + local screen + + before_each(function() + clear() + helpers.add_builddir_to_rtp() + exec([[ + setfiletype vim + syntax on + ]]) + screen = Screen.new() + screen:set_default_attr_ids({ + [0] = { foreground = Screen.colors.Blue, bold = true }, + [1] = { foreground = Screen.colors.Brown, bold = true }, + [2] = { foreground = tonumber('0x6a0dad') }, + }) + screen:attach() + end) + + it('prefixed boolean options are highlighted properly', function() + api.nvim_buf_set_lines(0, 0, -1, true, { + 'set number incsearch hlsearch', + 'set nonumber noincsearch nohlsearch', + 'set invnumber invincsearch invhlsearch', + }) + screen:expect([[ + {1:^set} {2:number} {2:incsearch} {2:hlsearch} | + {1:set} {2:nonumber} {2:noincsearch} {2:nohlsearch} | + {1:set} {2:invnumber} {2:invincsearch} {2:invhlsearch} | + {0:~ }|*10 + | + ]]) + end) +end) -- cgit From 8addd27504e698da62176824209ae2d3d24247c0 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sun, 25 Feb 2024 00:47:34 +0900 Subject: fix(lsp): when renaming directory, check path prefix of buffer names (#27603) For example, when renaming /path/to/dir, buffers like fern://drawer/file:///path/to/dir, /path/to/dir123 should not be matched. --- test/functional/plugin/lsp_spec.lua | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index be9a8342ff..b57fb268e1 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2515,6 +2515,47 @@ describe('LSP', function() os.remove(new_dir) end) + it('Does not touch buffers that do not match path prefix', function() + local old = tmpname() + local new = tmpname() + os.remove(old) + os.remove(new) + helpers.mkdir_p(old) + + local result = exec_lua( + [[ + local old = select(1, ...) + local new = select(2, ...) + + local old_prefixed = 'explorer://' .. old + local old_suffixed = old .. '.bak' + local new_prefixed = 'explorer://' .. new + local new_suffixed = new .. '.bak' + + local old_prefixed_buf = vim.fn.bufadd(old_prefixed) + local old_suffixed_buf = vim.fn.bufadd(old_suffixed) + local new_prefixed_buf = vim.fn.bufadd(new_prefixed) + local new_suffixed_buf = vim.fn.bufadd(new_suffixed) + + vim.lsp.util.rename(old, new) + + return + vim.api.nvim_buf_is_valid(old_prefixed_buf) and + vim.api.nvim_buf_is_valid(old_suffixed_buf) and + vim.api.nvim_buf_is_valid(new_prefixed_buf) and + vim.api.nvim_buf_is_valid(new_suffixed_buf) and + vim.api.nvim_buf_get_name(old_prefixed_buf) == old_prefixed and + vim.api.nvim_buf_get_name(old_suffixed_buf) == old_suffixed and + vim.api.nvim_buf_get_name(new_prefixed_buf) == new_prefixed and + vim.api.nvim_buf_get_name(new_suffixed_buf) == new_suffixed + ]], + old, + new + ) + eq(true, result) + + os.remove(new) + end) it( 'Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() -- cgit From 63f9c2da9aab52fa698fcbfdbc58ffd41794d28a Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Mon, 26 Feb 2024 11:42:51 -0800 Subject: feat(lsp): support completion itemDefaults --- test/functional/plugin/lsp/completion_spec.lua | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index b49f970385..655eb76be6 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -248,4 +248,32 @@ describe('vim.lsp._completion', function() item.user_data = nil eq(expected, item) end) + + it('uses defaults from itemDefaults', function() + --- @type lsp.CompletionList + local completion_list = { + isIncomplete = false, + itemDefaults = { + editRange = { + start = { line = 1, character = 1 }, + ['end'] = { line = 1, character = 4 }, + }, + insertTextFormat = 2, + data = 'foobar', + }, + items = { + { + label = 'hello', + data = 'item-property-has-priority', + textEditText = 'hello', + }, + }, + } + local result = complete('|', completion_list) + eq(1, #result.items) + local item = result.items[1].user_data.nvim.lsp.completion_item --- @type lsp.CompletionItem + eq(2, item.insertTextFormat) + eq('item-property-has-priority', item.data) + eq({ line = 1, character = 1 }, item.textEdit.range.start) + end) end) -- cgit From 2f85bbe61513d12c746641fed6ad07559bd95719 Mon Sep 17 00:00:00 2001 From: altermo <107814000+altermo@users.noreply.github.com> Date: Mon, 26 Feb 2024 11:42:51 -0800 Subject: feat!: rewrite TOhtml in lua Co-authored-by: wookayin Co-authored-by: clason Co-authored-by: Lewis Russell --- test/functional/plugin/tohtml_spec.lua | 370 +++++++++++++++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 test/functional/plugin/tohtml_spec.lua (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua new file mode 100644 index 0000000000..66dcfde3aa --- /dev/null +++ b/test/functional/plugin/tohtml_spec.lua @@ -0,0 +1,370 @@ +local Screen = require('test.functional.ui.screen') +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local exec = helpers.exec +local exec_lua = helpers.exec_lua +local eq = helpers.eq +local fn = helpers.fn +local api = helpers.api +local insert = helpers.insert + +local function html_syntax_match() + local styles = + vim.split(api.nvim_exec2([[/', + '', + '', + '
',
+      'line',
+      '',
+      '
', + '', + '', + }, fn.readfile(out_file)) + end) + + it('highlight attributes generated', function() + --Make sure to uncomment the attribute in `html_syntax_match()` + exec('hi LINE gui=' .. table.concat({ + 'bold', + 'underline', + 'italic', + 'strikethrough', + }, ',')) + exec('hi UNDERCURL gui=undercurl') + exec('syn keyword LINE line') + exec('syn keyword UNDERCURL undercurl') + insert('line\nundercurl') + run_tohtml_and_assert(screen) + end) + + it('syntax', function() + insert [[ + function main() + print("hello world") + end + ]] + exec('set termguicolors') + exec('syntax enable') + exec('setf lua') + run_tohtml_and_assert(screen) + end) + + it('diff', function() + exec('set diffopt=') + insert [[ + diffadd + nochage + diffchange1 + ]] + exec('new') + insert [[ + nochage + diffchange2 + diffremove + ]] + exec('set diff') + exec('close') + exec('set diff') + run_tohtml_and_assert(screen) + end) + + it('treesitter', function() + insert [[ + function main() + print("hello world") + end + ]] + exec('setf lua') + exec_lua('vim.treesitter.start()') + run_tohtml_and_assert(screen) + end) + + it('matchadd', function() + insert [[ + line + ]] + fn.matchadd('Visual', 'line') + run_tohtml_and_assert(screen) + end) + + describe('conceallevel', function() + local function run(level) + insert([[ + line0 + line1 + line2 + line3 + ]]) + local ns = api.nvim_create_namespace '' + fn.matchadd('Conceal', 'line1', 3, 5, { conceal = 'a' }) + api.nvim_buf_set_extmark(0, ns, 2, 0, { conceal = 'a', end_col = 5 }) + exec(':syntax match Conceal "line3" conceal cchar=a') + exec('set conceallevel=' .. level) + run_tohtml_and_assert(screen) + end + it('conceallevel=0', function() + run(0) + end) + it('conceallevel=1', function() + run(1) + end) + it('conceallevel=2', function() + run(2) + end) + it('conceallevel=3', function() + run(3) + end) + end) + + describe('extmarks', function() + it('virt_text', function() + insert [[ + line1 + line2 + line3 + line4 + ]] + local ns = api.nvim_create_namespace '' + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'foo' } } }) + api.nvim_buf_set_extmark( + 0, + ns, + 1, + 0, + { virt_text = { { 'foo' } }, virt_text_pos = 'overlay' } + ) + api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_text = { { 'foo' } }, virt_text_pos = 'inline' }) + --api.nvim_buf_set_extmark(0,ns,3,0,{virt_text={{'foo'}},virt_text_pos='right_align'}) + run_tohtml_and_assert(screen) + end) + it('highlgith', function() + insert [[ + line1 + ]] + local ns = api.nvim_create_namespace '' + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 2, hl_group = 'Visual' }) + run_tohtml_and_assert(screen) + end) + it('virt_line', function() + insert [[ + line1 + line2 + ]] + local ns = api.nvim_create_namespace '' + api.nvim_buf_set_extmark(0, ns, 1, 0, { end_col = 2, virt_lines = { { { 'foo' } } } }) + run_tohtml_and_assert(screen) + end) + end) + + it('listchars', function() + exec('setlocal list') + exec( + 'setlocal listchars=eol:$,tab:<->,space:-,multispace:++,lead:_,leadmultispace:##,trail:&,nbsp:%' + ) + fn.setline(1, '\tfoo\t') + fn.setline(2, ' foo foo ') + fn.setline(3, ' foo foo ') + fn.setline(4, 'foo\x2cfoo') + run_tohtml_and_assert(screen) + exec('new|only') + fn.setline(1, '\tfoo\t') + exec('setlocal list') + exec('setlocal listchars=tab:a-') + run_tohtml_and_assert(screen) + end) + + it('folds', function() + insert([[ + line1 + line2 + ]]) + exec('set foldtext=foldtext()') + exec('%fo') + run_tohtml_and_assert(screen) + end) + + it('statuscol', function() + local function run() + local buf = api.nvim_get_current_buf() + run_tohtml_and_assert(screen, function() + exec_lua [[ + local outfile = vim.fn.tempname() .. '.html' + local html = require('tohtml').tohtml(0,{number_lines=true}) + vim.fn.writefile(html, outfile) + vim.cmd.split(outfile) + ]] + end) + api.nvim_set_current_buf(buf) + end + insert([[ + line1 + line2 + ]]) + exec('setlocal relativenumber') + run() + exec('setlocal norelativenumber') + exec('setlocal number') + run() + exec('setlocal relativenumber') + run() + exec('setlocal signcolumn=yes:2') + run() + exec('setlocal foldcolumn=2') + run() + exec('setlocal norelativenumber') + run() + exec('setlocal signcolumn=no') + run() + end) +end) -- cgit From 7311958e1238559db7a0b1f490f15f618f51af06 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Thu, 29 Feb 2024 01:32:25 +0900 Subject: fix(lsp): remove unnecessary file load/write when renaming (#27621) Previously rename would unconditionally read the to-be-renamed file from the disk and write it to the disk. This is redundant in some cases If the file is not already loaded, it's not attached to lsp client, so nvim doesn't need to care about this file. If the file is loaded but has no change, it doesn't need to be written. --- test/functional/plugin/lsp_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index b57fb268e1..0fdcd0dd1d 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2611,7 +2611,7 @@ describe('LSP', function() eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) - eq('Old file\n', read_file(new)) + eq('Old file', read_file(new)) end) end) -- cgit From b413f5d048ab8676d5a77d0f2b3c20587a270673 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 2 Mar 2024 02:31:54 +0900 Subject: fix(lsp): rename undofile when renaming (#27684) Problem: After `rename()`, the undo information for the renamed file(s) are lost. Solution: Rename the undofile as well. --- test/functional/plugin/lsp_spec.lua | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 0fdcd0dd1d..af31d9ccae 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2593,6 +2593,58 @@ describe('LSP', function() eq('New file', read_file(new)) end ) + it('Maintains undo information for loaded buffer', function() + local old = tmpname() + write_file(old, 'line') + local new = tmpname() + os.remove(new) + + local undo_kept = exec_lua( + [[ + local old = select(1, ...) + local new = select(2, ...) + vim.opt.undofile = true + vim.cmd.edit(old) + vim.cmd.normal('dd') + vim.cmd.write() + local undotree = vim.fn.undotree() + vim.lsp.util.rename(old, new) + return vim.deep_equal(undotree, vim.fn.undotree()) + ]], + old, + new + ) + eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) + eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) + eq(true, undo_kept) + end) + it('Maintains undo information for unloaded buffer', function() + local old = tmpname() + write_file(old, 'line') + local new = tmpname() + os.remove(new) + + local undo_kept = exec_lua( + [[ + local old = select(1, ...) + local new = select(2, ...) + vim.opt.undofile = true + vim.cmd.split(old) + vim.cmd.normal('dd') + vim.cmd.write() + local undotree = vim.fn.undotree() + vim.cmd.bdelete() + vim.lsp.util.rename(old, new) + vim.cmd.edit(new) + return vim.deep_equal(undotree, vim.fn.undotree()) + ]], + old, + new + ) + eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) + eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) + eq(true, undo_kept) + end) it('Does override target if overwrite is true', function() local old = tmpname() write_file(old, 'Old file') -- cgit From b87505e11656163ddf0dbbc16b7d224815873964 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 7 Feb 2024 11:24:44 +0000 Subject: refactor(watch): general tidy up - Rename watch.poll to watch.watchdirs - Unify how include and exclude is applied - Improve type hints --- test/functional/plugin/lsp_spec.lua | 194 +++++++++++++++++++----------------- 1 file changed, 105 insertions(+), 89 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index af31d9ccae..79fa4786d2 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -205,8 +205,8 @@ describe('LSP', function() client.stop() end, on_exit = function(code, signal) - eq(0, code, 'exit code', fake_lsp_logfile) - eq(0, signal, 'exit signal', fake_lsp_logfile) + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') end, settings = { dummy = 1, @@ -4490,113 +4490,128 @@ describe('LSP', function() end) describe('vim.lsp._watchfiles', function() - it('sends notifications when files change', function() - skip( - is_os('bsd'), - 'kqueue only reports events on watched folder itself, not contained files #26110' - ) - local root_dir = tmpname() - os.remove(root_dir) - mkdir(root_dir) + local function test_filechanges(watchfunc) + it( + string.format('sends notifications when files change (watchfunc=%s)', watchfunc), + function() + skip( + is_os('bsd'), + 'kqueue only reports events on watched folder itself, not contained files #26110' + ) - exec_lua(create_server_definition) - local result = exec_lua( - [[ - local root_dir = ... + local root_dir = tmpname() + os.remove(root_dir) + mkdir(root_dir) - local server = _create_server() - local client_id = vim.lsp.start({ - name = 'watchfiles-test', - cmd = server.cmd, - root_dir = root_dir, - capabilities = { - workspace = { - didChangeWatchedFiles = { - dynamicRegistration = true, + exec_lua(create_server_definition) + local result = exec_lua( + [[ + local root_dir, watchfunc = ... + + local server = _create_server() + local client_id = vim.lsp.start({ + name = 'watchfiles-test', + cmd = server.cmd, + root_dir = root_dir, + capabilities = { + workspace = { + didChangeWatchedFiles = { + dynamicRegistration = true, + }, }, }, - }, - }) + }) - local expected_messages = 2 -- initialize, initialized + require('vim.lsp._watchfiles')._watchfunc = require('vim._watch')[watchfunc] - local watchfunc = require('vim.lsp._watchfiles')._watchfunc - local msg_wait_timeout = watchfunc == vim._watch.poll and 2500 or 200 - local function wait_for_messages() - assert(vim.wait(msg_wait_timeout, function() return #server.messages == expected_messages end), 'Timed out waiting for expected number of messages. Current messages seen so far: ' .. vim.inspect(server.messages)) - end + local expected_messages = 0 - wait_for_messages() + local msg_wait_timeout = watchfunc == 'watch' and 200 or 2500 - vim.lsp.handlers['client/registerCapability'](nil, { - registrations = { - { - id = 'watchfiles-test-0', - method = 'workspace/didChangeWatchedFiles', - registerOptions = { - watchers = { - { - globPattern = '**/watch', - kind = 7, + local function wait_for_message(incr) + expected_messages = expected_messages + (incr or 1) + assert( + vim.wait(msg_wait_timeout, function() + return #server.messages == expected_messages + end), + 'Timed out waiting for expected number of messages. Current messages seen so far: ' + .. vim.inspect(server.messages) + ) + end + + wait_for_message(2) -- initialize, initialized + + vim.lsp.handlers['client/registerCapability'](nil, { + registrations = { + { + id = 'watchfiles-test-0', + method = 'workspace/didChangeWatchedFiles', + registerOptions = { + watchers = { + { + globPattern = '**/watch', + kind = 7, + }, }, }, }, }, - }, - }, { client_id = client_id }) + }, { client_id = client_id }) - if watchfunc == vim._watch.poll then - vim.wait(100) - end + if watchfunc ~= 'watch' then + vim.wait(100) + end - local path = root_dir .. '/watch' - local file = io.open(path, 'w') - file:close() + local path = root_dir .. '/watch' + local tmp = vim.fn.tempname() + io.open(tmp, 'w'):close() + vim.uv.fs_rename(tmp, path) - expected_messages = expected_messages + 1 - wait_for_messages() + wait_for_message() - os.remove(path) + os.remove(path) - expected_messages = expected_messages + 1 - wait_for_messages() + wait_for_message() - return server.messages - ]], - root_dir - ) + return server.messages + ]], + root_dir, + watchfunc + ) - local function watched_uri(fname) - return exec_lua( - [[ - local root_dir, fname = ... - return vim.uri_from_fname(root_dir .. '/' .. fname) - ]], - root_dir, - fname - ) - end + local uri = vim.uri_from_fname(root_dir .. '/watch') - eq(4, #result) - eq('workspace/didChangeWatchedFiles', result[3].method) - eq({ - changes = { - { - type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]), - uri = watched_uri('watch'), - }, - }, - }, result[3].params) - eq('workspace/didChangeWatchedFiles', result[4].method) - eq({ - changes = { - { - type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]), - uri = watched_uri('watch'), - }, - }, - }, result[4].params) - end) + eq(4, #result) + + eq({ + method = 'workspace/didChangeWatchedFiles', + params = { + changes = { + { + type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]), + uri = uri, + }, + }, + }, + }, result[3]) + + eq({ + method = 'workspace/didChangeWatchedFiles', + params = { + changes = { + { + type = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]]), + uri = uri, + }, + }, + }, + }, result[4]) + end + ) + end + + test_filechanges('watch') + test_filechanges('watchdirs') it('correctly registers and unregisters', function() local root_dir = '/some_dir' @@ -5061,3 +5076,4 @@ describe('LSP', function() end) end) end) + -- cgit From 816b56f878f0291c00a9018d5057b7b2b00f1891 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 7 Feb 2024 13:05:33 +0000 Subject: fix(lsp): cancel watchers when closing a client --- test/functional/plugin/lsp_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 79fa4786d2..1610351090 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -4573,6 +4573,8 @@ describe('LSP', function() wait_for_message() + vim.lsp.stop_client(client_id) + return server.messages ]], root_dir, @@ -4581,7 +4583,7 @@ describe('LSP', function() local uri = vim.uri_from_fname(root_dir .. '/watch') - eq(4, #result) + eq(6, #result) eq({ method = 'workspace/didChangeWatchedFiles', -- cgit From 4ff3217bbd8747d2d44680a825ac29097faf9c4b Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 7 Feb 2024 11:28:35 +0000 Subject: feat(lsp): add fswatch watchfunc backend Problem: vim._watch.watchdirs has terrible performance. Solution: - On linux use fswatch as a watcher backend if available. - Add File watcher section to health:vim.lsp. Warn if watchfunc is libuv-poll. --- test/functional/plugin/lsp_spec.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1610351090..1e787d2b0c 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -4494,6 +4494,15 @@ describe('LSP', function() it( string.format('sends notifications when files change (watchfunc=%s)', watchfunc), function() + if watchfunc == 'fswatch' then + skip( + not is_ci() and fn.executable('fswatch') == 0, + 'fswatch not installed and not on CI' + ) + skip(is_os('win'), 'not supported on windows') + skip(is_os('mac'), 'flaky') + end + skip( is_os('bsd'), 'kqueue only reports events on watched folder itself, not contained files #26110' @@ -4614,6 +4623,7 @@ describe('LSP', function() test_filechanges('watch') test_filechanges('watchdirs') + test_filechanges('fswatch') it('correctly registers and unregisters', function() local root_dir = '/some_dir' @@ -5078,4 +5088,3 @@ describe('LSP', function() end) end) end) - -- cgit From dc8c086c7e73a9035c34be6416e7c465d61edc0e Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 2 Mar 2024 23:21:53 +0900 Subject: fix(lsp): directly rename the existing buffers when renaming (#27690) Problem: `vim.lsp.util.rename()` deletes the buffers that are affected by renaming. This has undesireable side effects. For example, when renaming a directory, all buffers under that directory are deleted and windows displaying those buffers are closed. Also, buffer options may change after renaming. Solution: Rename the buffers with :saveas. An alternative approach is to record all the relevant states and restore it after renaming, but that seems to be more complex. In fact, the older version was attempting to restore the states but only partially and incorrectly. --- test/functional/plugin/lsp_spec.lua | 140 ++++++++++++------------------------ 1 file changed, 47 insertions(+), 93 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1e787d2b0c..4826153edb 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2383,12 +2383,13 @@ describe('LSP', function() [[ local old = select(1, ...) local new = select(2, ...) + local old_bufnr = vim.fn.bufadd(old) + vim.fn.bufload(old_bufnr) vim.lsp.util.rename(old, new) - - -- after rename the target file must have the contents of the source file - local bufnr = vim.fn.bufadd(new) - vim.fn.bufload(new) - return vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) + -- the existing buffer is renamed in-place and its contents is kept + local new_bufnr = vim.fn.bufadd(new) + vim.fn.bufload(new_bufnr) + return (old_bufnr == new_bufnr) and vim.api.nvim_buf_get_lines(new_bufnr, 0, -1, true) ]], old, new @@ -2400,87 +2401,6 @@ describe('LSP', function() eq(true, exists) os.remove(new) end) - it('Kills old buffer after renaming an existing file', function() - local old = tmpname() - write_file(old, 'Test content') - local new = tmpname() - os.remove(new) -- only reserve the name, file must not exist for the test scenario - local lines = exec_lua( - [[ - local old = select(1, ...) - local oldbufnr = vim.fn.bufadd(old) - local new = select(2, ...) - vim.lsp.util.rename(old, new) - return vim.fn.bufloaded(oldbufnr) - ]], - old, - new - ) - eq(0, lines) - os.remove(new) - end) - it('new buffer remains unlisted and unloaded if the old was not in window before', function() - local old = tmpname() - write_file(old, 'Test content') - local new = tmpname() - os.remove(new) -- only reserve the name, file must not exist for the test scenario - local actual = exec_lua( - [[ - local old = select(1, ...) - local oldbufnr = vim.fn.bufadd(old) - local new = select(2, ...) - local newbufnr = vim.fn.bufadd(new) - vim.lsp.util.rename(old, new) - return { - buflisted = vim.bo[newbufnr].buflisted, - bufloaded = vim.api.nvim_buf_is_loaded(newbufnr) - } - ]], - old, - new - ) - - local expected = { - buflisted = false, - bufloaded = false, - } - - eq(expected, actual) - - os.remove(new) - end) - it('new buffer is listed and loaded if the old was in window before', function() - local old = tmpname() - write_file(old, 'Test content') - local new = tmpname() - os.remove(new) -- only reserve the name, file must not exist for the test scenario - local actual = exec_lua( - [[ - local win = vim.api.nvim_get_current_win() - local old = select(1, ...) - local oldbufnr = vim.fn.bufadd(old) - vim.api.nvim_win_set_buf(win, oldbufnr) - local new = select(2, ...) - vim.lsp.util.rename(old, new) - local newbufnr = vim.fn.bufadd(new) - return { - buflisted = vim.bo[newbufnr].buflisted, - bufloaded = vim.api.nvim_buf_is_loaded(newbufnr) - } - ]], - old, - new - ) - - local expected = { - buflisted = true, - bufloaded = true, - } - - eq(expected, actual) - - os.remove(new) - end) it('Can rename a directory', function() -- only reserve the name, file must not exist for the test scenario local old_dir = tmpname() @@ -2497,21 +2417,25 @@ describe('LSP', function() [[ local old_dir = select(1, ...) local new_dir = select(2, ...) - local pathsep = select(3, ...) - local oldbufnr = vim.fn.bufadd(old_dir .. pathsep .. 'file') - + local pathsep = select(3, ...) + local file = select(4, ...) + local old_bufnr = vim.fn.bufadd(old_dir .. pathsep .. file) + vim.fn.bufload(old_bufnr) vim.lsp.util.rename(old_dir, new_dir) - return vim.fn.bufloaded(oldbufnr) + -- the existing buffer is renamed in-place and its contents is kept + local new_bufnr = vim.fn.bufadd(new_dir .. pathsep .. file) + vim.fn.bufload(new_bufnr) + return (old_bufnr == new_bufnr) and vim.api.nvim_buf_get_lines(new_bufnr, 0, -1, true) ]], old_dir, new_dir, - pathsep + pathsep, + file ) - eq(0, lines) + eq({ 'Test content' }, lines) eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old_dir)) eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir)) eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir .. pathsep .. file)) - eq('Test content', read_file(new_dir .. pathsep .. file)) os.remove(new_dir) end) @@ -2609,6 +2533,11 @@ describe('LSP', function() vim.cmd.write() local undotree = vim.fn.undotree() vim.lsp.util.rename(old, new) + -- Renaming uses :saveas, which updates the "last write" information. + -- Other than that, the undotree should remain the same. + undotree.save_cur = undotree.save_cur + 1 + undotree.save_last = undotree.save_last + 1 + undotree.entries[1].save = undotree.entries[1].save + 1 return vim.deep_equal(undotree, vim.fn.undotree()) ]], old, @@ -2645,6 +2574,31 @@ describe('LSP', function() eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) eq(true, undo_kept) end) + it('Does not rename file when it conflicts with a buffer without file', function() + local old = tmpname() + write_file(old, 'Old File') + local new = tmpname() + os.remove(new) + + local lines = exec_lua( + [[ + local old = select(1, ...) + local new = select(2, ...) + local old_buf = vim.fn.bufadd(old) + vim.fn.bufload(old_buf) + local conflict_buf = vim.api.nvim_create_buf(true, false) + vim.api.nvim_buf_set_name(conflict_buf, new) + vim.api.nvim_buf_set_lines(conflict_buf, 0, -1, true, {'conflict'}) + vim.api.nvim_win_set_buf(0, conflict_buf) + vim.lsp.util.rename(old, new) + return vim.api.nvim_buf_get_lines(conflict_buf, 0, -1, true) + ]], + old, + new + ) + eq({ 'conflict' }, lines) + eq('Old File', read_file(old)) + end) it('Does override target if overwrite is true', function() local old = tmpname() write_file(old, 'Old file') -- cgit From a8131aee9ecc640415903d590b15863ce1c99112 Mon Sep 17 00:00:00 2001 From: altermo <107814000+altermo@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:08:23 +0100 Subject: fix(tohtml): replace hex escape with digit escape (#27728) --- test/functional/plugin/tohtml_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index 66dcfde3aa..0d0f10671f 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -315,7 +315,7 @@ describe(':TOhtml', function() fn.setline(1, '\tfoo\t') fn.setline(2, ' foo foo ') fn.setline(3, ' foo foo ') - fn.setline(4, 'foo\x2cfoo') + fn.setline(4, 'foo\194\160 \226\128\175foo') run_tohtml_and_assert(screen) exec('new|only') fn.setline(1, '\tfoo\t') -- cgit From 970b60aa7c899851973285f9b33f5f49cae55f76 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Mar 2024 10:24:46 +0800 Subject: test(tohtml_spec): don't use hard-coded sleeping time (#27770) Instead cause some changes to screen state and use screen:expect(). --- test/functional/plugin/tohtml_spec.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index 0d0f10671f..2ac0fe1fa3 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -115,18 +115,20 @@ end ---@param func function? local function run_tohtml_and_assert(screen, func) exec('norm! ggO-;') - exec('norm! gg0f;:\r') - screen:sleep(10) - local snapshot = { grid = screen:get_snapshot().grid, attr_ids = screen:get_snapshot().attr_ids } + screen:expect({ any = vim.pesc('-^;') }) + exec('norm! :\rh') + screen:expect({ any = vim.pesc('^-;') }) + local expected = screen:get_snapshot() do (func or exec)('TOhtml') end exec('only') html_syntax_match() html_to_extmarks() - exec('norm! gg0f;:\r') - screen:sleep(10) - eq(snapshot, { grid = screen:get_snapshot().grid, attr_ids = screen:get_snapshot().attr_ids }) + exec('norm! gg0f;') + screen:expect({ any = vim.pesc('-^;') }) + exec('norm! :\rh') + screen:expect({ grid = expected.grid, attr_ids = expected.attr_ids }) end describe(':TOhtml', function() @@ -288,7 +290,7 @@ describe(':TOhtml', function() --api.nvim_buf_set_extmark(0,ns,3,0,{virt_text={{'foo'}},virt_text_pos='right_align'}) run_tohtml_and_assert(screen) end) - it('highlgith', function() + it('highlight', function() insert [[ line1 ]] -- cgit