Add cmdline expansion test
This commit is contained in:
@@ -4,6 +4,7 @@ local types = require('cmp.types')
|
|||||||
local core = require('cmp.core')
|
local core = require('cmp.core')
|
||||||
local source = require('cmp.source')
|
local source = require('cmp.source')
|
||||||
local keymap = require('cmp.utils.keymap')
|
local keymap = require('cmp.utils.keymap')
|
||||||
|
local api = require('cmp.utils.api')
|
||||||
|
|
||||||
describe('cmp.core', function()
|
describe('cmp.core', function()
|
||||||
describe('confirm', function()
|
describe('confirm', function()
|
||||||
@@ -27,8 +28,12 @@ describe('cmp.core', function()
|
|||||||
local state = {}
|
local state = {}
|
||||||
feedkeys.call('', 'x', function()
|
feedkeys.call('', 'x', function()
|
||||||
feedkeys.call('', 'n', function()
|
feedkeys.call('', 'n', function()
|
||||||
state.buffer = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
if api.is_cmdline_mode() then
|
||||||
state.cursor = vim.api.nvim_win_get_cursor(0)
|
state.buffer = { api.get_current_line() }
|
||||||
|
else
|
||||||
|
state.buffer = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||||
|
end
|
||||||
|
state.cursor = api.get_cursor()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
return state
|
return state
|
||||||
@@ -107,5 +112,47 @@ describe('cmp.core', function()
|
|||||||
assert.are.same(state.cursor, { 2, 2 })
|
assert.are.same(state.cursor, { 2, 2 })
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('cmdline-mode', function()
|
||||||
|
before_each(spec.before)
|
||||||
|
|
||||||
|
it('label', function()
|
||||||
|
local state = confirm(':A', 'IU', {
|
||||||
|
label = 'AIUEO',
|
||||||
|
})
|
||||||
|
assert.are.same(state.buffer, { 'AIUEO' })
|
||||||
|
assert.are.same(state.cursor[2], 5)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('insertText', function()
|
||||||
|
local state = confirm(':A', 'IU', {
|
||||||
|
label = 'AIUEO',
|
||||||
|
insertText = '_AIUEO_',
|
||||||
|
})
|
||||||
|
assert.are.same(state.buffer, { '_AIUEO_' })
|
||||||
|
assert.are.same(state.cursor[2], 7)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('text edit', function()
|
||||||
|
local state = confirm(keymap.t(':***AEO***<Left><Left><Left><Left><Left>'), 'IU', {
|
||||||
|
label = 'AIUEO',
|
||||||
|
textEdit = {
|
||||||
|
range = {
|
||||||
|
start = {
|
||||||
|
line = 0,
|
||||||
|
character = 3,
|
||||||
|
},
|
||||||
|
['end'] = {
|
||||||
|
line = 0,
|
||||||
|
character = 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
newText = 'foobarbaz',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.are.same(state.buffer, { '***foobarbaz***' })
|
||||||
|
assert.are.same(state.cursor[2], 12)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ spec.before = function()
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
config.set_cmdline({
|
||||||
|
sources = {
|
||||||
|
{ name = 'spec' },
|
||||||
|
},
|
||||||
|
}, ':')
|
||||||
end
|
end
|
||||||
|
|
||||||
spec.state = function(text, row, col)
|
spec.state = function(text, row, col)
|
||||||
|
|||||||
Reference in New Issue
Block a user