test: add decoration provider, integration, and neogit spec files
Problem: regressions #119 and #120 exposed gaps in coverage of the decoration provider cache pipeline, the end-to-end highlight pipeline, and Neogit-specific behavior. Solution: add three spec files covering: - decoration_provider_spec: cache population, fingerprint guard, pending_clear semantics, BufWipeout cleanup via _test table - integration_spec: full buffer to attach to extmarks pipeline - neogit_integration_spec: neogit_disable_hunk_highlight and filetype attachment Closes #122
This commit is contained in:
parent
4e11858c6e
commit
e88f96b2be
3 changed files with 632 additions and 0 deletions
126
spec/neogit_integration_spec.lua
Normal file
126
spec/neogit_integration_spec.lua
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
require('spec.helpers')
|
||||
|
||||
vim.g.diffs = { neogit = true }
|
||||
|
||||
local diffs = require('diffs')
|
||||
local parser = require('diffs.parser')
|
||||
|
||||
local function create_buffer(lines)
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines or {})
|
||||
return bufnr
|
||||
end
|
||||
|
||||
local function delete_buffer(bufnr)
|
||||
if vim.api.nvim_buf_is_valid(bufnr) then
|
||||
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||
end
|
||||
end
|
||||
|
||||
describe('neogit_integration', function()
|
||||
describe('neogit_disable_hunk_highlight', function()
|
||||
it('sets neogit_disable_hunk_highlight on NeogitStatus buffer after attach', function()
|
||||
local bufnr = create_buffer({
|
||||
'modified test.lua',
|
||||
'@@ -1,1 +1,2 @@',
|
||||
' local x = 1',
|
||||
'+local y = 2',
|
||||
})
|
||||
vim.api.nvim_set_option_value('filetype', 'NeogitStatus', { buf = bufnr })
|
||||
diffs.attach(bufnr)
|
||||
|
||||
assert.is_true(vim.b[bufnr].neogit_disable_hunk_highlight)
|
||||
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('does not set neogit_disable_hunk_highlight on non-Neogit buffer', function()
|
||||
local bufnr = create_buffer({})
|
||||
vim.api.nvim_set_option_value('filetype', 'git', { buf = bufnr })
|
||||
diffs.attach(bufnr)
|
||||
|
||||
assert.is_not_true(vim.b[bufnr].neogit_disable_hunk_highlight)
|
||||
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('NeogitStatus buffer attach', function()
|
||||
it('populates hunk_cache for NeogitStatus buffer with diff content', function()
|
||||
local bufnr = create_buffer({
|
||||
'modified hello.lua',
|
||||
'@@ -1,2 +1,3 @@',
|
||||
' local M = {}',
|
||||
'+local x = 1',
|
||||
' return M',
|
||||
})
|
||||
vim.api.nvim_set_option_value('filetype', 'NeogitStatus', { buf = bufnr })
|
||||
diffs.attach(bufnr)
|
||||
local entry = diffs._test.hunk_cache[bufnr]
|
||||
assert.is_not_nil(entry)
|
||||
assert.is_table(entry.hunks)
|
||||
assert.are.equal(1, #entry.hunks)
|
||||
assert.are.equal('hello.lua', entry.hunks[1].filename)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('populates hunk_cache for NeogitDiffView buffer', function()
|
||||
local bufnr = create_buffer({
|
||||
'new file newmod.lua',
|
||||
'@@ -0,0 +1,2 @@',
|
||||
'+local M = {}',
|
||||
'+return M',
|
||||
})
|
||||
vim.api.nvim_set_option_value('filetype', 'NeogitDiffView', { buf = bufnr })
|
||||
diffs.attach(bufnr)
|
||||
local entry = diffs._test.hunk_cache[bufnr]
|
||||
assert.is_not_nil(entry)
|
||||
assert.is_table(entry.hunks)
|
||||
assert.are.equal(1, #entry.hunks)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('parser neogit patterns', function()
|
||||
it('detects renamed prefix via parser', function()
|
||||
local bufnr = create_buffer({
|
||||
'renamed old.lua',
|
||||
'@@ -1,2 +1,3 @@',
|
||||
' local M = {}',
|
||||
'+local x = 1',
|
||||
' return M',
|
||||
})
|
||||
local hunks = parser.parse_buffer(bufnr)
|
||||
assert.are.equal(1, #hunks)
|
||||
assert.are.equal('old.lua', hunks[1].filename)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('detects copied prefix via parser', function()
|
||||
local bufnr = create_buffer({
|
||||
'copied orig.lua',
|
||||
'@@ -1,2 +1,3 @@',
|
||||
' local M = {}',
|
||||
'+local x = 1',
|
||||
' return M',
|
||||
})
|
||||
local hunks = parser.parse_buffer(bufnr)
|
||||
assert.are.equal(1, #hunks)
|
||||
assert.are.equal('orig.lua', hunks[1].filename)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('detects deleted prefix via parser', function()
|
||||
local bufnr = create_buffer({
|
||||
'deleted gone.lua',
|
||||
'@@ -1,2 +0,0 @@',
|
||||
'-local M = {}',
|
||||
'-return M',
|
||||
})
|
||||
local hunks = parser.parse_buffer(bufnr)
|
||||
assert.are.equal(1, #hunks)
|
||||
assert.are.equal('gone.lua', hunks[1].filename)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue