test: add decoration provider, integration, and neogit spec files (#134)
## Problem Regressions #119 and #120 showed the test suite had no coverage of the decoration provider cache pipeline, no end-to-end pipeline tests from buffer content to extmarks, and no Neogit-specific integration tests. ## Solution Adds three new spec files (28 new tests, 316 total): - `spec/decoration_provider_spec.lua` — indirect cache pipeline tests via `_test` table: `ensure_cache` population, content fingerprint guard, `pending_clear` semantics, BufWipeout cleanup - `spec/integration_spec.lua` — full pipeline: diff buffer → `attach` → extmarks; verifies `DiffsAdd`/`DiffsDelete` on correct lines, treesitter captures, multi-hunk coverage - `spec/neogit_integration_spec.lua` — `neogit_disable_hunk_highlight` behavior, NeogitStatus/NeogitDiffView attach and cache population, parser neogit filename patterns Depends on #133. Closes #122
This commit is contained in:
parent
2feb8a86ed
commit
d797833341
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