all repos

init.lua @ 2af7fad9840000aee7901802f82ca7b09d2a193d

my nvim config

init.lua/lua/scratch/gotest_switcher.lua(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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