initialize with first MVP

This commit is contained in:
2025-12-23 14:10:06 +01:00
commit 4de8921a42
14 changed files with 733 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
local go_runner = require("test-samurai.runners.go")
describe("test-samurai go runner", function()
it("detects Go test files by suffix", function()
local bufnr1 = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr1, "/tmp/foo_test.go")
assert.is_true(go_runner.is_test_file(bufnr1))
local bufnr2 = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr2, "/tmp/foo.go")
assert.is_false(go_runner.is_test_file(bufnr2))
end)
it("finds subtest when cursor is inside t.Run block", function()
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, "/tmp/foo_test.go")
local lines = {
"package main",
"import \"testing\"",
"",
"func TestFoo(t *testing.T) {",
" t.Run(\"first\", func(t *testing.T) {",
" -- inside first",
" })",
"",
" t.Run(\"second\", func(t *testing.T) {",
" -- inside second",
" })",
"}",
}
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
local orig_fs_find = vim.fs.find
vim.fs.find = function(markers, opts)
return { "/tmp/go.mod" }
end
local row_inside_first = 5
local spec, err = go_runner.find_nearest(bufnr, row_inside_first, 0)
vim.fs.find = orig_fs_find
assert.is_nil(err)
assert.is_not_nil(spec)
assert.equals("TestFoo/first", spec.test_path)
assert.equals("subtest", spec.scope)
assert.equals("/tmp/foo_test.go", spec.file)
assert.equals("/tmp", spec.cwd)
end)
it("falls back to whole test function when between subtests", function()
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, "/tmp/foo_test.go")
local lines = {
"package main",
"import \"testing\"",
"",
"func TestFoo(t *testing.T) {",
" t.Run(\"first\", func(t *testing.T) {",
" -- inside first",
" })",
"",
" t.Run(\"second\", func(t *testing.T) {",
" -- inside second",
" })",
"}",
}
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
local orig_fs_find = vim.fs.find
vim.fs.find = function(markers, opts)
return { "/tmp/go.mod" }
end
local row_between = 7
local spec, err = go_runner.find_nearest(bufnr, row_between, 0)
vim.fs.find = orig_fs_find
assert.is_nil(err)
assert.is_not_nil(spec)
assert.equals("TestFoo", spec.test_path)
assert.equals("function", spec.scope)
end)
end)