feat(tests): add utils that does most of tests boilerplate

This commit is contained in:
Oleksandr Smirnov 2025-03-22 20:04:08 +02:00
parent 7e33602065
commit c4c302ed48
No known key found for this signature in database

View file

@ -45,4 +45,29 @@ function testutils.get_fixtures(fixture)
} }
end end
---@param fixture string
---@param child MiniTest.child
---@param pos? number[]
---@return {tmp: string, fixtures: {input: string, output: string}}
function testutils.setup(fixture, child, pos)
local tmp = testutils.tmpfile()
local fixtures = testutils.get_fixtures(fixture)
testutils.writefile(tmp, fixtures.input)
child.cmd("silent edit " .. tmp)
if pos then
child.fn.setpos(".", { child.fn.bufnr(tmp), unpack(pos) })
end
return {
tmp = tmp,
fixtures = fixtures,
}
end
function testutils.cleanup(tmp)
testutils.deletefile(tmp)
end
return testutils return testutils