From 56c52124ec9a1c1d564818d7e67b43ebc4b358ef Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 12:36:04 -0400 Subject: [PATCH] feat: some more tests, a checkpoint --- lua/cp/test_render.lua | 2 +- spec/config_spec.lua | 59 ++++++++++++++++++++++++++++++++++++++- spec/diff_spec.lua | 42 ++++++++++++++++++++++++++++ spec/highlight_spec.lua | 39 ++++++++++++++++++++++++++ spec/test_render_spec.lua | 30 ++++++++++++++++++++ 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 spec/diff_spec.lua create mode 100644 spec/highlight_spec.lua create mode 100644 spec/test_render_spec.lua diff --git a/lua/cp/test_render.lua b/lua/cp/test_render.lua index 9bf92c9..aa7acf1 100644 --- a/lua/cp/test_render.lua +++ b/lua/cp/test_render.lua @@ -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' } diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 3b94ddf..a429ae5 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -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() diff --git a/spec/diff_spec.lua b/spec/diff_spec.lua new file mode 100644 index 0000000..bdfda29 --- /dev/null +++ b/spec/diff_spec.lua @@ -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) diff --git a/spec/highlight_spec.lua b/spec/highlight_spec.lua new file mode 100644 index 0000000..5df7dd1 --- /dev/null +++ b/spec/highlight_spec.lua @@ -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) diff --git a/spec/test_render_spec.lua b/spec/test_render_spec.lua new file mode 100644 index 0000000..e1d5ea1 --- /dev/null +++ b/spec/test_render_spec.lua @@ -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)