feat: initial release
This commit is contained in:
commit
a2fe68b248
26 changed files with 960 additions and 0 deletions
54
spec/helpers.lua
Normal file
54
spec/helpers.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
local plugin_dir = vim.fn.getcwd()
|
||||
vim.opt.runtimepath:prepend(plugin_dir)
|
||||
|
||||
if not package.loaded['blink.cmp.types'] then
|
||||
package.loaded['blink.cmp.types'] = {
|
||||
CompletionItemKind = {
|
||||
Text = 1,
|
||||
Method = 2,
|
||||
Function = 3,
|
||||
Constructor = 4,
|
||||
Field = 5,
|
||||
Variable = 6,
|
||||
Class = 7,
|
||||
Interface = 8,
|
||||
Module = 9,
|
||||
Property = 10,
|
||||
Unit = 11,
|
||||
Value = 12,
|
||||
Enum = 13,
|
||||
Keyword = 14,
|
||||
Snippet = 15,
|
||||
Color = 16,
|
||||
File = 17,
|
||||
Reference = 18,
|
||||
Folder = 19,
|
||||
EnumMember = 20,
|
||||
Constant = 21,
|
||||
Struct = 22,
|
||||
Event = 23,
|
||||
Operator = 24,
|
||||
TypeParameter = 25,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.create_buffer(lines, filetype)
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines or {})
|
||||
if filetype then
|
||||
vim.api.nvim_set_option_value('filetype', filetype, { buf = bufnr })
|
||||
end
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
return bufnr
|
||||
end
|
||||
|
||||
function M.delete_buffer(bufnr)
|
||||
if bufnr and vim.api.nvim_buf_is_valid(bufnr) then
|
||||
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
34
spec/minimal_init.lua
Normal file
34
spec/minimal_init.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
vim.cmd([[set runtimepath=$VIMRUNTIME]])
|
||||
vim.opt.runtimepath:append('.')
|
||||
vim.opt.packpath = {}
|
||||
vim.opt.loadplugins = false
|
||||
|
||||
package.loaded['blink.cmp.types'] = {
|
||||
CompletionItemKind = {
|
||||
Text = 1,
|
||||
Method = 2,
|
||||
Function = 3,
|
||||
Constructor = 4,
|
||||
Field = 5,
|
||||
Variable = 6,
|
||||
Class = 7,
|
||||
Interface = 8,
|
||||
Module = 9,
|
||||
Property = 10,
|
||||
Unit = 11,
|
||||
Value = 12,
|
||||
Enum = 13,
|
||||
Keyword = 14,
|
||||
Snippet = 15,
|
||||
Color = 16,
|
||||
File = 17,
|
||||
Reference = 18,
|
||||
Folder = 19,
|
||||
EnumMember = 20,
|
||||
Constant = 21,
|
||||
Struct = 22,
|
||||
Event = 23,
|
||||
Operator = 24,
|
||||
TypeParameter = 25,
|
||||
},
|
||||
}
|
||||
166
spec/tmux_spec.lua
Normal file
166
spec/tmux_spec.lua
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
local helpers = require('spec.helpers')
|
||||
|
||||
local TMUX_COMMANDS = table.concat({
|
||||
'bind-key (bind) [-lnrN:T:] key command [arguments]',
|
||||
'display-message (display) [-aINpv] [-c target-client] [-d delay] [-t target-pane] [message]',
|
||||
'set-option (set) [-aFgopqsuUw] [-t target-pane] option [value]',
|
||||
}, '\n')
|
||||
|
||||
local TMUX_NAMES = 'bind-key\ndisplay-message\nset-option\n'
|
||||
|
||||
local MAN_PAGE = table.concat({
|
||||
' bind-key [-lnrN:T:] key command [arguments]',
|
||||
' (alias: bind)',
|
||||
'',
|
||||
' Bind a key to a command.',
|
||||
'',
|
||||
' display-message [-aINpv] [-c target-client] [-d delay] [-t target-pane] [message]',
|
||||
' (alias: display)',
|
||||
'',
|
||||
' Display a message.',
|
||||
'',
|
||||
' set-option [-aFgopqsuUw] [-t target-pane] option [value]',
|
||||
' (alias: set)',
|
||||
'',
|
||||
' Set a window option.',
|
||||
}, '\n')
|
||||
|
||||
local function mock_system()
|
||||
local original = vim.system
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
vim.system = function(cmd)
|
||||
if cmd[1] == 'bash' then
|
||||
return {
|
||||
wait = function()
|
||||
return { stdout = MAN_PAGE, code = 0 }
|
||||
end,
|
||||
}
|
||||
elseif cmd[1] == 'tmux' and cmd[2] == 'list-commands' then
|
||||
if cmd[3] == '-F' then
|
||||
return {
|
||||
wait = function()
|
||||
return { stdout = TMUX_NAMES, code = 0 }
|
||||
end,
|
||||
}
|
||||
end
|
||||
return {
|
||||
wait = function()
|
||||
return { stdout = TMUX_COMMANDS, code = 0 }
|
||||
end,
|
||||
}
|
||||
end
|
||||
return {
|
||||
wait = function()
|
||||
return { stdout = '', code = 1 }
|
||||
end,
|
||||
}
|
||||
end
|
||||
return function()
|
||||
vim.system = original
|
||||
end
|
||||
end
|
||||
|
||||
describe('blink-cmp-tmux', function()
|
||||
local restore
|
||||
|
||||
before_each(function()
|
||||
package.loaded['blink-cmp-tmux'] = nil
|
||||
restore = mock_system()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
if restore then
|
||||
restore()
|
||||
end
|
||||
end)
|
||||
|
||||
describe('enabled', function()
|
||||
it('returns true for tmux filetype', function()
|
||||
local bufnr = helpers.create_buffer({}, 'tmux')
|
||||
local source = require('blink-cmp-tmux')
|
||||
assert.is_true(source.enabled())
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('returns false for other filetypes', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local source = require('blink-cmp-tmux')
|
||||
assert.is_false(source.enabled())
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('get_completions', function()
|
||||
it('returns items with Keyword kind', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local items
|
||||
source:get_completions({ line = '', cursor = { 1, 0 } }, function(response)
|
||||
items = response.items
|
||||
end)
|
||||
assert.is_not_nil(items)
|
||||
assert.equals(3, #items)
|
||||
for _, item in ipairs(items) do
|
||||
assert.equals(14, item.kind)
|
||||
end
|
||||
end)
|
||||
|
||||
it('returns items on empty line', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local items
|
||||
source:get_completions({ line = '', cursor = { 1, 0 } }, function(response)
|
||||
items = response.items
|
||||
end)
|
||||
assert.equals(3, #items)
|
||||
end)
|
||||
|
||||
it('returns items when typing command prefix', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local items
|
||||
source:get_completions({ line = 'bind', cursor = { 1, 4 } }, function(response)
|
||||
items = response.items
|
||||
end)
|
||||
assert.is_true(#items > 0)
|
||||
end)
|
||||
|
||||
it('returns empty after command arguments', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local items
|
||||
source:get_completions({ line = 'bind-key -n ', cursor = { 1, 12 } }, function(response)
|
||||
items = response.items
|
||||
end)
|
||||
assert.equals(0, #items)
|
||||
end)
|
||||
|
||||
it('includes documentation with man page description', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local items
|
||||
source:get_completions({ line = '', cursor = { 1, 0 } }, function(response)
|
||||
items = response.items
|
||||
end)
|
||||
local bind = vim.iter(items):find(function(item)
|
||||
return item.label == 'bind-key'
|
||||
end)
|
||||
assert.is_not_nil(bind)
|
||||
assert.is_not_nil(bind.documentation)
|
||||
assert.is_truthy(bind.documentation.value:find('Bind a key'))
|
||||
end)
|
||||
|
||||
it('includes alias in documentation', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local items
|
||||
source:get_completions({ line = '', cursor = { 1, 0 } }, function(response)
|
||||
items = response.items
|
||||
end)
|
||||
local bind = vim.iter(items):find(function(item)
|
||||
return item.label == 'bind-key'
|
||||
end)
|
||||
assert.is_truthy(bind.documentation.value:find('alias'))
|
||||
end)
|
||||
|
||||
it('returns a cancel function', function()
|
||||
local source = require('blink-cmp-tmux').new()
|
||||
local cancel = source:get_completions({ line = '', cursor = { 1, 0 } }, function() end)
|
||||
assert.is_function(cancel)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue