refactor(tests): rewrite using new thing

This commit is contained in:
Oleksandr Smirnov 2025-03-22 20:04:30 +02:00
parent c4c302ed48
commit 1cb507fa40
No known key found for this signature in database
5 changed files with 36 additions and 101 deletions

View file

@ -11,45 +11,31 @@ local T = MiniTest.new_set {
}
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 })
local rs = t.setup("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)
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)
local rs = t.setup("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)
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 })
local rs = t.setup("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)
end
return T