Compares current buffer against any git revision (default HEAD), opens result in vsplit with full diffs.nvim syntax highlighting.
37 lines
1.2 KiB
Lua
37 lines
1.2 KiB
Lua
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)
|