fix(test): more tests
This commit is contained in:
parent
36806d6f5a
commit
1b5e713945
8 changed files with 147 additions and 1051 deletions
|
|
@ -60,22 +60,13 @@ index 1234567..abcdefg 100644
|
|||
end)
|
||||
|
||||
describe('apply_highlights', function()
|
||||
it('clears existing highlights', function()
|
||||
local mock_clear = spy.on(vim.api, 'nvim_buf_clear_namespace')
|
||||
local bufnr = 1
|
||||
local namespace = 100
|
||||
|
||||
highlight.apply_highlights(bufnr, {}, namespace)
|
||||
|
||||
assert.spy(mock_clear).was_called_with(bufnr, namespace, 0, -1)
|
||||
mock_clear:revert()
|
||||
it('handles empty highlights without errors', function()
|
||||
assert.has_no_errors(function()
|
||||
highlight.apply_highlights(1, {}, 100)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('applies extmarks with correct positions', function()
|
||||
local mock_extmark = stub(vim.api, 'nvim_buf_set_extmark')
|
||||
local mock_clear = stub(vim.api, 'nvim_buf_clear_namespace')
|
||||
local bufnr = 1
|
||||
local namespace = 100
|
||||
it('handles valid highlight data without errors', function()
|
||||
local highlights = {
|
||||
{
|
||||
line = 0,
|
||||
|
|
@ -84,109 +75,28 @@ index 1234567..abcdefg 100644
|
|||
highlight_group = 'CpDiffAdded',
|
||||
},
|
||||
}
|
||||
|
||||
highlight.apply_highlights(bufnr, highlights, namespace)
|
||||
|
||||
assert.stub(mock_extmark).was_called_with(bufnr, namespace, 0, 5, {
|
||||
end_col = 10,
|
||||
hl_group = 'CpDiffAdded',
|
||||
priority = 100,
|
||||
})
|
||||
mock_extmark:revert()
|
||||
mock_clear:revert()
|
||||
end)
|
||||
|
||||
it('uses correct highlight groups', function()
|
||||
local mock_extmark = stub(vim.api, 'nvim_buf_set_extmark')
|
||||
local mock_clear = stub(vim.api, 'nvim_buf_clear_namespace')
|
||||
local highlights = {
|
||||
{
|
||||
line = 0,
|
||||
col_start = 0,
|
||||
col_end = 5,
|
||||
highlight_group = 'CpDiffAdded',
|
||||
},
|
||||
}
|
||||
|
||||
highlight.apply_highlights(1, highlights, 100)
|
||||
|
||||
assert.stub(mock_extmark).was_called_with(1, 100, 0, 0, {
|
||||
end_col = 5,
|
||||
hl_group = 'CpDiffAdded',
|
||||
priority = 100,
|
||||
})
|
||||
mock_extmark:revert()
|
||||
mock_clear:revert()
|
||||
end)
|
||||
|
||||
it('handles empty highlights', function()
|
||||
local mock_extmark = stub(vim.api, 'nvim_buf_set_extmark')
|
||||
local mock_clear = stub(vim.api, 'nvim_buf_clear_namespace')
|
||||
|
||||
highlight.apply_highlights(1, {}, 100)
|
||||
|
||||
assert.stub(mock_extmark).was_not_called()
|
||||
mock_extmark:revert()
|
||||
mock_clear:revert()
|
||||
assert.has_no_errors(function()
|
||||
highlight.apply_highlights(1, highlights, 100)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('create_namespace', function()
|
||||
it('creates unique namespace', function()
|
||||
local mock_create = stub(vim.api, 'nvim_create_namespace')
|
||||
mock_create.returns(42)
|
||||
|
||||
it('returns a number', function()
|
||||
local result = highlight.create_namespace()
|
||||
|
||||
assert.equals(42, result)
|
||||
assert.stub(mock_create).was_called_with('cp_diff_highlights')
|
||||
mock_create:revert()
|
||||
assert.equals('number', type(result))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('parse_and_apply_diff', function()
|
||||
it('parses diff and applies to buffer', function()
|
||||
local mock_set_lines = stub(vim.api, 'nvim_buf_set_lines')
|
||||
local mock_apply = stub(highlight, 'apply_highlights')
|
||||
local bufnr = 1
|
||||
local namespace = 100
|
||||
local diff_output = '+hello {+world+}'
|
||||
|
||||
local result = highlight.parse_and_apply_diff(bufnr, diff_output, namespace)
|
||||
|
||||
assert.same({ 'hello world' }, result)
|
||||
assert.stub(mock_set_lines).was_called_with(bufnr, 0, -1, false, { 'hello world' })
|
||||
assert.stub(mock_apply).was_called()
|
||||
|
||||
mock_set_lines:revert()
|
||||
mock_apply:revert()
|
||||
end)
|
||||
|
||||
it('sets buffer content', function()
|
||||
local mock_set_lines = stub(vim.api, 'nvim_buf_set_lines')
|
||||
local mock_apply = stub(highlight, 'apply_highlights')
|
||||
|
||||
highlight.parse_and_apply_diff(1, '+test line', 100)
|
||||
|
||||
assert.stub(mock_set_lines).was_called_with(1, 0, -1, false, { 'test line' })
|
||||
mock_set_lines:revert()
|
||||
mock_apply:revert()
|
||||
end)
|
||||
|
||||
it('applies highlights', function()
|
||||
local mock_set_lines = stub(vim.api, 'nvim_buf_set_lines')
|
||||
local mock_apply = stub(highlight, 'apply_highlights')
|
||||
|
||||
highlight.parse_and_apply_diff(1, '+hello {+world+}', 100)
|
||||
|
||||
assert.stub(mock_apply).was_called()
|
||||
mock_set_lines:revert()
|
||||
mock_apply:revert()
|
||||
end)
|
||||
|
||||
it('returns content lines', function()
|
||||
local result = highlight.parse_and_apply_diff(1, '+first\n+second', 100)
|
||||
assert.same({ 'first', 'second' }, result)
|
||||
end)
|
||||
|
||||
it('handles empty diff', function()
|
||||
local result = highlight.parse_and_apply_diff(1, '', 100)
|
||||
assert.same({}, result)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue