feat: add :Gdiff command for unified diff against git revision
Compares current buffer against any git revision (default HEAD), opens result in vsplit with full diffs.nvim syntax highlighting.
This commit is contained in:
parent
2ce76e7683
commit
bf2c91f79f
5 changed files with 271 additions and 0 deletions
37
spec/commands_spec.lua
Normal file
37
spec/commands_spec.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
require('spec.helpers')
|
||||
|
||||
describe('commands', function()
|
||||
describe('setup', function()
|
||||
it('registers Gdiff command', function()
|
||||
require('diffs.commands').setup()
|
||||
local commands = vim.api.nvim_get_commands({})
|
||||
assert.is_not_nil(commands.Gdiff)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('unified diff generation', function()
|
||||
local old_lines = { 'local M = {}', 'return M' }
|
||||
local new_lines = { 'local M = {}', 'local x = 1', 'return M' }
|
||||
|
||||
it('generates valid unified diff', function()
|
||||
local old_content = table.concat(old_lines, '\n')
|
||||
local new_content = table.concat(new_lines, '\n')
|
||||
local diff_output = vim.diff(old_content, new_content, {
|
||||
result_type = 'unified',
|
||||
ctxlen = 3,
|
||||
})
|
||||
assert.is_not_nil(diff_output)
|
||||
assert.is_true(diff_output:find('@@ ') ~= nil)
|
||||
assert.is_true(diff_output:find('+local x = 1') ~= nil)
|
||||
end)
|
||||
|
||||
it('returns empty for identical content', function()
|
||||
local content = table.concat(old_lines, '\n')
|
||||
local diff_output = vim.diff(content, content, {
|
||||
result_type = 'unified',
|
||||
ctxlen = 3,
|
||||
})
|
||||
assert.are.equal('', diff_output)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue