fix(ci): fix the tests

This commit is contained in:
Barrett Ruth 2025-09-19 18:46:00 -04:00
parent 7a850ab228
commit 2b9e55f077
3 changed files with 38 additions and 29 deletions

View file

@ -239,18 +239,12 @@ local function toggle_test_panel(is_debug)
vim.api.nvim_set_option_value('readonly', was_readonly, { buf = bufnr }) vim.api.nvim_set_option_value('readonly', was_readonly, { buf = bufnr })
vim.api.nvim_buf_clear_namespace(bufnr, test_list_namespace, 0, -1) vim.api.nvim_buf_clear_namespace(bufnr, test_list_namespace, 0, -1)
for _, highlight in ipairs(highlights) do for _, hl in ipairs(highlights) do
vim.api.nvim_buf_set_extmark( vim.api.nvim_buf_set_extmark(bufnr, test_list_namespace, hl.line, hl.col_start, {
bufnr, end_col = hl.col_end,
test_list_namespace, hl_group = hl.highlight_group,
highlight.line, priority = 100,
highlight.col_start, })
{
end_col = highlight.col_end,
hl_group = highlight.highlight_group,
priority = 100,
}
)
end end
end end

View file

@ -1 +1 @@
std = "vim" std = 'vim'

View file

@ -53,7 +53,7 @@ describe('cp.test_render', function()
end) end)
describe('render_test_list', function() describe('render_test_list', function()
it('renders test cases with CP terminology', function() it('renders table with headers and borders', function()
local test_state = { local test_state = {
test_cases = { test_cases = {
{ status = 'pass', input = '5' }, { status = 'pass', input = '5' },
@ -62,11 +62,12 @@ describe('cp.test_render', function()
current_index = 1, current_index = 1,
} }
local result = test_render.render_test_list(test_state) local result = test_render.render_test_list(test_state)
assert.equals('> 1. AC', result[1]) assert.is_true(result[1]:match('^┌'))
assert.equals(' 2. WA', result[3]) assert.is_true(result[2]:match('│.*#.*│.*Status.*│.*Time.*│.*Exit Code.*│'))
assert.is_true(result[3]:match('^├'))
end) end)
it('shows current test with > prefix', function() it('shows current test with > prefix in table', function()
local test_state = { local test_state = {
test_cases = { test_cases = {
{ status = 'pass', input = '' }, { status = 'pass', input = '' },
@ -75,8 +76,14 @@ describe('cp.test_render', function()
current_index = 2, current_index = 2,
} }
local result = test_render.render_test_list(test_state) local result = test_render.render_test_list(test_state)
assert.equals(' 1. AC', result[1]) local found_current = false
assert.equals('> 2. AC', result[2]) for _, line in ipairs(result) do
if line:match('│.*>2.*│') then
found_current = true
break
end
end
assert.is_true(found_current)
end) end)
it('displays input only for current test', function() it('displays input only for current test', function()
@ -88,15 +95,20 @@ describe('cp.test_render', function()
current_index = 1, current_index = 1,
} }
local result = test_render.render_test_list(test_state) local result = test_render.render_test_list(test_state)
assert.equals('> 1. AC', result[1]) local found_input = false
assert.equals(' 5 3', result[2]) for _, line in ipairs(result) do
assert.equals(' 2. AC', result[3]) if line:match('│5 3') then
found_input = true
break
end
end
assert.is_true(found_input)
end) end)
it('handles empty test cases', function() it('handles empty test cases', function()
local test_state = { test_cases = {}, current_index = 1 } local test_state = { test_cases = {}, current_index = 1 }
local result = test_render.render_test_list(test_state) local result = test_render.render_test_list(test_state)
assert.equals(0, #result) assert.equals(3, #result)
end) end)
it('preserves input line breaks', function() it('preserves input line breaks', function()
@ -107,10 +119,13 @@ describe('cp.test_render', function()
current_index = 1, current_index = 1,
} }
local result = test_render.render_test_list(test_state) local result = test_render.render_test_list(test_state)
assert.equals('> 1. AC', result[1]) local input_lines = {}
assert.equals(' 5', result[2]) for _, line in ipairs(result) do
assert.equals(' 3', result[3]) if line:match('^│[531]') then
assert.equals(' 1', result[4]) table.insert(input_lines, line:match('│([531])'))
end
end
assert.same({ '5', '3', '1' }, input_lines)
end) end)
end) end)
@ -118,7 +133,7 @@ describe('cp.test_render', function()
it('formats time and exit code', function() it('formats time and exit code', function()
local test_case = { time_ms = 45.7, code = 0 } local test_case = { time_ms = 45.7, code = 0 }
local result = test_render.render_status_bar(test_case) local result = test_render.render_status_bar(test_case)
assert.equals('46ms │ Exit: 0', result) assert.equals('45.70ms │ Exit: 0', result)
end) end)
it('handles missing time', function() it('handles missing time', function()
@ -130,7 +145,7 @@ describe('cp.test_render', function()
it('handles missing exit code', function() it('handles missing exit code', function()
local test_case = { time_ms = 123 } local test_case = { time_ms = 123 }
local result = test_render.render_status_bar(test_case) local result = test_render.render_status_bar(test_case)
assert.equals('123ms', result) assert.equals('123.00ms', result)
end) end)
it('returns empty for nil test case', function() it('returns empty for nil test case', function()