refactor: some refactoring of tests (#102)
* feat(tests): add utils that does most of tests boilerplate * refactor(tests): rewrite using new thing * refactor(tests): clean up everywhere * refactor(tests): remove boilerplate even further * refactor(tests): soon it will be too far * refactor(tests): some test renaming
This commit is contained in:
parent
7ebe190c96
commit
3dcf708d34
6 changed files with 114 additions and 161 deletions
|
|
@ -1,55 +1,35 @@
|
|||
local t = require "spec.testutils"
|
||||
local child, T = t.setup "impl"
|
||||
|
||||
local child = MiniTest.new_child_neovim()
|
||||
local T = MiniTest.new_set {
|
||||
hooks = {
|
||||
post_once = child.stop,
|
||||
pre_case = function()
|
||||
child.restart { "-u", t.mininit_path }
|
||||
end,
|
||||
},
|
||||
}
|
||||
T["impl"] = MiniTest.new_set {}
|
||||
T["impl"]["works w io.Writer"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "impl/writer"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 0 })
|
||||
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"
|
||||
|
||||
-- NOTE: since "impl" won't implement interface if it's already implemented i went with this hack
|
||||
local rhs = fixtures.output:gsub("Test2", "Test")
|
||||
t.eq(t.readfile(tmp), rhs)
|
||||
local rhs = rs.fixtures.output:gsub("Test2", "Test")
|
||||
t.eq(t.readfile(rs.tmp), rhs)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
T["impl"]["works r Read io.Reader"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "impl/reader"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
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"
|
||||
|
||||
local rhs = fixtures.output:gsub("Read2", "Read")
|
||||
t.eq(t.readfile(tmp), rhs)
|
||||
local rhs = rs.fixtures.output:gsub("Read2", "Read")
|
||||
t.eq(t.readfile(rs.tmp), rhs)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
T["impl"]["works io.Closer"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "impl/closer"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 6 })
|
||||
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"
|
||||
|
||||
local rhs = fixtures.output:gsub("Test2", "Test")
|
||||
t.eq(t.readfile(tmp), rhs)
|
||||
local rhs = rs.fixtures.output:gsub("Test2", "Test")
|
||||
t.eq(t.readfile(rs.tmp), rhs)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue