add quick help within detail-float
This commit is contained in:
@@ -148,4 +148,98 @@ describe("test-samurai core (no bundled runners)", function()
|
||||
assert.equals(1, #last)
|
||||
assert.equals("TestA", last[1].text)
|
||||
end)
|
||||
|
||||
it("shows help with TSam commands and keymaps in the detail float", function()
|
||||
local runner = {
|
||||
name = "test-runner-help",
|
||||
}
|
||||
|
||||
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 = "TestA" }
|
||||
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 = {}, skips = {} }
|
||||
end
|
||||
|
||||
function runner.output_parser()
|
||||
return {
|
||||
on_line = function(_line, _state)
|
||||
return nil
|
||||
end,
|
||||
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 {}
|
||||
end
|
||||
|
||||
package.loaded["test-samurai-help-runner"] = runner
|
||||
test_samurai.setup({ runner_modules = { "test-samurai-help-runner" } })
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_help.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()
|
||||
|
||||
local listing_buf = vim.api.nvim_get_current_buf()
|
||||
local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
||||
local has_help = false
|
||||
for _, map in ipairs(maps) do
|
||||
if map.lhs == "?" then
|
||||
has_help = true
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_true(has_help)
|
||||
|
||||
core.show_help()
|
||||
|
||||
local detail_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(detail_buf, 0, -1, false)
|
||||
local joined = table.concat(lines, "\n")
|
||||
assert.is_true(joined:find("TSamNearest", 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>to", 1, true) ~= nil)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user