aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:29 +0100
commit04f2f864e270e772c6326cefdf24947f0130e492 (patch)
tree46f83f909b888a66c741032ab955afc6eab84292 /test/functional/plugin/lsp
parent59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff)
downloadrneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip
refactor: format test/*
Diffstat (limited to 'test/functional/plugin/lsp')
-rw-r--r--test/functional/plugin/lsp/codelens_spec.lua43
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua90
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua59
-rw-r--r--test/functional/plugin/lsp/handler_spec.lua19
-rw-r--r--test/functional/plugin/lsp/helpers.lua43
-rw-r--r--test/functional/plugin/lsp/incremental_sync_spec.lua426
-rw-r--r--test/functional/plugin/lsp/inlay_hint_spec.lua16
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua251
-rw-r--r--test/functional/plugin/lsp/utils_spec.lua117
9 files changed, 625 insertions, 439 deletions
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 = ''