parent
76e817b5e1
commit
f23cb97d1a
37 changed files with 188 additions and 472 deletions
14
spec/fixtures/tags/add_range_input.go
vendored
14
spec/fixtures/tags/add_range_input.go
vendored
|
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Name string
|
||||
Num int64
|
||||
Cost int
|
||||
Thingy []string
|
||||
Testing int
|
||||
Another struct {
|
||||
First int
|
||||
Second string
|
||||
}
|
||||
}
|
||||
14
spec/fixtures/tags/add_range_output.go
vendored
14
spec/fixtures/tags/add_range_output.go
vendored
|
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Name string `gopher:"name"`
|
||||
Num int64 `gopher:"num"`
|
||||
Cost int `gopher:"cost"`
|
||||
Thingy []string
|
||||
Testing int
|
||||
Another struct {
|
||||
First int
|
||||
Second string
|
||||
}
|
||||
}
|
||||
14
spec/fixtures/tags/remove_range_input.go
vendored
14
spec/fixtures/tags/remove_range_input.go
vendored
|
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `asdf:"id"`
|
||||
Name string `asdf:"name"`
|
||||
Num int64 `asdf:"num"`
|
||||
Cost int `asdf:"cost"`
|
||||
Thingy []string `asdf:"thingy"`
|
||||
Testing int `asdf:"testing"`
|
||||
Another struct {
|
||||
First int `asdf:"first"`
|
||||
Second string `asdf:"second"`
|
||||
} `asdf:"another"`
|
||||
}
|
||||
14
spec/fixtures/tags/remove_range_output.go
vendored
14
spec/fixtures/tags/remove_range_output.go
vendored
|
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `asdf:"id"`
|
||||
Name string `asdf:"name"`
|
||||
Num int64
|
||||
Cost int
|
||||
Thingy []string
|
||||
Testing int `asdf:"testing"`
|
||||
Another struct {
|
||||
First int `asdf:"first"`
|
||||
Second string `asdf:"second"`
|
||||
} `asdf:"another"`
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
local t = require "spec.testutils"
|
||||
local child, T, comment = t.setup "comment"
|
||||
local child, T = t.setup "comment"
|
||||
|
||||
local function do_the_test(fixture, pos)
|
||||
local rs = t.setup_test("comment/" .. fixture, child, pos)
|
||||
|
|
@ -10,27 +10,27 @@ local function do_the_test(fixture, pos)
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
comment["should add comment to package"] = function()
|
||||
T["comment"]["should add comment to package"] = function()
|
||||
do_the_test("package", { 1, 1 })
|
||||
end
|
||||
|
||||
comment["should add comment to struct"] = function()
|
||||
T["comment"]["should add comment to struct"] = function()
|
||||
do_the_test("struct", { 4, 1 })
|
||||
end
|
||||
|
||||
comment["should add comment to function"] = function()
|
||||
T["comment"]["should add comment to function"] = function()
|
||||
do_the_test("func", { 3, 1 })
|
||||
end
|
||||
|
||||
comment["should add comment to method"] = function()
|
||||
T["comment"]["should add comment to method"] = function()
|
||||
do_the_test("method", { 5, 1 })
|
||||
end
|
||||
|
||||
comment["should add comment to interface"] = function()
|
||||
T["comment"]["should add comment to interface"] = function()
|
||||
do_the_test("interface", { 3, 6 })
|
||||
end
|
||||
|
||||
comment["otherwise should add // above cursor"] = function()
|
||||
T["comment"]["otherwise should add // above cursor"] = function()
|
||||
do_the_test("empty", { 1, 1 })
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
local t = require "spec.testutils"
|
||||
local child, T, gotests = t.setup "gotests"
|
||||
local child, T = t.setup "gotests"
|
||||
|
||||
--- NOTE: :GoTestAdd is the only place that has actual logic
|
||||
--- All other parts are handled `gotests` itself.
|
||||
|
|
@ -10,7 +10,7 @@ local function read_testfile(fpath)
|
|||
return t.readfile(fpath:gsub(".go", "_test.go"))
|
||||
end
|
||||
|
||||
gotests["should add test for function under cursor"] = function()
|
||||
T["gotests"]["should add test for function under cursor"] = function()
|
||||
local rs = t.setup_test("tests/function", child, { 3, 5 })
|
||||
child.cmd "GoTestAdd"
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ gotests["should add test for function under cursor"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
gotests["should add test for method under cursor"] = function()
|
||||
T["gotests"]["should add test for method under cursor"] = function()
|
||||
local rs = t.setup_test("tests/method", child, { 5, 19 })
|
||||
child.cmd "GoTestAdd"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
local t = require "spec.testutils"
|
||||
local child, T, iferr = t.setup "iferr"
|
||||
local child, T = t.setup "iferr"
|
||||
|
||||
iferr["should add if != nil {"] = function()
|
||||
T["iferr"]["should add if != nil {"] = function()
|
||||
local rs = t.setup_test("iferr/iferr", child, { 8, 2 })
|
||||
child.cmd "GoIfErr"
|
||||
child.cmd "write"
|
||||
|
|
@ -10,7 +10,7 @@ iferr["should add if != nil {"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
iferr["should add if err with custom message"] = function()
|
||||
T["iferr"]["should add if err with custom message"] = function()
|
||||
child.lua [[
|
||||
require("gopher").setup {
|
||||
iferr = { message = 'fmt.Errorf("failed to %w", err)' }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
local t = require "spec.testutils"
|
||||
local child, T, impl = t.setup "impl"
|
||||
local child, T = t.setup "impl"
|
||||
|
||||
impl["should do impl with 'w io.Writer'"] = function()
|
||||
T["impl"]["should do impl with 'w io.Writer'"] = function()
|
||||
local rs = t.setup_test("impl/writer", child, { 3, 0 })
|
||||
child.cmd "GoImpl w io.Writer"
|
||||
child.cmd "write"
|
||||
|
|
@ -12,7 +12,7 @@ impl["should do impl with 'w io.Writer'"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
impl["should work with full input, 'r Read io.Reader'"] = function()
|
||||
T["impl"]["should work with full input, 'r Read io.Reader'"] = function()
|
||||
local rs = t.setup_test("impl/reader", child)
|
||||
child.cmd "GoImpl r Read io.Reader"
|
||||
child.cmd "write"
|
||||
|
|
@ -22,7 +22,7 @@ impl["should work with full input, 'r Read io.Reader'"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
impl["should work with minimal input 'io.Closer'"] = function()
|
||||
T["impl"]["should work with minimal input 'io.Closer'"] = function()
|
||||
local rs = t.setup_test("impl/closer", child, { 3, 6 })
|
||||
child.cmd "GoImpl io.Closer"
|
||||
child.cmd "write"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
local t = require "spec.testutils"
|
||||
local child, T, struct_tags = t.setup "struct_tags"
|
||||
local child, T = t.setup "struct_tags"
|
||||
|
||||
struct_tags["should add tag"] = function()
|
||||
T["struct_tags"]["should add tag"] = function()
|
||||
local rs = t.setup_test("tags/add", child, { 3, 6 })
|
||||
child.cmd "GoTagAdd json"
|
||||
child.cmd "write"
|
||||
|
|
@ -10,7 +10,7 @@ struct_tags["should add tag"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should remove tag"] = function()
|
||||
T["struct_tags"]["should remove tag"] = function()
|
||||
local rs = t.setup_test("tags/remove", child, { 4, 6 })
|
||||
child.cmd "GoTagRm json"
|
||||
child.cmd "write"
|
||||
|
|
@ -19,7 +19,7 @@ struct_tags["should remove tag"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should be able to handle many structs"] = function()
|
||||
T["struct_tags"]["should be able to handle many structs"] = function()
|
||||
local rs = t.setup_test("tags/many", child, { 10, 3 })
|
||||
child.cmd "GoTagAdd testing"
|
||||
child.cmd "write"
|
||||
|
|
@ -28,7 +28,7 @@ struct_tags["should be able to handle many structs"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should clear struct"] = function()
|
||||
T["struct_tags"]["should clear struct"] = function()
|
||||
local rs = t.setup_test("tags/clear", child, { 3, 1 })
|
||||
child.cmd "GoTagClear"
|
||||
child.cmd "write"
|
||||
|
|
@ -37,7 +37,7 @@ struct_tags["should clear struct"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should add more than one tag"] = function()
|
||||
T["struct_tags"]["should add more than one tag"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tags/add_many"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
|
@ -60,7 +60,7 @@ struct_tags["should add more than one tag"] = function()
|
|||
t.cleanup { tmp = tmp }
|
||||
end
|
||||
|
||||
struct_tags["should add tags on var"] = function()
|
||||
T["struct_tags"]["should add tags on var"] = function()
|
||||
local rs = t.setup_test("tags/var", child, { 5, 6 })
|
||||
child.cmd "GoTagAdd yaml"
|
||||
child.cmd "write"
|
||||
|
|
@ -69,7 +69,7 @@ struct_tags["should add tags on var"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should add tags on short declr var"] = function()
|
||||
T["struct_tags"]["should add tags on short declr var"] = function()
|
||||
local rs = t.setup_test("tags/svar", child, { 4, 3 })
|
||||
child.cmd "GoTagAdd xml"
|
||||
child.cmd "write"
|
||||
|
|
@ -78,22 +78,4 @@ struct_tags["should add tags on short declr var"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should add tag with range"] = function()
|
||||
local rs = t.setup_test("tags/add_range", child, { 5, 1 })
|
||||
child.cmd ".,+2GoTagAdd gopher"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should remove tag with range"] = function()
|
||||
local rs = t.setup_test("tags/remove_range", child, { 6, 1 })
|
||||
child.cmd ".,+2GoTagRm asdf"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ local testutils = {}
|
|||
testutils.mininit_path = vim.fs.joinpath(base_dir, "scripts", "minimal_init.lua")
|
||||
testutils.fixtures_dir = vim.fs.joinpath(base_dir, "spec/fixtures")
|
||||
|
||||
---@param mod string Module name for which to create a nested test set.
|
||||
---@return MiniTest.child child nvim client.
|
||||
---@return table T root test set created by `MiniTest.new_set()`.
|
||||
---@return table mod_name nested set of tests in `T[mod]`.
|
||||
function testutils.setup(mod)
|
||||
---@param name string
|
||||
---@return MiniTest.child, table
|
||||
function testutils.setup(name)
|
||||
local child = MiniTest.new_child_neovim()
|
||||
local T = MiniTest.new_set {
|
||||
hooks = {
|
||||
|
|
@ -21,8 +19,8 @@ function testutils.setup(mod)
|
|||
},
|
||||
}
|
||||
|
||||
T[mod] = MiniTest.new_set {}
|
||||
return child, T, T[mod]
|
||||
T[name] = MiniTest.new_set {}
|
||||
return child, T
|
||||
end
|
||||
|
||||
---@generic T
|
||||
|
|
@ -78,8 +76,6 @@ end
|
|||
---@param pos? number[]
|
||||
---@return gopher.TestUtilsSetup
|
||||
function testutils.setup_test(fixture, child, pos)
|
||||
vim.validate("pos", pos, "table", true)
|
||||
|
||||
local tmp = testutils.tmpfile()
|
||||
local fixtures = testutils.get_fixtures(fixture)
|
||||
|
||||
|
|
@ -88,8 +84,6 @@ function testutils.setup_test(fixture, child, pos)
|
|||
|
||||
local bufnr = child.fn.bufnr(tmp)
|
||||
if pos then
|
||||
assert(#pos == 2, "invalid cursor position")
|
||||
|
||||
child.fn.setpos(".", { bufnr, unpack(pos) })
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
local t = require "spec.testutils"
|
||||
local _, T, config = t.setup "config"
|
||||
|
||||
config["can be called without any arguments passed"] = function()
|
||||
---@diagnostic disable-next-line: missing-parameter
|
||||
require("gopher").setup()
|
||||
end
|
||||
|
||||
config["can be called with empty table"] = function()
|
||||
require("gopher").setup {}
|
||||
end
|
||||
|
||||
config["should change option"] = function()
|
||||
local log_level = 1234567890
|
||||
require("gopher").setup {
|
||||
log_level = log_level,
|
||||
}
|
||||
|
||||
t.eq(log_level, require("gopher.config").log_level)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
local t = require "spec.testutils"
|
||||
local _, T, utils = t.setup "utils"
|
||||
local _, T = t.setup "utils"
|
||||
|
||||
utils["should .remove_empty_lines()"] = function()
|
||||
T["utils"]["should .remove_empty_lines()"] = function()
|
||||
local u = require "gopher._utils"
|
||||
local inp = { "hi", "", "a", "", "", "asdf" }
|
||||
|
||||
t.eq(u.remove_empty_lines(inp), { "hi", "a", "asdf" })
|
||||
end
|
||||
|
||||
utils["should .readfile_joined()"] = function()
|
||||
T["utils"]["should .readfile_joined()"] = function()
|
||||
local data = "line1\nline2\nline3"
|
||||
local tmp = t.tmpfile()
|
||||
local u = require "gopher._utils"
|
||||
|
|
@ -17,7 +17,7 @@ utils["should .readfile_joined()"] = function()
|
|||
t.eq(u.readfile_joined(tmp), data)
|
||||
end
|
||||
|
||||
utils["should .trimend()"] = function()
|
||||
T["utils"]["should .trimend()"] = function()
|
||||
local u = require "gopher._utils"
|
||||
t.eq(u.trimend " hi ", " hi")
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue