feat: good ass testing going on here

This commit is contained in:
mpaulson 2023-11-03 18:30:35 -06:00
parent 65d652dccd
commit ab45ad2982
2 changed files with 60 additions and 5 deletions

View File

@ -1,3 +1,4 @@
local utils = require("harpoon2.test.utils")
local Data = require("harpoon2.data") local Data = require("harpoon2.data")
local harpoon = require("harpoon2") local harpoon = require("harpoon2")
@ -18,16 +19,13 @@ describe("harpoon", function()
local file_name = "/tmp/harpoon-test" local file_name = "/tmp/harpoon-test"
local row = 3 local row = 3
local col = 1 local col = 1
local bufnr = vim.fn.bufnr(file_name, true)
local default_key = harpoon:info().default_key local default_key = harpoon:info().default_key
vim.api.nvim_set_current_buf(bufnr) local bufnr = utils.create_file(file_name, {
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, {
"foo", "foo",
"bar", "bar",
"baz", "baz",
"qux" "qux"
}) }, row, col)
vim.api.nvim_win_set_cursor(0, {row, col})
local list = harpoon:list():append() local list = harpoon:list():append()
harpoon:sync() harpoon:sync()
@ -36,6 +34,46 @@ describe("harpoon", function()
[default_key] = list:encode() [default_key] = list:encode()
}) })
end) end)
it("prepend/append double add", function()
local default_key = harpoon:info().default_key
local file_name_1 = "/tmp/harpoon-test"
local row_1 = 3
local col_1 = 1
local file_name_2 = "/tmp/harpoon-test-2"
local row_2 = 1
local col_2 = 2
local contents = { "foo", "bar", "baz", "qux" }
local bufnr_1 = utils.create_file(file_name_1, contents, row_1, col_1)
local list = harpoon:list():append()
utils.create_file(file_name_2, contents, row_2, col_2)
harpoon:list():prepend()
harpoon:sync()
eq(harpoon:dump(), {
[default_key] = list:encode()
})
eq(list.items, {
{value = file_name_2, context = {row = row_2, col = col_2}},
{value = file_name_1, context = {row = row_1, col = col_1}},
})
harpoon:list():append()
vim.api.nvim_set_current_buf(bufnr_1)
harpoon:list():prepend()
eq(list.items, {
{value = file_name_2, context = {row = row_2, col = col_2}},
{value = file_name_1, context = {row = row_1, col = col_1}},
})
end)
end) end)

View File

@ -0,0 +1,17 @@
local M = {}
---@param name string
---@param contents string[]
function M.create_file(name, contents, row, col)
local bufnr = vim.fn.bufnr(name, true)
vim.api.nvim_set_current_buf(bufnr)
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, contents)
if row then
vim.api.nvim_win_set_cursor(0, {row, col})
end
return bufnr
end
return M