expand opening keymap on detail-float
All checks were successful
tests / test (push) Successful in 8s
All checks were successful
tests / test (push) Successful in 8s
This commit is contained in:
@@ -1358,4 +1358,115 @@ describe("test-samurai core (no bundled runners)", function()
|
||||
local detail_lines = vim.api.nvim_buf_get_lines(refreshed_buf, 0, -1, false)
|
||||
assert.same({ "", "No output captured" }, detail_lines)
|
||||
end)
|
||||
|
||||
it("allows <leader>o from the detail float to jump to the test location", function()
|
||||
local runner = {
|
||||
name = "test-runner-detail-o",
|
||||
}
|
||||
|
||||
function runner.is_test_file(_bufnr)
|
||||
return true
|
||||
end
|
||||
|
||||
function runner.find_nearest(bufnr, _row, _col)
|
||||
return { file = vim.api.nvim_buf_get_name(bufnr), cwd = vim.loop.cwd(), test_name = "TestJump" }
|
||||
end
|
||||
|
||||
function runner.build_command(spec)
|
||||
return { cmd = { "echo", "nearest" }, cwd = spec.cwd }
|
||||
end
|
||||
|
||||
function runner.build_file_command(_bufnr)
|
||||
return { cmd = { "echo", "file" } }
|
||||
end
|
||||
|
||||
function runner.build_all_command(_bufnr)
|
||||
return { cmd = { "echo", "all" } }
|
||||
end
|
||||
|
||||
function runner.build_failed_command(last_command, _failures, _scope_kind)
|
||||
return { cmd = { "echo", "failed" }, cwd = last_command and last_command.cwd or nil }
|
||||
end
|
||||
|
||||
function runner.parse_results(_output)
|
||||
return { passes = {}, failures = { "TestJump" }, skips = {} }
|
||||
end
|
||||
|
||||
function runner.output_parser()
|
||||
return {
|
||||
on_complete = function(output, _state)
|
||||
return runner.parse_results(output)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function runner.parse_test_output(_output)
|
||||
return {}
|
||||
end
|
||||
|
||||
function runner.collect_failed_locations(_failures, _command, _scope_kind)
|
||||
return { { filename = "/tmp/test_jump_detail.go", lnum = 2, col = 3 } }
|
||||
end
|
||||
|
||||
package.loaded["test-samurai-detail-o-runner"] = runner
|
||||
test_samurai.setup({ runner_modules = { "test-samurai-detail-o-runner" } })
|
||||
|
||||
local target_buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(target_buf, "/tmp/test_jump_detail.go")
|
||||
vim.api.nvim_buf_set_lines(target_buf, 0, -1, false, { "line1", "line2", "line3" })
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_runner_detail_o.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts.on_exit then
|
||||
opts.on_exit(nil, 0, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
core.run_nearest()
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
|
||||
local listing_buf = vim.api.nvim_get_current_buf()
|
||||
assert.is_true(vim.bo[listing_buf].filetype == "test-samurai-output")
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
local fail_entry = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
fail_entry = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_true(fail_entry ~= nil)
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { fail_entry, 0 })
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local detail_buf = vim.api.nvim_get_current_buf()
|
||||
local maps = vim.api.nvim_buf_get_keymap(detail_buf, "n")
|
||||
local found = nil
|
||||
for _, map in ipairs(maps) do
|
||||
if type(map.lhs) == "string" and map.lhs:sub(-1) == "o" then
|
||||
found = map
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_true(found ~= nil)
|
||||
|
||||
assert.is_true(type(found.callback) == "function")
|
||||
found.callback()
|
||||
|
||||
local current = vim.api.nvim_get_current_buf()
|
||||
local name = vim.api.nvim_buf_get_name(current)
|
||||
assert.is_true(name:sub(-#"/tmp/test_jump_detail.go") == "/tmp/test_jump_detail.go")
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
assert.equals(2, cursor[1])
|
||||
assert.equals(2, cursor[2])
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user