fix(ci): format

This commit is contained in:
Barrett Ruth 2025-09-19 12:11:56 -04:00
parent d193fabfb9
commit ab9a0f43b5
5 changed files with 48 additions and 33 deletions

View file

@ -83,14 +83,14 @@ M.defaults = {
scrapers = constants.PLATFORMS,
filename = nil,
test_panel = {
diff_mode = "vim",
toggle_key = "t",
status_format = "compact",
diff_mode = 'vim',
toggle_key = 't',
status_format = 'compact',
},
diff = {
git = {
command = "git",
args = {"diff", "--no-index", "--word-diff=plain", "--word-diff-regex=.", "--no-prefix"},
command = 'git',
args = { 'diff', '--no-index', '--word-diff=plain', '--word-diff-regex=.', '--no-prefix' },
},
vim = {
enable_diffthis = true,
@ -142,7 +142,7 @@ function M.setup(user_config)
diff_mode = {
user_config.test_panel.diff_mode,
function(value)
return vim.tbl_contains({"vim", "git"}, value)
return vim.tbl_contains({ 'vim', 'git' }, value)
end,
"diff_mode must be 'vim' or 'git'",
},
@ -150,7 +150,7 @@ function M.setup(user_config)
status_format = {
user_config.test_panel.status_format,
function(value)
return vim.tbl_contains({"compact", "verbose"}, value)
return vim.tbl_contains({ 'compact', 'verbose' }, value)
end,
"status_format must be 'compact' or 'verbose'",
},

View file

@ -19,9 +19,9 @@ local vim_backend = {
return {
content = actual_lines,
highlights = nil -- diffthis handles highlighting
highlights = nil, -- diffthis handles highlighting
}
end
end,
}
---Git word-diff backend for character-level precision
@ -37,8 +37,14 @@ local git_backend = {
vim.fn.writefile(vim.split(actual, '\n', { plain = true }), tmp_actual)
local cmd = {
'git', 'diff', '--no-index', '--word-diff=plain', '--word-diff-regex=.',
'--no-prefix', tmp_expected, tmp_actual
'git',
'diff',
'--no-index',
'--word-diff=plain',
'--word-diff-regex=.',
'--no-prefix',
tmp_expected,
tmp_actual,
}
local result = vim.system(cmd, { text = true }):wait()
@ -50,17 +56,17 @@ local git_backend = {
if result.code == 0 then
return {
content = vim.split(actual, '\n', { plain = true, trimempty = true }),
highlights = {}
highlights = {},
}
else
local highlight_module = require('cp.highlight')
return {
content = {},
highlights = {},
raw_diff = result.stdout or ''
raw_diff = result.stdout or '',
}
end
end
end,
}
---Available diff backends
@ -86,7 +92,7 @@ end
---Check if git backend is available
---@return boolean
function M.is_git_available()
local result = vim.system({'git', '--version'}, { text = true }):wait()
local result = vim.system({ 'git', '--version' }, { text = true }):wait()
return result.code == 0
end
@ -115,4 +121,4 @@ function M.render_diff(expected, actual, backend_name, mode)
return backend.render(expected, actual, mode)
end
return M
return M

View file

@ -23,7 +23,7 @@ local function parse_diff_line(text)
local start_pos = text:find('%[%-' .. vim.pesc(removed_text) .. '%-%]', 1, false)
if start_pos then
-- Remove the marker and adjust positions
local marker_len = #('[-%-%]') + #removed_text
local marker_len = #'[-%-%]' + #removed_text
cleaned_text = cleaned_text:gsub('%[%-' .. vim.pesc(removed_text) .. '%-%]', '', 1)
-- Since we're removing text, we don't add highlights for removed content in the actual pane
@ -41,20 +41,20 @@ local function parse_diff_line(text)
local start_pos = final_text:find('{%+' .. vim.pesc(added_text) .. '%+}', 1, false)
if start_pos then
-- Calculate position after previous highlights
local highlight_start = start_pos - offset - 1 -- 0-based for extmarks
local highlight_start = start_pos - offset - 1 -- 0-based for extmarks
local highlight_end = highlight_start + #added_text
table.insert(final_highlights, {
line = 0, -- Will be set by caller
col_start = highlight_start,
col_end = highlight_end,
highlight_group = 'CpDiffAdded'
highlight_group = 'CpDiffAdded',
})
-- Remove the marker
local marker_len = #{'{+'} + #{'+}'} + #added_text
local marker_len = #{ '{+' } + #{ '+}' } + #added_text
final_text = final_text:gsub('{%+' .. vim.pesc(added_text) .. '%+}', added_text, 1)
offset = offset + #{'{+'} + #{'+}'}
offset = offset + #{ '{+' } + #{ '+}' }
end
end
@ -73,13 +73,16 @@ function M.parse_git_diff(diff_output)
local content_started = false
for _, line in ipairs(lines) do
-- Skip header lines (@@, +++, ---, index, etc.)
if content_started or (
not line:match('^@@') and
not line:match('^%+%+%+') and
not line:match('^%-%-%-') and
not line:match('^index') and
not line:match('^diff %-%-git')
) then
if
content_started
or (
not line:match('^@@')
and not line:match('^%+%+%+')
and not line:match('^%-%-%-')
and not line:match('^index')
and not line:match('^diff %-%-git')
)
then
content_started = true
-- Process content lines
@ -115,7 +118,7 @@ function M.parse_git_diff(diff_output)
return {
content = content_lines,
highlights = all_highlights
highlights = all_highlights,
}
end
@ -161,4 +164,4 @@ function M.parse_and_apply_diff(bufnr, diff_output, namespace)
return parsed.content
end
return M
return M

View file

@ -193,7 +193,7 @@ local function toggle_test_panel(is_debug)
-- Set buffer options
local buffer_opts = { 'bufhidden', 'wipe' }
for _, buf in ipairs({tab_buf, expected_buf, actual_buf}) do
for _, buf in ipairs({ tab_buf, expected_buf, actual_buf }) do
vim.api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf })
vim.api.nvim_set_option_value('readonly', true, { buf = buf })
vim.api.nvim_set_option_value('modifiable', false, { buf = buf })
@ -295,7 +295,11 @@ local function toggle_test_panel(is_debug)
if backend.name == 'git' then
local diff_result = backend.render(current_test.expected, current_test.actual)
if diff_result.raw_diff and diff_result.raw_diff ~= '' then
highlight.parse_and_apply_diff(test_buffers.actual_buf, diff_result.raw_diff, diff_namespace)
highlight.parse_and_apply_diff(
test_buffers.actual_buf,
diff_result.raw_diff,
diff_namespace
)
else
update_buffer_content(test_buffers.actual_buf, actual_lines)
end

View file

@ -49,7 +49,9 @@ function M.render_test_list(test_state, config)
table.insert(lines, line)
if is_current and test_case.input and test_case.input ~= '' then
for _, input_line in ipairs(vim.split(test_case.input, '\n', { plain = true, trimempty = false })) do
for _, input_line in
ipairs(vim.split(test_case.input, '\n', { plain = true, trimempty = false }))
do
table.insert(lines, ' ' .. input_line)
end
end