chore: apply formatting
This commit is contained in:
+55
-47
@@ -29,9 +29,11 @@ end
|
||||
local function sign_marks(buf)
|
||||
local ns = vim.api.nvim_get_namespaces()["ow.git.hunks"]
|
||||
local out = {}
|
||||
for _, m in ipairs(vim.api.nvim_buf_get_extmarks(buf, ns, 0, -1, {
|
||||
details = true,
|
||||
})) do
|
||||
for _, m in
|
||||
ipairs(vim.api.nvim_buf_get_extmarks(buf, ns, 0, -1, {
|
||||
details = true,
|
||||
}))
|
||||
do
|
||||
local d = assert(m[4])
|
||||
table.insert(out, {
|
||||
row = m[2],
|
||||
@@ -167,7 +169,10 @@ t.test("overlay: change hunk shows deletion and addition", function()
|
||||
t.eq(add_d.line_hl_group, "GitHunkAddLine")
|
||||
virt_d = assert(virt_d, "the deletion should render as virtual lines")
|
||||
local piece = assert(assert(assert(virt_d.virt_lines)[1])[1])
|
||||
t.truthy(vim.startswith(piece[1], "b"), "deleted line shows the old content")
|
||||
t.truthy(
|
||||
vim.startswith(piece[1], "b"),
|
||||
"deleted line shows the old content"
|
||||
)
|
||||
t.eq(piece[2], "GitHunkDeleteLine")
|
||||
end)
|
||||
|
||||
@@ -197,11 +202,8 @@ t.test("overlay: add hunk highlights the added lines", function()
|
||||
end)
|
||||
|
||||
t.test("overlay: deleted lines are treesitter-highlighted", function()
|
||||
local _, buf = setup(
|
||||
"-- a note\nlocal x = 1\nlocal y = 2\n",
|
||||
"local y = 2\n",
|
||||
"a.lua"
|
||||
)
|
||||
local _, buf =
|
||||
setup("-- a note\nlocal x = 1\nlocal y = 2\n", "local y = 2\n", "a.lua")
|
||||
t.truthy(
|
||||
pcall(vim.treesitter.start, buf, "lua"),
|
||||
"the lua parser should be available"
|
||||
@@ -437,22 +439,25 @@ t.test("toggle_stage unstages one of two adjacent staged hunks", function()
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("toggle_stage refreshes the gutter when status stays modified", function()
|
||||
local _, buf = setup("a\nb\nc\nd\ne\n", "A\nb\nC\nd\nE\n")
|
||||
t.eq(#assert(hunks.state(buf)).hunks, 3)
|
||||
t.test(
|
||||
"toggle_stage refreshes the gutter when status stays modified",
|
||||
function()
|
||||
local _, buf = setup("a\nb\nc\nd\ne\n", "A\nb\nC\nd\nE\n")
|
||||
t.eq(#assert(hunks.state(buf)).hunks, 3)
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 2
|
||||
end, "gutter to drop the first staged hunk")
|
||||
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 2
|
||||
end, "gutter to drop the first staged hunk")
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "gutter to drop the middle staged hunk")
|
||||
end)
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "gutter to drop the middle staged hunk")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("staged hunks show with the staged highlight", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
@@ -499,32 +504,35 @@ t.test("toggle_stage toggles a staged hunk back to unstaged", function()
|
||||
})
|
||||
end)
|
||||
|
||||
t.test("toggle_stage unstages correctly when buffer lines are shifted", function()
|
||||
local dir, buf = setup("a\nb\nc\n", "a\nb\nC\n")
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 1
|
||||
end, "the line-3 change to be staged")
|
||||
t.test(
|
||||
"toggle_stage unstages correctly when buffer lines are shifted",
|
||||
function()
|
||||
local dir, buf = setup("a\nb\nc\n", "a\nb\nC\n")
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 1
|
||||
end, "the line-3 change to be staged")
|
||||
|
||||
vim.api.nvim_buf_set_lines(buf, 0, 0, false, { "NEW" })
|
||||
vim.api.nvim_exec_autocmds("TextChanged", { buffer = buf })
|
||||
hunks._flush(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "the unstaged add at the top to register")
|
||||
vim.api.nvim_buf_set_lines(buf, 0, 0, false, { "NEW" })
|
||||
vim.api.nvim_exec_autocmds("TextChanged", { buffer = buf })
|
||||
hunks._flush(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "the unstaged add at the top to register")
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { 4, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 0
|
||||
end, "the shifted staged hunk to be unstaged")
|
||||
t.eq(
|
||||
h.git(dir, "show", ":0:a.txt").stdout,
|
||||
"a\nb\nc",
|
||||
"the index reverts to HEAD content for the unstaged hunk"
|
||||
)
|
||||
end)
|
||||
vim.api.nvim_win_set_cursor(0, { 4, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 0
|
||||
end, "the shifted staged hunk to be unstaged")
|
||||
t.eq(
|
||||
h.git(dir, "show", ":0:a.txt").stdout,
|
||||
"a\nb\nc",
|
||||
"the index reverts to HEAD content for the unstaged hunk"
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
t.test("reset_hunk restores the index content for a change", function()
|
||||
local _, buf, state = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
|
||||
Reference in New Issue
Block a user