2 files changed,
21 insertions(+),
0 deletions(-)
jump to
| M | after/ftplugin/go.lua |
| A | lua/scratch/gotest.lua |
M
after/ftplugin/go.lua
@@ -13,3 +13,5 @@
map("n", "<localleader>t", "<cmd>GoTestAdd<cr>", true) map("n", "<localleader>a", "<cmd>GoTestsAll<cr>", true) map("n", "<localleader>e", "<cmd>GoTestsExp<cr>", true) + +map("n", "<localleader>s", require("scratch.gotest").switch, true)
A
lua/scratch/gotest.lua
@@ -0,0 +1,19 @@
+local gotests = {} + +function gotests.switch() + local bufnr = vim.api.nvim_get_current_buf() + local fname_parts = vim.split(vim.api.nvim_buf_get_name(bufnr), "/") + local test_fname = fname_parts[#fname_parts] + if test_fname:find "_test.go" then + test_fname = test_fname:gsub("_test.go", ".go") + else + test_fname = test_fname:gsub(".go", "_test.go") + end + + table.remove(fname_parts, #fname_parts) + local path = table.concat(fname_parts, "/") .. "/" .. test_fname + + vim.cmd("edit " .. path) +end + +return gotests