diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
| commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
| tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/plugin | |
| parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
| download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip | |
refactor: format test/*
Diffstat (limited to 'test/functional/plugin')
| -rw-r--r-- | test/functional/plugin/editorconfig_spec.lua | 2 | ||||
| -rw-r--r-- | test/functional/plugin/health_spec.lua | 124 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/codelens_spec.lua | 43 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/completion_spec.lua | 90 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/diagnostic_spec.lua | 59 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/handler_spec.lua | 19 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/helpers.lua | 43 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/incremental_sync_spec.lua | 426 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/inlay_hint_spec.lua | 16 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/semantic_tokens_spec.lua | 251 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/utils_spec.lua | 117 | ||||
| -rw-r--r-- | test/functional/plugin/lsp_spec.lua | 2215 | ||||
| -rw-r--r-- | test/functional/plugin/man_spec.lua | 115 | ||||
| -rw-r--r-- | test/functional/plugin/matchparen_spec.lua | 13 | ||||
| -rw-r--r-- | test/functional/plugin/msgpack_spec.lua | 497 | ||||
| -rw-r--r-- | test/functional/plugin/shada_spec.lua | 3578 | ||||
| -rw-r--r-- | test/functional/plugin/tutor_spec.lua | 6 |
17 files changed, 4378 insertions, 3236 deletions
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<C-R>"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { 'jf_vejjbhhdu<C-R>' }, 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$h<C-V>jg<C-A>"}, expected_text_changes, 'utf-16', '\n') + test_edit(original_lines, { '3gg$h<C-V>jg<C-A>' }, 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | | 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 <iostream> | 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 <iostream> | | int {8:main}() | @@ -1214,10 +1273,12 @@ int main() ^} | {1:~ }|*4 | - ]]} + ]], + } end, expected_screen2 = function() - screen:expect{grid=[[ + screen:expect { + grid = [[ #include <iostream> | | 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<CR><Esc>") -- fill screen with empty lines + feed('79i<CR><Esc>') -- 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 - if ctx.method == 'finish' then client.stop() end - 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 <algorithm>\r'}); + make_edit(0, 0, 1, 22, { '#include "whatever.h"\r\n#include <algorithm>\r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'#include "whatever.h"', '#include <algorithm>'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-8') + eq({ '#include "whatever.h"', '#include <algorithm>' }, 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 <algorithm>\r'}); + make_edit(0, 0, 0, 22, { '#include "whatever.h"\r\n#include <algorithm>\r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'#include "whatever.h"', '#include <algorithm>', '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 <algorithm>', '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 <algorithm>\r'}); + make_edit(0, 2, 1, 22, { '#include "whatever.h"\r\n#include <algorithm>\r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'Te#include "whatever.h"', '#include <algorithm>'}, buf_lines(1)) + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-8') + eq({ 'Te#include "whatever.h"', '#include <algorithm>' }, 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 <algorithm>\r'}); + make_edit(0, 2, 0, 22, { '#include "whatever.h"\r\n#include <algorithm>\r' }), } - exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") - eq({'Te#include "whatever.h"', '#include <algorithm>', '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 <algorithm>', '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('<cword>')]]) + eq('å', exec_lua [[return vim.fn.expand('<cword>')]]) 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 i<C-v><C-h>is<C-v><C-h>s a<C-v><C-h>a test - with _<C-v><C-h>o_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>c_<C-v><C-h>k text<ESC>]]) + with _<C-v><C-h>o_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>c_<C-v><C-h>k text<ESC>]] + ) - 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 <C-v><ESC>[1mis <C-v><ESC>[3ma <C-v><ESC>[4mtest<C-v><ESC>[0m - <C-v><ESC>[4mwith<C-v><ESC>[24m <C-v><ESC>[4mescaped<C-v><ESC>[24m <C-v><ESC>[4mtext<C-v><ESC>[24m<ESC>]]) + <C-v><ESC>[4mwith<C-v><ESC>[24m <C-v><ESC>[4mescaped<C-v><ESC>[24m <C-v><ESC>[4mtext<C-v><ESC>[24m<ESC>]] + ) - 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 i<C-v><C-h>is<C-v><C-h>s あ<C-v><C-h>あ test - with _<C-v><C-h>ö_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>̃_<C-v><C-h>c_<C-v><C-h>k te<C-v><ESC>[3mxt¶<C-v><ESC>[0m<ESC>]]) - exec_lua[[require'man'.init_pager()]] + with _<C-v><C-h>ö_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>̃_<C-v><C-h>c_<C-v><C-h>k te<C-v><ESC>[3mxt¶<C-v><ESC>[0m<ESC>]] + ) + 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_<C-v><C-h>_b<C-v><C-h>be<C-v><C-h>eg<C-v><C-h>gi<C-v><C-h>in<C-v><C-h>ns<C-v><C-h>s m<C-v><C-h>mi<C-v><C-h>id<C-v><C-h>d_<C-v><C-h>_d<C-v><C-h>dl<C-v><C-h>le<C-v><C-h>e - _<C-v><C-h>m_<C-v><C-h>i_<C-v><C-h>d_<C-v><C-h>__<C-v><C-h>d_<C-v><C-h>l_<C-v><C-h>e<ESC>]]) - exec_lua[[require'man'.init_pager()]] + _<C-v><C-h>m_<C-v><C-h>i_<C-v><C-h>d_<C-v><C-h>__<C-v><C-h>d_<C-v><C-h>l_<C-v><C-h>e<ESC>]] + ) + exec_lua [[require'man'.init_pager()]] screen:expect([[ {b:^_begins} | @@ -142,7 +154,7 @@ describe(':Man', function() i· ·<C-v><C-h>· +<C-v><C-h>o +<C-v><C-h>+<C-v><C-h>o<C-v><C-h>o double<ESC>]]) - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^· {b:·} | @@ -159,7 +171,7 @@ describe(':Man', function() <C-v><C-[>[44m 4 <C-v><C-[>[45m 5 <C-v><C-[>[46m 6 <C-v><C-[>[47m 7 <C-v><C-[>[100m 8 <C-v><C-[>[101m 9 <C-v><C-[>[102m 10 <C-v><C-[>[103m 11 <C-v><C-[>[104m 12 <C-v><C-[>[105m 13 <C-v><C-[>[106m 14 <C-v><C-[>[107m 15 <C-v><C-[>[48:5:16m 16 <ESC>]]) - 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_<Up>. 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', @@ -1112,24 +1312,27 @@ describe('autoload/shada.vim', function() ' + 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': [ + }, { { 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', '')) + ]}] ]]):gsub('\n', '') + ) end) it('works with local mark items', function() @@ -1137,99 +1340,120 @@ describe('autoload/shada.vim', function() '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': { + }, { { 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': { + }}] ]]):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': { + }}] ]]):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 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 mld = function(s) + return { + { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongDescription' }, + 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. | |