Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| ab439dd96d |
4 changed files with 62 additions and 6 deletions
|
|
@ -1,9 +1,13 @@
|
||||||
local mock = {
|
local mock = {
|
||||||
commands = {},
|
commands = {},
|
||||||
|
lines = {},
|
||||||
|
cursors = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.reset = function()
|
mock.reset = function()
|
||||||
mock.commands = {}
|
mock.commands = {}
|
||||||
|
mock.lines = {}
|
||||||
|
mock.cursors = {}
|
||||||
|
|
||||||
_G.vim = {
|
_G.vim = {
|
||||||
notify = function() end,
|
notify = function() end,
|
||||||
|
|
@ -23,6 +27,44 @@ mock.reset = function()
|
||||||
nvim_buf_set_option = function() end,
|
nvim_buf_set_option = function() end,
|
||||||
nvim_buf_set_var = function() end,
|
nvim_buf_set_var = function() end,
|
||||||
nvim_buf_set_keymap = function() end,
|
nvim_buf_set_keymap = function() end,
|
||||||
|
nvim_buf_delete = function() end,
|
||||||
|
nvim_buf_set_lines = function(buffer_number, state_index, end_index, _, items)
|
||||||
|
local new_lines = {}
|
||||||
|
|
||||||
|
for index = 1, state_index do
|
||||||
|
if mock.lines[buffer_number][index] == nil then
|
||||||
|
table.insert(new_lines, "")
|
||||||
|
else
|
||||||
|
table.insert(new_lines, mock.lines[buffer_number][index])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for index = 1, #items do
|
||||||
|
table.insert(new_lines, items[index])
|
||||||
|
end
|
||||||
|
|
||||||
|
if end_index ~= -1 then
|
||||||
|
error("Mock of nvim_buf_set_lines dose not support a end_index grater than -1 found " .. end_index)
|
||||||
|
end
|
||||||
|
|
||||||
|
mock.lines[buffer_number] = new_lines
|
||||||
|
end,
|
||||||
|
nvim_win_set_height = function() end,
|
||||||
|
nvim_win_set_cursor = function(window_number, position)
|
||||||
|
mock.cursors[window_number] = position
|
||||||
|
end,
|
||||||
|
nvim_buf_get_lines = function(buffer_number, start_index, end_index)
|
||||||
|
local lines = {}
|
||||||
|
for index = start_index, end_index do
|
||||||
|
table.insert(lines, mock.lines[buffer_number][index + 1])
|
||||||
|
end
|
||||||
|
|
||||||
|
if #lines == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return lines
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,19 @@ before_each(function()
|
||||||
vim_mock.reset()
|
vim_mock.reset()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("can initialize", function(t)
|
it("can initialize and destroy the window", function(t)
|
||||||
window.initialize()
|
window.initialize()
|
||||||
|
|
||||||
if window.get_buffer() ~= 10 then
|
t.assert_equal(10, window.get_buffer())
|
||||||
t.error("The windows buffer should be 10 found " .. window.get_buffer())
|
t.assert_equal(10, window.buffer)
|
||||||
end
|
|
||||||
|
window.destroy()
|
||||||
|
t.assert_equal(nil, window.buffer)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("can set items", function(t)
|
||||||
|
window.initialize()
|
||||||
|
|
||||||
|
window.set_items { { content = "Line one" } }
|
||||||
|
t.assert_equal("Line one", window.get_current_selection())
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -54,12 +54,12 @@ vim.api.nvim_create_user_command("IvyLines", function()
|
||||||
local score = libivy.ivy_match(input, line)
|
local score = libivy.ivy_match(input, line)
|
||||||
if score > -200 then
|
if score > -200 then
|
||||||
local prefix = string.rep(" ", 4 - #tostring(index)) .. index .. ": "
|
local prefix = string.rep(" ", 4 - #tostring(index)) .. index .. ": "
|
||||||
table.insert(list, { score, prefix .. line })
|
table.insert(list, { score = score, content = prefix .. line })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.sort(list, function(a, b)
|
table.sort(list, function(a, b)
|
||||||
return a[1] < b[1]
|
return a.score < b.score
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return list
|
return list
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ _G.it = function(name, callback)
|
||||||
error = function(message)
|
error = function(message)
|
||||||
error(message, 2)
|
error(message, 2)
|
||||||
end,
|
end,
|
||||||
|
assert_equal = function(expected, actual)
|
||||||
|
if expected ~= actual then
|
||||||
|
error("Failed to assert that '" .. expected .. "' matches '" .. actual .. "'", 2)
|
||||||
|
end
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
call_hook "before_each"
|
call_hook "before_each"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue