all repos

gopher.nvim @ 9bf72afc63a9d2061299e9defa6c45d726dfb3be

Minimalistic plugin for Go development

gopher.nvim/spec/integration/gotests_test.lua(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local t = require "spec.testutils"
local child, T, gotests = t.setup "gotests"

--- NOTE: :GoTestAdd is the only place that has actual logic
--- All other parts are handled `gotests` itself.

---@param fpath string
---@return string
local function read_testfile(fpath)
  return t.readfile(fpath:gsub(".go", "_test.go"))
end

gotests["should add test for function under cursor"] = function()
  local rs = t.setup_test("tests/function", child, { 3, 5 })
  child.cmd "GoTestAdd"

  t.eq(rs.fixtures.output, read_testfile(rs.tmp))
  t.cleanup(rs)
end

gotests["should add test for method under cursor"] = function()
  local rs = t.setup_test("tests/method", child, { 5, 19 })
  child.cmd "GoTestAdd"

  t.eq(rs.fixtures.output, read_testfile(rs.tmp))
  t.cleanup(rs)
end

return T