test: add blend_alpha and prefix extmark coverage
This commit is contained in:
parent
23391556fd
commit
ba51e7a556
3 changed files with 113 additions and 7 deletions
|
|
@ -241,11 +241,13 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
||||||
Only visible if line numbers are enabled.
|
Only visible if line numbers are enabled.
|
||||||
|
|
||||||
{blend_alpha} (number, default: 0.6)
|
{blend_alpha} (number, default: 0.6)
|
||||||
Alpha value for character-level blend intensity.
|
Alpha value for diff line background intensity.
|
||||||
Controls how strongly changed characters stand
|
Controls how strongly diff lines (adds/deletes)
|
||||||
out from the line-level background. Must be
|
stand out from the editor background. Intra-line
|
||||||
between 0 and 1 (inclusive). Higher values
|
highlights use alpha + 0.3 (capped at 1.0) for
|
||||||
produce more vivid character-level highlights.
|
extra contrast. Must be between 0 and 1
|
||||||
|
(inclusive). Higher values produce more vivid
|
||||||
|
backgrounds.
|
||||||
|
|
||||||
{context} (table, default: see below)
|
{context} (table, default: see below)
|
||||||
Syntax parsing context options.
|
Syntax parsing context options.
|
||||||
|
|
|
||||||
|
|
@ -511,6 +511,83 @@ describe('highlight', function()
|
||||||
delete_buffer(bufnr)
|
delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('applies DiffsAddNr prefix extmark on + line for pw=1', function()
|
||||||
|
local bufnr = create_buffer({
|
||||||
|
'@@ -1,2 +1,2 @@',
|
||||||
|
'-old',
|
||||||
|
'+new',
|
||||||
|
})
|
||||||
|
|
||||||
|
local hunk = {
|
||||||
|
filename = 'test.lua',
|
||||||
|
lang = 'lua',
|
||||||
|
start_line = 1,
|
||||||
|
lines = { '-old', '+new' },
|
||||||
|
prefix_width = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
highlight.highlight_hunk(
|
||||||
|
bufnr,
|
||||||
|
ns,
|
||||||
|
hunk,
|
||||||
|
default_opts({ highlights = { background = true, treesitter = { enabled = false } } })
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local add_prefix = false
|
||||||
|
local del_prefix = false
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
local d = mark[4]
|
||||||
|
if d and d.end_col == 1 and mark[3] == 0 then
|
||||||
|
if d.hl_group == 'DiffsAddNr' and mark[2] == 2 then
|
||||||
|
add_prefix = true
|
||||||
|
end
|
||||||
|
if d.hl_group == 'DiffsDeleteNr' and mark[2] == 1 then
|
||||||
|
del_prefix = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(add_prefix, 'DiffsAddNr on + prefix')
|
||||||
|
assert.is_true(del_prefix, 'DiffsDeleteNr on - prefix')
|
||||||
|
delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('does not apply prefix extmark on context line', function()
|
||||||
|
local bufnr = create_buffer({
|
||||||
|
'@@ -1,2 +1,2 @@',
|
||||||
|
' ctx',
|
||||||
|
'+new',
|
||||||
|
})
|
||||||
|
|
||||||
|
local hunk = {
|
||||||
|
filename = 'test.lua',
|
||||||
|
lang = 'lua',
|
||||||
|
start_line = 1,
|
||||||
|
lines = { ' ctx', '+new' },
|
||||||
|
prefix_width = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
highlight.highlight_hunk(
|
||||||
|
bufnr,
|
||||||
|
ns,
|
||||||
|
hunk,
|
||||||
|
default_opts({ highlights = { background = true, treesitter = { enabled = false } } })
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local ctx_prefix = false
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
local d = mark[4]
|
||||||
|
if d and mark[2] == 1 and mark[3] == 0 and d.end_col == 1 then
|
||||||
|
if d.hl_group == 'DiffsAddNr' or d.hl_group == 'DiffsDeleteNr' then
|
||||||
|
ctx_prefix = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_false(ctx_prefix, 'no prefix extmark on context line')
|
||||||
|
delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
it('applies vim syntax extmarks when vim.enabled and no TS parser', function()
|
it('applies vim syntax extmarks when vim.enabled and no TS parser', function()
|
||||||
local orig_synID = vim.fn.synID
|
local orig_synID = vim.fn.synID
|
||||||
local orig_synIDtrans = vim.fn.synIDtrans
|
local orig_synIDtrans = vim.fn.synIDtrans
|
||||||
|
|
|
||||||
|
|
@ -554,7 +554,7 @@ describe('diffs', function()
|
||||||
diffs._test.set_hl_retry_pending(false)
|
diffs._test.set_hl_retry_pending(false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('omits DiffsClear.bg when Normal.bg is nil (transparent)', function()
|
it('uses dark fallback bg for DiffsClear when Normal.bg is nil (transparent)', function()
|
||||||
vim.api.nvim_get_hl = function(ns, opts)
|
vim.api.nvim_get_hl = function(ns, opts)
|
||||||
if opts.name == 'Normal' then
|
if opts.name == 'Normal' then
|
||||||
return { fg = 0xc0c0c0 }
|
return { fg = 0xc0c0c0 }
|
||||||
|
|
@ -562,11 +562,38 @@ describe('diffs', function()
|
||||||
return saved_get_hl(ns, opts)
|
return saved_get_hl(ns, opts)
|
||||||
end
|
end
|
||||||
diffs._test.compute_highlight_groups()
|
diffs._test.compute_highlight_groups()
|
||||||
assert.is_nil(set_calls.DiffsClear.bg)
|
assert.are.equal(0x1a1a1a, set_calls.DiffsClear.bg)
|
||||||
assert.is_table(set_calls.DiffsAdd)
|
assert.is_table(set_calls.DiffsAdd)
|
||||||
assert.is_table(set_calls.DiffsDelete)
|
assert.is_table(set_calls.DiffsDelete)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('blend_alpha controls DiffsAdd.bg intensity', function()
|
||||||
|
local saved_config_alpha = diffs._test.get_config().highlights.blend_alpha
|
||||||
|
diffs._test.get_config().highlights.blend_alpha = 0.3
|
||||||
|
vim.api.nvim_get_hl = function(ns, opts)
|
||||||
|
if opts.name == 'Normal' then
|
||||||
|
return { fg = 0xc0c0c0, bg = 0x1e1e2e }
|
||||||
|
end
|
||||||
|
if opts.name == 'DiffAdd' then
|
||||||
|
return { bg = 0x1a3a1a }
|
||||||
|
end
|
||||||
|
if opts.name == 'DiffDelete' then
|
||||||
|
return { bg = 0x3a1a1a }
|
||||||
|
end
|
||||||
|
return saved_get_hl(ns, opts)
|
||||||
|
end
|
||||||
|
diffs._test.compute_highlight_groups()
|
||||||
|
local bg_03 = set_calls.DiffsAdd.bg
|
||||||
|
|
||||||
|
diffs._test.get_config().highlights.blend_alpha = 0.9
|
||||||
|
diffs._test.compute_highlight_groups()
|
||||||
|
local bg_09 = set_calls.DiffsAdd.bg
|
||||||
|
|
||||||
|
assert.is_not.equal(bg_03, bg_09)
|
||||||
|
|
||||||
|
diffs._test.get_config().highlights.blend_alpha = saved_config_alpha
|
||||||
|
end)
|
||||||
|
|
||||||
it('retries once then stops when Normal.bg stays nil', function()
|
it('retries once then stops when Normal.bg stays nil', function()
|
||||||
vim.api.nvim_get_hl = function(ns, opts)
|
vim.api.nvim_get_hl = function(ns, opts)
|
||||||
if opts.name == 'Normal' then
|
if opts.name == 'Normal' then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue