mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
feat: good ass testing going on here
This commit is contained in:
parent
65d652dccd
commit
ab45ad2982
@ -1,3 +1,4 @@
|
||||
local utils = require("harpoon2.test.utils")
|
||||
local Data = require("harpoon2.data")
|
||||
local harpoon = require("harpoon2")
|
||||
|
||||
@ -18,16 +19,13 @@ describe("harpoon", function()
|
||||
local file_name = "/tmp/harpoon-test"
|
||||
local row = 3
|
||||
local col = 1
|
||||
local bufnr = vim.fn.bufnr(file_name, true)
|
||||
local default_key = harpoon:info().default_key
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, {
|
||||
local bufnr = utils.create_file(file_name, {
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
"qux"
|
||||
})
|
||||
vim.api.nvim_win_set_cursor(0, {row, col})
|
||||
}, row, col)
|
||||
|
||||
local list = harpoon:list():append()
|
||||
harpoon:sync()
|
||||
@ -36,6 +34,46 @@ describe("harpoon", function()
|
||||
[default_key] = list:encode()
|
||||
})
|
||||
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)
|
||||
|
||||
|
||||
|
17
lua/harpoon2/test/utils.lua
Normal file
17
lua/harpoon2/test/utils.lua
Normal 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
|
Loading…
x
Reference in New Issue
Block a user