2 files changed,
23 insertions(+),
1 deletions(-)
Author:
Smirnov Oleksandr
ss2316544@gmail.com
Committed at:
2024-01-15 19:14:08 +0200
Parent:
ed0b5de
jump to
| M | after/ftplugin/go.lua |
| A | lua/scratch/gotest_switcher.lua |
M
after/ftplugin/go.lua
@@ -12,4 +12,6 @@ map("n", "<leader>;c", "<cmd>GoCmt<cr>")
map("n", "<leader>;g", "<cmd>GoGenerate %<cr>") map("n", "<leader>;o", "<cmd>GoTestAdd<cr>") map("n", "<leader>;a", "<cmd>GoTestsAll<cr>") -map("n", "<leader>;e", "<cmd>GoTestsExpr<cr>") +map("n", "<leader>;s", function() + require("scratch.gotest_switcher").switch() +end)
A
lua/scratch/gotest_switcher.lua
@@ -0,0 +1,20 @@
+local gotests = {} + +function gotests.switch() + local bufnr = vim.api.nvim_get_current_buf() + local fname = vim.api.nvim_buf_get_name(bufnr) + local fname_parts = vim.split(fname, "/") + 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