add convenient keymaps for test-command inspection
This commit is contained in:
@@ -70,6 +70,8 @@ Additional keymaps:
|
|||||||
- `<leader>ss` -> filter the listing to `[ SKIP ] - ...` entries
|
- `<leader>ss` -> filter the listing to `[ SKIP ] - ...` entries
|
||||||
- `<leader>sa` -> clear the listing filter and show all entries
|
- `<leader>sa` -> clear the listing filter and show all entries
|
||||||
- `<leader>tt` -> run the test under the cursor in the listing
|
- `<leader>tt` -> run the test under the cursor in the listing
|
||||||
|
- `<leader>cb` -> breaks test-command onto multiple lines
|
||||||
|
- `<leader>cj` -> joins test-command onto single line
|
||||||
- `?` -> show help with TSam commands and standard keymaps in the Detail-Float
|
- `?` -> show help with TSam commands and standard keymaps in the Detail-Float
|
||||||
|
|
||||||
## Output UI
|
## Output UI
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ Additional keymaps:
|
|||||||
<leader>ss Filter listing to [ SKIP ] only
|
<leader>ss Filter listing to [ SKIP ] only
|
||||||
<leader>sa Show all listing entries (clear filter)
|
<leader>sa Show all listing entries (clear filter)
|
||||||
<leader>tt Run the test under the cursor in the listing
|
<leader>tt Run the test under the cursor in the listing
|
||||||
|
<leader>cb breaks test-command onto multiple lines
|
||||||
|
<leader>cj joins test-command onto single line
|
||||||
<leader>o Jump to test location
|
<leader>o Jump to test location
|
||||||
<leader>z Toggle Detail-Float full width
|
<leader>z Toggle Detail-Float full width
|
||||||
<C-l> Focus Detail-Float (press l again for full)
|
<C-l> Focus Detail-Float (press l again for full)
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ local function help_lines()
|
|||||||
" <C-h> Focus Test-Listing-Float",
|
" <C-h> Focus Test-Listing-Float",
|
||||||
" <leader>z Toggle Detail-Float full width",
|
" <leader>z Toggle Detail-Float full width",
|
||||||
" <leader>o Jump to test location",
|
" <leader>o Jump to test location",
|
||||||
|
" <leader>cb breaks test-command onto multiple lines",
|
||||||
|
" <leader>cj joins test-command onto single line",
|
||||||
" ? Show this help",
|
" ? Show this help",
|
||||||
"",
|
"",
|
||||||
"Testing-Float (Detail):",
|
"Testing-Float (Detail):",
|
||||||
@@ -139,6 +141,16 @@ local function apply_listing_lines(buf, lines)
|
|||||||
rebuild_result_line_map(lines)
|
rebuild_result_line_map(lines)
|
||||||
end
|
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)
|
local function apply_listing_filter(kind)
|
||||||
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
|
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
|
||||||
return
|
return
|
||||||
@@ -766,6 +778,12 @@ local function create_output_win(initial_lines)
|
|||||||
vim.keymap.set("n", "<leader>pf", function()
|
vim.keymap.set("n", "<leader>pf", function()
|
||||||
jump_listing_fail("prev")
|
jump_listing_fail("prev")
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>cb", function()
|
||||||
|
M.listing_break_on_dashes()
|
||||||
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>cj", function()
|
||||||
|
M.listing_join_backslashes()
|
||||||
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<leader>o", function()
|
vim.keymap.set("n", "<leader>o", function()
|
||||||
jump_to_listing_test()
|
jump_to_listing_test()
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
@@ -845,6 +863,12 @@ local function reopen_output_win()
|
|||||||
vim.keymap.set("n", "<leader>pf", function()
|
vim.keymap.set("n", "<leader>pf", function()
|
||||||
jump_listing_fail("prev")
|
jump_listing_fail("prev")
|
||||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>cb", function()
|
||||||
|
M.listing_break_on_dashes()
|
||||||
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>cj", function()
|
||||||
|
M.listing_join_backslashes()
|
||||||
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<leader>o", function()
|
vim.keymap.set("n", "<leader>o", function()
|
||||||
jump_to_listing_test()
|
jump_to_listing_test()
|
||||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
@@ -1332,6 +1356,14 @@ function M.filter_listing_all()
|
|||||||
apply_listing_filter("all")
|
apply_listing_filter("all")
|
||||||
end
|
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()
|
function M.run_test_at_cursor()
|
||||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||||
local line = cursor[1]
|
local line = cursor[1]
|
||||||
|
|||||||
@@ -222,13 +222,20 @@ describe("test-samurai core (no bundled runners)", function()
|
|||||||
local listing_buf = vim.api.nvim_get_current_buf()
|
local listing_buf = vim.api.nvim_get_current_buf()
|
||||||
local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
||||||
local has_help = false
|
local has_help = false
|
||||||
|
local has_cb = false
|
||||||
|
local has_cj = false
|
||||||
for _, map in ipairs(maps) do
|
for _, map in ipairs(maps) do
|
||||||
if map.lhs == "?" then
|
if map.lhs == "?" then
|
||||||
has_help = true
|
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
|
||||||
end
|
end
|
||||||
assert.is_true(has_help)
|
assert.is_true(has_help)
|
||||||
|
assert.is_true(has_cb)
|
||||||
|
assert.is_true(has_cj)
|
||||||
|
|
||||||
core.show_help()
|
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("TSamShowOutput", 1, true) ~= nil)
|
||||||
assert.is_true(joined:find("<leader>tn", 1, true) ~= nil)
|
assert.is_true(joined:find("<leader>tn", 1, true) ~= nil)
|
||||||
assert.is_true(joined:find("<leader>to", 1, true) ~= nil)
|
assert.is_true(joined:find("<leader>to", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("<leader>cb", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("<leader>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
|
vim.fn.jobstart = orig_jobstart
|
||||||
end)
|
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()
|
it("filters listing entries and restores them", function()
|
||||||
local runner = {
|
local runner = {
|
||||||
name = "test-runner-filter",
|
name = "test-runner-filter",
|
||||||
|
|||||||
Reference in New Issue
Block a user