Skip to content

Commit

Permalink
tests: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Jun 1, 2024
1 parent 5068348 commit bd13fd9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 54 deletions.
62 changes: 62 additions & 0 deletions tests/precognition/e2e_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,65 @@ describe("e2e tests", function()
eq(customMark, vim.api.nvim_get_hl(0, { name = extmarks[3].virt_lines[1][1][2] }))
end)
end)

describe("Gutter Priority", function()
it("0 priority item is not added", function()
precognition.setup({
---@diagnostic disable-next-line: missing-fields
gutterHints = {
G = { text = "G", prio = 0 },
},
})

local testBuf = vim.api.nvim_create_buf(true, false)

vim.api.nvim_buf_set_lines(testBuf, 0, -1, false, {
"ABC",
"DEF",
"",
"GHI",
"",
"JKL",
"",
"MNO",
})
vim.api.nvim_set_current_buf(testBuf)
vim.api.nvim_win_set_cursor(0, { 4, 0 })

precognition.on_cursor_moved()

local gutter_extmarks = get_gutter_extmarks(testBuf)

for _, extmark in pairs(gutter_extmarks) do
eq(true, extmark[4].sign_text ~= "G ")
eq(true, extmark[4].sign_name ~= "precognition_gutter_G")
end
end)

it("higher priority item replaces", function()
precognition.setup({
---@diagnostic disable-next-line: missing-fields
gutterHints = {
G = { text = "G", prio = 3 },
gg = { text = "gg", prio = 100 },
NextParagraph = { text = "}", prio = 2 },
PrevParagraph = { text = "{", prio = 1 },
},
})

local testBuf = vim.api.nvim_create_buf(true, false)

vim.api.nvim_buf_set_lines(testBuf, 0, -1, false, {
"ABC",
})
vim.api.nvim_set_current_buf(testBuf)
vim.api.nvim_win_set_cursor(0, { 1, 0 })

precognition.on_cursor_moved()

local gutter_extmarks = get_gutter_extmarks(testBuf)

eq(1, vim.tbl_count(gutter_extmarks))
eq("gg", gutter_extmarks[1][4].sign_text)
end)
end)
54 changes: 0 additions & 54 deletions tests/precognition/gutter_hints_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,57 +155,3 @@ local function dump(o)
return tostring(o)
end
end

describe("Priority", function()
it("0 priority item is not added", function()
precognition.setup({
---@diagnostic disable-next-line: missing-fields
gutterHints = {
G = { text = "G", prio = 0 },
gg = { text = "gg", prio = 9 },
PrevParagraph = { text = "{", prio = 8 },
NextParagraph = { text = "}", prio = 8 },
},
})

local testBuf = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_name(testBuf, "foo")

vim.api.nvim_buf_set_lines(testBuf, 0, -1, false, {
"ABC",
"DEF",
"",
"GHI",
"",
"JKL",
"",
"MNO",
})

local hints = precognition.build_gutter_hints(testBuf)
precognition.apply_gutter_hints(hints, testBuf)

local def = vim.fn.sign_getdefined("precognition_gutter_PrevParagraph")
print("def")
print(dump(def))

local gutter_group = "precognition_gutter"
local buf_name = vim.fn.bufname(testBuf)
print("buf name " .. buf_name)
local placed = vim.fn.sign_getplaced("foo", { group = "*" })

print("placed")
print(dump(placed))
print(placed[1].signs[1])
for _, g in ipairs(placed[1].signs) do
print(g.name)
end
-- print("hints g is `" .. precognition.gutter_signs_cache["G"] .. "`")
-- eq({
-- ["gg"] = 1,
-- PrevParagraph = 3,
-- NextParagraph = 5,
-- ["G"] = 8,
-- }, hints)
end)
end)

0 comments on commit bd13fd9

Please sign in to comment.