fix: broken unit tests

This commit is contained in:
Michael Paulson 2023-12-01 13:44:59 -07:00
parent a539f664fd
commit 23fb0002cf
4 changed files with 37 additions and 4 deletions

View File

@ -8,7 +8,7 @@ local HARPOON_MENU = "__harpoon-menu__"
-- simple reason here is that if we are deving harpoon, we will create several
-- ui objects, each with their own buffer, which will cause the name to be
-- duplicated and then we will get a vim error on nvim_buf_set_name
local harpoon_menu_id = 0
local harpoon_menu_id = math.random(1000000)
local function get_harpoon_menu_name()
harpoon_menu_id = harpoon_menu_id + 1

View File

@ -57,7 +57,7 @@ function M.get_default_config()
return {
settings = {
save_on_toggle = true,
save_on_toggle = false,
jump_to_file_location = true,
key = function()
return vim.loop.cwd()

View File

@ -40,6 +40,7 @@ describe("harpoon", function()
table.remove(created_files, 2)
Buffer.set_contents(harpoon.ui.bufnr, created_files)
harpoon.ui:save()
harpoon.ui:toggle_quick_menu()
eq(harpoon:list():length(), 2)
eq(harpoon:list():display(), created_files)
@ -55,6 +56,7 @@ describe("harpoon", function()
harpoon.ui:toggle_quick_menu(list)
Buffer.set_contents(harpoon.ui.bufnr, created_files)
harpoon.ui:save()
harpoon.ui:toggle_quick_menu()
eq(list:length(), 4)
eq(list:display(), created_files)
@ -91,4 +93,18 @@ describe("harpoon", function()
eq(harpoon.ui.bufnr, nil)
eq(harpoon.ui.win_id, nil)
end)
it("closing toggle_quick_menu with save_on_toggle should save contents", function()
harpoon:setup({ settings = { save_on_toggle = true }})
local list = harpoon:list()
local created_files = utils.fill_list_with_files(3, list)
harpoon.ui:toggle_quick_menu(list)
table.remove(created_files, 2)
Buffer.set_contents(harpoon.ui.bufnr, created_files)
harpoon.ui:toggle_quick_menu()
eq(list:length(), 2)
eq(list:display(), created_files)
end)
end)

View File

@ -4,6 +4,22 @@ local M = {}
M.created_files = {}
local checkpoint_file = nil
local checkpoint_file_bufnr = nil
function M.create_checkpoint_file()
checkpoint_file = os.tmpname()
checkpoint_file_bufnr = M.create_file(checkpoint_file, { "test" })
end
function M.return_to_checkpoint()
if checkpoint_file_bufnr == nil then
return
end
vim.api.nvim_set_current_buf(checkpoint_file_bufnr)
M.clean_files()
end
---@param name string
function M.before_each(name)
return function()
@ -15,7 +31,7 @@ function M.before_each(name)
Data.set_data_path(name)
local harpoon = require("harpoon")
M.clean_files()
M.return_to_checkpoint()
harpoon:setup({
settings = {
@ -39,6 +55,7 @@ end
---@param contents string[]
function M.create_file(name, contents, row, col)
local bufnr = vim.fn.bufnr(name, true)
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "hide")
vim.api.nvim_set_current_buf(bufnr)
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, contents)
if row then
@ -54,7 +71,7 @@ end
function M.fill_list_with_files(count, list)
local files = {}
for _ = 1, count do
for i = 1, count do
local name = os.tmpname()
table.insert(files, name)
M.create_file(name, { "test" })