Add tests
This commit is contained in:
@@ -389,12 +389,6 @@ core.confirm = function(self, e, option, callback)
|
||||
completion_item.textEdit.newText = ''
|
||||
end
|
||||
vim.fn['cmp#apply_text_edits'](ctx.bufnr, { completion_item.textEdit })
|
||||
if is_snippet then
|
||||
config.get().snippet.expand({
|
||||
body = new_text,
|
||||
insert_text_mode = completion_item.insertTextMode,
|
||||
})
|
||||
else
|
||||
local texts = vim.split(completion_item.textEdit.newText, '\n')
|
||||
local position = completion_item.textEdit.range.start
|
||||
position.line = position.line + (#texts - 1)
|
||||
@@ -405,6 +399,11 @@ core.confirm = function(self, e, option, callback)
|
||||
end
|
||||
local pos = types.lsp.Position.to_vim(0, position)
|
||||
vim.api.nvim_win_set_cursor(0, { pos.row, pos.col - 1 })
|
||||
if is_snippet then
|
||||
config.get().snippet.expand({
|
||||
body = new_text,
|
||||
insert_text_mode = completion_item.insertTextMode,
|
||||
})
|
||||
end
|
||||
else
|
||||
local keys = {}
|
||||
|
||||
@@ -6,9 +6,7 @@ local source = require('cmp.source')
|
||||
local keymap = require('cmp.utils.keymap')
|
||||
|
||||
describe('cmp.core', function()
|
||||
describe('confirm #confirm', function()
|
||||
before_each(spec.before)
|
||||
|
||||
describe('confirm', function()
|
||||
local confirm = function(request, filter, completion_item)
|
||||
local c = core.new()
|
||||
local s = source.new('spec', {
|
||||
@@ -36,7 +34,10 @@ describe('cmp.core', function()
|
||||
return state
|
||||
end
|
||||
|
||||
it('label only', function()
|
||||
describe('insert-mode', function()
|
||||
before_each(spec.before)
|
||||
|
||||
it('label', function()
|
||||
local state = confirm('iA', 'IU', {
|
||||
label = 'AIUEO',
|
||||
})
|
||||
@@ -44,6 +45,15 @@ describe('cmp.core', function()
|
||||
assert.are.same(state.cursor, { 1, 5 })
|
||||
end)
|
||||
|
||||
it('insertText', function()
|
||||
local state = confirm('iA', 'IU', {
|
||||
label = 'AIUEO',
|
||||
insertText = '_AIUEO_',
|
||||
})
|
||||
assert.are.same(state.buffer, { '_AIUEO_' })
|
||||
assert.are.same(state.cursor, { 1, 7 })
|
||||
end)
|
||||
|
||||
it('text edit', function()
|
||||
local state = confirm(keymap.t('i***AEO***<Left><Left><Left><Left><Left>'), 'IU', {
|
||||
label = 'AIUEO',
|
||||
@@ -65,7 +75,7 @@ describe('cmp.core', function()
|
||||
assert.are.same(state.cursor, { 3, 3 })
|
||||
end)
|
||||
|
||||
it('snippet', function()
|
||||
it('insertText & snippet', function()
|
||||
local state = confirm('iA', 'IU', {
|
||||
label = 'AIUEO',
|
||||
insertText = 'AIUEO($0)',
|
||||
@@ -74,5 +84,28 @@ describe('cmp.core', function()
|
||||
assert.are.same(state.buffer, { 'AIUEO()' })
|
||||
assert.are.same(state.cursor, { 1, 6 })
|
||||
end)
|
||||
|
||||
it('textEdit & snippet', function()
|
||||
local state = confirm(keymap.t('i***AEO***<Left><Left><Left><Left><Left>'), 'IU', {
|
||||
label = 'AIUEO',
|
||||
insertTextFormat = types.lsp.InsertTextFormat.Snippet,
|
||||
textEdit = {
|
||||
range = {
|
||||
start = {
|
||||
line = 0,
|
||||
character = 3,
|
||||
},
|
||||
['end'] = {
|
||||
line = 0,
|
||||
character = 6,
|
||||
},
|
||||
},
|
||||
newText = 'foo\nba$0r\nbaz',
|
||||
},
|
||||
})
|
||||
assert.are.same(state.buffer, { '***foo', 'bar', 'baz***' })
|
||||
assert.are.same(state.cursor, { 2, 2 })
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -37,7 +37,7 @@ spec.before = function()
|
||||
if i == 1 then
|
||||
vim.api.nvim_win_set_cursor(0, { ctx.cursor.row, ctx.cursor.col + s - 2 })
|
||||
else
|
||||
vim.api.nvim_win_set_cursor(0, { ctx.cursor.row, s - 1 })
|
||||
vim.api.nvim_win_set_cursor(0, { ctx.cursor.row + i - 1, s - 1 })
|
||||
end
|
||||
break
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user