From 118f84c31ec8b1fe0df097c9679feb340443a14f Mon Sep 17 00:00:00 2001 From: "M.Schirmer" Date: Thu, 8 Jan 2026 13:21:01 +0100 Subject: [PATCH] add convenient keymaps for test-command inspection --- README.md | 2 ++ doc/test-samurai.txt | 2 ++ lua/test-samurai/core.lua | 32 +++++++++++++++++++++++++ tests/test_samurai_core_spec.lua | 40 +++++++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f1738bc..13afa31 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ Additional keymaps: - `ss` -> filter the listing to `[ SKIP ] - ...` entries - `sa` -> clear the listing filter and show all entries - `tt` -> run the test under the cursor in the listing +- `cb` -> breaks test-command onto multiple lines +- `cj` -> joins test-command onto single line - `?` -> show help with TSam commands and standard keymaps in the Detail-Float ## Output UI diff --git a/doc/test-samurai.txt b/doc/test-samurai.txt index e39193e..aa61bef 100644 --- a/doc/test-samurai.txt +++ b/doc/test-samurai.txt @@ -58,6 +58,8 @@ Additional keymaps: ss Filter listing to [ SKIP ] only sa Show all listing entries (clear filter) tt Run the test under the cursor in the listing + cb breaks test-command onto multiple lines + cj joins test-command onto single line o Jump to test location z Toggle Detail-Float full width Focus Detail-Float (press l again for full) diff --git a/lua/test-samurai/core.lua b/lua/test-samurai/core.lua index b79a97d..15c67be 100644 --- a/lua/test-samurai/core.lua +++ b/lua/test-samurai/core.lua @@ -76,6 +76,8 @@ local function help_lines() " Focus Test-Listing-Float", " z Toggle Detail-Float full width", " o Jump to test location", + " cb breaks test-command onto multiple lines", + " cj joins test-command onto single line", " ? Show this help", "", "Testing-Float (Detail):", @@ -139,6 +141,16 @@ local function apply_listing_lines(buf, lines) rebuild_result_line_map(lines) end +local function apply_listing_substitution(command) + local buf = vim.api.nvim_get_current_buf() + if not (buf and vim.api.nvim_buf_is_valid(buf)) then + return + end + vim.api.nvim_buf_call(buf, function() + vim.cmd(command) + end) +end + local function apply_listing_filter(kind) if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then return @@ -766,6 +778,12 @@ local function create_output_win(initial_lines) vim.keymap.set("n", "pf", function() jump_listing_fail("prev") end, { buffer = buf, nowait = true, silent = true }) + vim.keymap.set("n", "cb", function() + M.listing_break_on_dashes() + end, { buffer = buf, nowait = true, silent = true }) + vim.keymap.set("n", "cj", function() + M.listing_join_backslashes() + end, { buffer = buf, nowait = true, silent = true }) vim.keymap.set("n", "o", function() jump_to_listing_test() end, { buffer = buf, nowait = true, silent = true }) @@ -845,6 +863,12 @@ local function reopen_output_win() vim.keymap.set("n", "pf", function() jump_listing_fail("prev") end, { buffer = state.last_buf, nowait = true, silent = true }) + vim.keymap.set("n", "cb", function() + M.listing_break_on_dashes() + end, { buffer = state.last_buf, nowait = true, silent = true }) + vim.keymap.set("n", "cj", function() + M.listing_join_backslashes() + end, { buffer = state.last_buf, nowait = true, silent = true }) vim.keymap.set("n", "o", function() jump_to_listing_test() end, { buffer = state.last_buf, nowait = true, silent = true }) @@ -1332,6 +1356,14 @@ function M.filter_listing_all() apply_listing_filter("all") end +function M.listing_break_on_dashes() + apply_listing_substitution([[%s/--/\\\r\t--/g]]) +end + +function M.listing_join_backslashes() + apply_listing_substitution([[%s/\\\n\t//g]]) +end + function M.run_test_at_cursor() local cursor = vim.api.nvim_win_get_cursor(0) local line = cursor[1] diff --git a/tests/test_samurai_core_spec.lua b/tests/test_samurai_core_spec.lua index 1509698..ff874e7 100644 --- a/tests/test_samurai_core_spec.lua +++ b/tests/test_samurai_core_spec.lua @@ -222,13 +222,20 @@ describe("test-samurai core (no bundled runners)", function() local listing_buf = vim.api.nvim_get_current_buf() local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n") local has_help = false + local has_cb = false + local has_cj = false for _, map in ipairs(maps) do if map.lhs == "?" then has_help = true - break + elseif map.lhs and map.lhs:sub(-2) == "cb" then + has_cb = true + elseif map.lhs and map.lhs:sub(-2) == "cj" then + has_cj = true end end assert.is_true(has_help) + assert.is_true(has_cb) + assert.is_true(has_cj) core.show_help() @@ -239,10 +246,41 @@ describe("test-samurai core (no bundled runners)", function() assert.is_true(joined:find("TSamShowOutput", 1, true) ~= nil) assert.is_true(joined:find("tn", 1, true) ~= nil) assert.is_true(joined:find("to", 1, true) ~= nil) + assert.is_true(joined:find("cb", 1, true) ~= nil) + assert.is_true(joined:find("cj", 1, true) ~= nil) + assert.is_true(joined:find("breaks test-command onto multiple lines", 1, true) ~= nil) + assert.is_true(joined:find("joins test-command onto single line", 1, true) ~= nil) vim.fn.jobstart = orig_jobstart end) + it("applies listing break/join substitutions", function() + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_set_current_buf(buf) + vim.api.nvim_buf_set_lines(buf, 0, -1, false, { + "alpha -- beta", + "gamma -- delta", + }) + + core.listing_break_on_dashes() + + local broken = vim.api.nvim_buf_get_lines(buf, 0, -1, false) + assert.same({ + "alpha \\", + "\t-- beta", + "gamma \\", + "\t-- delta", + }, broken) + + core.listing_join_backslashes() + + local joined = vim.api.nvim_buf_get_lines(buf, 0, -1, false) + assert.same({ + "alpha -- beta", + "gamma -- delta", + }, joined) + end) + it("filters listing entries and restores them", function() local runner = { name = "test-runner-filter",