Skip to content

Commit

Permalink
tests: more gutter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed May 15, 2024
1 parent fcf5169 commit ed077c1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"diagnostics.globals": [
"describe",
"it",
"before_each",
]
}
3 changes: 3 additions & 0 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ local state = {
extmark = function()
return extmark
end,
gutter_group = function()
return gutter_group
end,
ns = function()
return ns
end,
Expand Down
72 changes: 71 additions & 1 deletion tests/precognition/e2e_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ local precognition = require("precognition")
---@diagnostic disable-next-line: undefined-field
local eq = assert.are.same

local function get_gutter_extmarks(buffer)
local gutter_extmarks = {}
for _, extmark in
pairs(vim.api.nvim_buf_get_extmarks(buffer, -1, 0, -1, {
details = true,
}))
do
if extmark[4] and extmark[4].sign_name and extmark[4].sign_name:match(precognition.gutter_group) then
table.insert(gutter_extmarks, extmark)
end
end
return gutter_extmarks
end

describe("e2e tests", function()
before_each(function()
precognition.setup({})
Expand All @@ -26,7 +40,13 @@ describe("e2e tests", function()
it("virtual line is displayed and updated", function()
local buffer = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buffer)
vim.api.nvim_buf_set_lines(buffer, 0, -1, false, { "Hello World this is a test", "line 2" })
vim.api.nvim_buf_set_lines(
buffer,
0,
-1,
false,
{ "Hello World this is a test", "line 2", "", "line 4", "", "line 6" }
)
vim.api.nvim_win_set_cursor(0, { 1, 1 })

precognition.on_cursor_moved()
Expand All @@ -35,6 +55,22 @@ describe("e2e tests", function()
details = true,
})

local gutter_extmarks = get_gutter_extmarks(buffer)

for _, extmark in pairs(gutter_extmarks) do
if extmark[4].sign_text == "G " then
eq(5, extmark[2])
elseif extmark[4].sign_text == "gg" then
eq(0, extmark[2])
elseif extmark[4].sign_text == "{ " then
eq(0, extmark[2])
elseif extmark[4].sign_text == "} " then
eq(2, extmark[2])
else
assert(false, "unexpected sign text")
end
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])

Expand Down Expand Up @@ -71,11 +107,45 @@ describe("e2e tests", function()
vim.api.nvim_win_set_cursor(0, { 2, 1 })
precognition.on_cursor_moved()

gutter_extmarks = get_gutter_extmarks(buffer)

extmarks = vim.api.nvim_buf_get_extmark_by_id(buffer, precognition.ns, precognition.extmark, {
details = true,
})

for _, extmark in pairs(gutter_extmarks) do
if extmark[4].sign_text == "G " then
eq(5, extmark[2])
elseif extmark[4].sign_text == "gg" then
eq(0, extmark[2])
elseif extmark[4].sign_text == "{ " then
eq(0, extmark[2])
elseif extmark[4].sign_text == "} " then
eq(2, extmark[2])
else
assert(false, "unexpected sign text")
end
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b e w", extmarks[3].virt_lines[1][1][1])

vim.api.nvim_win_set_cursor(0, { 4, 1 })
precognition.on_cursor_moved()
gutter_extmarks = get_gutter_extmarks(buffer)

for _, extmark in pairs(gutter_extmarks) do
if extmark[4].sign_text == "G " then
eq(5, extmark[2])
elseif extmark[4].sign_text == "gg" then
eq(0, extmark[2])
elseif extmark[4].sign_text == "{ " then
eq(2, extmark[2])
elseif extmark[4].sign_text == "} " then
eq(4, extmark[2])
else
assert(false, "unexpected sign text")
end
end
end)
end)

0 comments on commit ed077c1

Please sign in to comment.