mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 10:00:29 +00:00
fix: broken unit tests
This commit is contained in:
parent
a539f664fd
commit
23fb0002cf
@ -8,7 +8,7 @@ local HARPOON_MENU = "__harpoon-menu__"
|
|||||||
-- simple reason here is that if we are deving harpoon, we will create several
|
-- 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
|
-- 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
|
-- 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()
|
local function get_harpoon_menu_name()
|
||||||
harpoon_menu_id = harpoon_menu_id + 1
|
harpoon_menu_id = harpoon_menu_id + 1
|
||||||
|
@ -57,7 +57,7 @@ function M.get_default_config()
|
|||||||
return {
|
return {
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
save_on_toggle = true,
|
save_on_toggle = false,
|
||||||
jump_to_file_location = true,
|
jump_to_file_location = true,
|
||||||
key = function()
|
key = function()
|
||||||
return vim.loop.cwd()
|
return vim.loop.cwd()
|
||||||
|
@ -40,6 +40,7 @@ describe("harpoon", function()
|
|||||||
table.remove(created_files, 2)
|
table.remove(created_files, 2)
|
||||||
Buffer.set_contents(harpoon.ui.bufnr, created_files)
|
Buffer.set_contents(harpoon.ui.bufnr, created_files)
|
||||||
harpoon.ui:save()
|
harpoon.ui:save()
|
||||||
|
harpoon.ui:toggle_quick_menu()
|
||||||
|
|
||||||
eq(harpoon:list():length(), 2)
|
eq(harpoon:list():length(), 2)
|
||||||
eq(harpoon:list():display(), created_files)
|
eq(harpoon:list():display(), created_files)
|
||||||
@ -55,6 +56,7 @@ describe("harpoon", function()
|
|||||||
harpoon.ui:toggle_quick_menu(list)
|
harpoon.ui:toggle_quick_menu(list)
|
||||||
Buffer.set_contents(harpoon.ui.bufnr, created_files)
|
Buffer.set_contents(harpoon.ui.bufnr, created_files)
|
||||||
harpoon.ui:save()
|
harpoon.ui:save()
|
||||||
|
harpoon.ui:toggle_quick_menu()
|
||||||
|
|
||||||
eq(list:length(), 4)
|
eq(list:length(), 4)
|
||||||
eq(list:display(), created_files)
|
eq(list:display(), created_files)
|
||||||
@ -91,4 +93,18 @@ describe("harpoon", function()
|
|||||||
eq(harpoon.ui.bufnr, nil)
|
eq(harpoon.ui.bufnr, nil)
|
||||||
eq(harpoon.ui.win_id, nil)
|
eq(harpoon.ui.win_id, nil)
|
||||||
end)
|
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)
|
end)
|
||||||
|
@ -4,6 +4,22 @@ local M = {}
|
|||||||
|
|
||||||
M.created_files = {}
|
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
|
---@param name string
|
||||||
function M.before_each(name)
|
function M.before_each(name)
|
||||||
return function()
|
return function()
|
||||||
@ -15,7 +31,7 @@ function M.before_each(name)
|
|||||||
Data.set_data_path(name)
|
Data.set_data_path(name)
|
||||||
local harpoon = require("harpoon")
|
local harpoon = require("harpoon")
|
||||||
|
|
||||||
M.clean_files()
|
M.return_to_checkpoint()
|
||||||
|
|
||||||
harpoon:setup({
|
harpoon:setup({
|
||||||
settings = {
|
settings = {
|
||||||
@ -39,6 +55,7 @@ end
|
|||||||
---@param contents string[]
|
---@param contents string[]
|
||||||
function M.create_file(name, contents, row, col)
|
function M.create_file(name, contents, row, col)
|
||||||
local bufnr = vim.fn.bufnr(name, true)
|
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_set_current_buf(bufnr)
|
||||||
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, contents)
|
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, contents)
|
||||||
if row then
|
if row then
|
||||||
@ -54,7 +71,7 @@ end
|
|||||||
function M.fill_list_with_files(count, list)
|
function M.fill_list_with_files(count, list)
|
||||||
local files = {}
|
local files = {}
|
||||||
|
|
||||||
for _ = 1, count do
|
for i = 1, count do
|
||||||
local name = os.tmpname()
|
local name = os.tmpname()
|
||||||
table.insert(files, name)
|
table.insert(files, name)
|
||||||
M.create_file(name, { "test" })
|
M.create_file(name, { "test" })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user