feat: some more tests, a checkpoint

This commit is contained in:
Barrett Ruth 2025-09-19 12:36:04 -04:00
parent 5ca6b8b272
commit 56c52124ec
5 changed files with 170 additions and 2 deletions

View file

@ -13,7 +13,7 @@ local function get_status_info(test_case)
elseif test_case.status == 'fail' then
if test_case.timed_out then
return { text = 'TLE', highlight_group = 'CpTestError' }
elseif test_case.code and test_case.code ~= 0 then
elseif test_case.code and test_case.code >= 128 then
return { text = 'RTE', highlight_group = 'CpTestError' }
else
return { text = 'WA', highlight_group = 'CpTestError' }

View file

@ -66,13 +66,70 @@ describe('cp.config', function()
it('validates hook functions', function()
local invalid_config = {
hooks = { before_run = 'not_a_function' },
hooks = { before_test = 'not_a_function' },
}
assert.has_error(function()
config.setup(invalid_config)
end)
end)
describe('test_panel config validation', function()
it('validates diff_mode values', function()
local invalid_config = {
test_panel = { diff_mode = 'invalid' },
}
assert.has_error(function()
config.setup(invalid_config)
end)
end)
it('validates toggle_key is non-empty string', function()
local invalid_config = {
test_panel = { toggle_key = '' },
}
assert.has_error(function()
config.setup(invalid_config)
end)
end)
it('validates next_test_key is non-empty string', function()
local invalid_config = {
test_panel = { next_test_key = nil },
}
assert.has_error(function()
config.setup(invalid_config)
end)
end)
it('validates prev_test_key is non-empty string', function()
local invalid_config = {
test_panel = { prev_test_key = '' },
}
assert.has_error(function()
config.setup(invalid_config)
end)
end)
it('accepts valid test_panel config', function()
local valid_config = {
test_panel = {
diff_mode = 'git',
toggle_key = 'x',
next_test_key = 'j',
prev_test_key = 'k',
},
}
assert.has_no.errors(function()
config.setup(valid_config)
end)
end)
end)
end)
describe('default_filename', function()

42
spec/diff_spec.lua Normal file
View file

@ -0,0 +1,42 @@
describe('cp.diff', function()
local diff = require('cp.diff')
describe('get_available_backends', function()
it('returns vim and git backends')
end)
describe('get_backend', function()
it('returns vim backend by name')
it('returns git backend by name')
it('returns nil for invalid name')
end)
describe('is_git_available', function()
it('returns true when git command succeeds')
it('returns false when git command fails')
end)
describe('get_best_backend', function()
it('returns preferred backend when available')
it('falls back to vim when git unavailable')
it('defaults to vim backend')
end)
describe('vim backend', function()
it('returns content as-is')
it('returns nil highlights')
end)
describe('git backend', function()
it('creates temp files for diff')
it('returns raw diff output')
it('cleans up temp files')
it('handles no differences')
it('handles git command failure')
end)
describe('render_diff', function()
it('uses best available backend')
it('passes parameters to backend')
end)
end)

39
spec/highlight_spec.lua Normal file
View file

@ -0,0 +1,39 @@
describe('cp.highlight', function()
local highlight = require('cp.highlight')
describe('parse_diff_line', function()
it('parses added text markers {+text+}')
it('removes removed text markers [-text-]')
it('handles mixed add/remove markers')
it('calculates correct highlight positions')
it('handles text without markers')
it('handles empty text')
end)
describe('parse_git_diff', function()
it('skips git diff headers')
it('processes added lines')
it('ignores removed lines')
it('handles unchanged lines')
it('sets correct line numbers')
it('handles empty diff output')
end)
describe('apply_highlights', function()
it('clears existing highlights')
it('applies extmarks with correct positions')
it('uses correct highlight groups')
it('handles empty highlights')
end)
describe('create_namespace', function()
it('creates unique namespace')
end)
describe('parse_and_apply_diff', function()
it('parses diff and applies to buffer')
it('sets buffer content')
it('applies highlights')
it('returns content lines')
end)
end)

30
spec/test_render_spec.lua Normal file
View file

@ -0,0 +1,30 @@
describe('cp.test_render', function()
local test_render = require('cp.test_render')
describe('get_status_info', function()
it('returns AC for pass status')
it('returns WA for fail status with non-zero code')
it('returns TLE for timeout status')
it('returns RTE for fail with zero code')
it('returns empty for pending status')
end)
describe('render_test_list', function()
it('renders test cases with CP terminology')
it('shows current test with > prefix')
it('displays input only for current test')
it('handles empty test cases')
it('preserves input line breaks')
end)
describe('render_status_bar', function()
it('formats time and exit code')
it('handles missing time')
it('handles missing exit code')
it('returns empty for nil test case')
end)
describe('setup_highlights', function()
it('sets up all highlight groups')
end)
end)