50 lines
1.6 KiB
Lua
50 lines
1.6 KiB
Lua
local t = require("test")
|
|
local util = require("git.util")
|
|
|
|
local function fresh_buf()
|
|
local buf = vim.api.nvim_create_buf(false, true)
|
|
t.defer(function()
|
|
pcall(vim.api.nvim_buf_delete, buf, { force = true })
|
|
end)
|
|
return buf
|
|
end
|
|
|
|
t.test("set_buf_lines preserves modifiable=false", function()
|
|
local buf = fresh_buf()
|
|
vim.bo[buf].modifiable = false
|
|
util.set_buf_lines(buf, 0, -1, { "a", "b", "c" })
|
|
t.eq(
|
|
vim.api.nvim_buf_get_lines(buf, 0, -1, false),
|
|
{ "a", "b", "c" },
|
|
"lines should be replaced"
|
|
)
|
|
t.falsy(vim.bo[buf].modifiable, "modifiable should stay false")
|
|
t.falsy(vim.bo[buf].modified, "modified should be cleared")
|
|
end)
|
|
|
|
t.test("set_buf_lines preserves modifiable=true", function()
|
|
local buf = fresh_buf()
|
|
vim.bo[buf].modifiable = true
|
|
util.set_buf_lines(buf, 0, -1, { "a", "b" })
|
|
t.truthy(vim.bo[buf].modifiable, "modifiable should stay true")
|
|
t.falsy(vim.bo[buf].modified, "modified should be cleared")
|
|
end)
|
|
|
|
t.test("set_buf_lines partial range update", function()
|
|
local buf = fresh_buf()
|
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "a", "b", "c", "d" })
|
|
util.set_buf_lines(buf, 1, 3, { "X", "Y", "Z" })
|
|
t.eq(
|
|
vim.api.nvim_buf_get_lines(buf, 0, -1, false),
|
|
{ "a", "X", "Y", "Z", "d" },
|
|
"lines [1, 3) should be replaced"
|
|
)
|
|
end)
|
|
|
|
t.test("set_buf_lines errors on out-of-bounds (strict_indexing)", function()
|
|
local buf = fresh_buf()
|
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "a", "b" })
|
|
local ok = pcall(util.set_buf_lines, buf, 100, 200, { "x" })
|
|
t.falsy(ok, "out-of-bounds index should error")
|
|
end)
|