feat(tests): add utils that does most of tests boilerplate
This commit is contained in:
parent
7e33602065
commit
c4c302ed48
1 changed files with 25 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue