ivy.nvim/lua/ivy/utils_vimgrep_action_spec.lua
Ade Attwood 37cad71291 test: move the suite over to busted
Summary:

Right now we are using a custom test runner. This move the suite over to
busted, this will make things much more maintainable going forward. The two
main reasons for moving are.

1) The custom runner as some bugs, when running assertions we are not getting
the correct results.

2) All of the busted mocking features. We can use spy and mock, this will allow
us to remove the nvim_mock. This file is not amazing and confuses the lsp
often.

Test Plan:

CI
2024-06-16 17:17:16 +01:00

56 lines
1.5 KiB
Lua

local utils = require "ivy.utils"
local vimgrep_action = utils.vimgrep_action()
local test_data = {
{
it = "will edit some file and goto the line",
completion = "some/file.lua:2: This is some text",
action = utils.actions.EDIT,
commands = {
"edit some/file.lua",
"2",
},
},
{
it = "will skip the line if its not matched",
completion = "some/file.lua: This is some text",
action = utils.actions.EDIT,
commands = { "buffer some/file.lua" },
},
{
it = "will run the vsplit command",
completion = "some/file.lua: This is some text",
action = utils.actions.VSPLIT,
commands = { "vsplit | buffer some/file.lua" },
},
{
it = "will run the split command",
completion = "some/file.lua: This is some text",
action = utils.actions.SPLIT,
commands = { "split | buffer some/file.lua" },
},
}
describe("utils vimgrep_action", function()
before_each(function()
spy.on(vim, "cmd")
end)
after_each(function()
vim.cmd:revert()
end)
for i = 1, #test_data do
local data = test_data[i]
it(data.it, function()
assert.is_true(#data.commands > 0, "You must assert that at least one command is run")
vimgrep_action(data.completion, data.action)
assert.is_equal(#vim.cmd.calls, #data.commands, "The `vim.cmd` function should be called once")
for j = 1, #data.commands do
assert.spy(vim.cmd).was_called_with(data.commands[j])
end
end)
end
end)