diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/vim_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/lua/uri_spec.lua | 11 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 102 | ||||
-rw-r--r-- | test/functional/terminal/buffer_spec.lua | 12 |
4 files changed, 145 insertions, 2 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index fb3755cb8e..2e9d0f57ac 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -571,6 +571,28 @@ describe('API', function() eq({0,7,1,0}, funcs.getpos('.')) eq(false, nvim('get_option', 'paste')) end) + it('Replace-mode', function() + -- Within single line + nvim('put', {'aabbccdd', 'eeffgghh', 'iijjkkll'}, "c", true, false) + command('normal l') + command('startreplace') + nvim('paste', '123456', true, -1) + expect([[ + a123456d + eeffgghh + iijjkkll]]) + command('%delete _') + -- Across lines + nvim('put', {'aabbccdd', 'eeffgghh', 'iijjkkll'}, "c", true, false) + command('normal l') + command('startreplace') + nvim('paste', '123\n456', true, -1) + expect([[ + a123 + 456d + eeffgghh + iijjkkll]]) + end) it('crlf=false does not break lines at CR, CRLF', function() nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua index 128c7c6137..a3b8e685e1 100644 --- a/test/functional/lua/uri_spec.lua +++ b/test/functional/lua/uri_spec.lua @@ -113,4 +113,15 @@ describe('URI methods', function() end) end) end) + + describe('uri to bufnr', function() + it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris', function() + local uri = 'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class' + local test_case = string.format([[ + local uri = '%s' + return vim.uri_from_bufnr(vim.uri_to_bufnr(uri)) + ]], uri) + eq(uri, exec_lua(test_case)) + end) + end) end) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1a0063b43e..79f6ef9dd2 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -770,13 +770,14 @@ describe('LSP', function() exec_lua([[require'vim.lsp'; return vim.fn.getcompletion('Lsp', 'highlight')]])) end) - describe('apply_edits', function() + describe('apply_text_edits', function() before_each(function() insert(dedent([[ First line of text Second line of text Third line of text - Fourth line of text]])) + Fourth line of text + å å ɧ 汉语 ↥ 🤦 🦄]])) end) it('applies apply simple edits', function() local edits = { @@ -790,6 +791,7 @@ describe('LSP', function() '2econd line of text'; '3ird line of text'; 'Fourth line of text'; + 'å å ɧ 汉语 ↥ 🤦 🦄'; }, buf_lines(1)) end) it('applies complex edits', function() @@ -813,8 +815,104 @@ describe('LSP', function() 'The next line of text'; 'another line of text'; 'before this!'; + 'å å ɧ 汉语 ↥ 🤦 🦄'; }, buf_lines(1)) end) + pending('applies non-ASCII characters edits', function() + -- FIXME: We don't handle non-ASCII characters well in UTF-16 + local edits = { + make_edit(4, 0, 4, 14, {"a a h"}); + } + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1) + eq({ + 'First line of text'; + 'Second line of text'; + 'Third line of text'; + 'Fourth line of text'; + 'a a h'; + }, buf_lines(1)) + end) + end) + + describe('apply_text_document_edit', function() + local target_bufnr + before_each(function() + target_bufnr = exec_lua [[ + local bufnr = vim.fn.bufadd("fake/uri") + local lines = {"1st line of text", "2nd line of text"} + vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines) + return bufnr + ]] + end) + it('correctly goes ahead with the edit if all is normal', function() + local text_document_edit = { + edits = { + make_edit(0, 0, 0, 3, "First") + }, + textDocument = { + uri = "file://fake/uri"; + version = 5 + } + } + exec_lua([[ + local args = {...} + local target_bufnr = args[2] + vim.lsp.util.buf_versions[target_bufnr] = 4 + vim.lsp.util.apply_text_document_edit(...) + ]], text_document_edit, target_bufnr) + eq({ + 'First line of text'; + '2nd line of text'; + }, buf_lines(target_bufnr)) + end) + it('correctly goes ahead with the edit if the version is vim.NIL', function() + -- we get vim.NIL when we decode json null value. + local json = exec_lua[[ + return vim.fn.json_decode("{ \"a\": 1, \"b\": null }") + ]] + eq(json.b, exec_lua("return vim.NIL")) + + local text_document_edit = { + edits = { + make_edit(0, 0, 0, 3, "First") + }, + textDocument = { + uri = "file://fake/uri"; + version = exec_lua("return vim.NIL") + } + } + exec_lua([[ + local args = {...} + local target_bufnr = args[2] + vim.lsp.util.buf_versions[target_bufnr] = vim.NIL + vim.lsp.util.apply_text_document_edit(...) + ]], text_document_edit, target_bufnr) + eq({ + '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 text_document_edit = { + edits = { + make_edit(0, 0, 0, 3, "First") + }, + textDocument = { + uri = "file://fake/uri"; + version = 1 + } + } + exec_lua([[ + local args = {...} + local target_bufnr = args[2] + vim.lsp.util.buf_versions[target_bufnr] = 2 + vim.lsp.util.apply_text_document_edit(...) + ]], text_document_edit, target_bufnr) + eq({ + '1st line of text'; + '2nd line of text'; + }, buf_lines(target_bufnr)) + end) end) describe('completion_list_to_complete_items', function() diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index d40baca871..f79aceaddf 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -17,6 +17,18 @@ describe(':terminal buffer', function() screen = thelpers.screen_setup() end) + it('terminal-mode forces various options', function() + feed([[<C-\><C-N>]]) + command('setlocal cursorline cursorcolumn scrolloff=4 sidescrolloff=7') + eq({ 1, 1, 4, 7 }, eval('[&l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]')) + eq('n', eval('mode()')) + + -- Enter terminal-mode ("insert" mode in :terminal). + feed('i') + eq('t', eval('mode()')) + eq({ 0, 0, 0, 0 }, eval('[&l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]')) + end) + describe('when a new file is edited', function() before_each(function() feed('<c-\\><c-n>:set bufhidden=wipe<cr>:enew<cr>') |