+2
after/ftplugin/go.lua
+2
after/ftplugin/go.lua
+19
lua/scratch/gotest.lua
+19
lua/scratch/gotest.lua
···
1
+
local gotests = {}
2
+
3
+
function gotests.switch()
4
+
local bufnr = vim.api.nvim_get_current_buf()
5
+
local fname_parts = vim.split(vim.api.nvim_buf_get_name(bufnr), "/")
6
+
local test_fname = fname_parts[#fname_parts]
7
+
if test_fname:find "_test.go" then
8
+
test_fname = test_fname:gsub("_test.go", ".go")
9
+
else
10
+
test_fname = test_fname:gsub(".go", "_test.go")
11
+
end
12
+
13
+
table.remove(fname_parts, #fname_parts)
14
+
local path = table.concat(fname_parts, "/") .. "/" .. test_fname
15
+
16
+
vim.cmd("edit " .. path)
17
+
end
18
+
19
+
return gotests