From c4c302ed485e81e63d8d51665d57e76d23b77d3a Mon Sep 17 00:00:00 2001 From: Oleksandr Smirnov Date: Sat, 22 Mar 2025 20:04:08 +0200 Subject: [PATCH] feat(tests): add utils that does most of tests boilerplate --- spec/testutils.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/testutils.lua b/spec/testutils.lua index 32c19ab..d690e9f 100644 --- a/spec/testutils.lua +++ b/spec/testutils.lua @@ -45,4 +45,29 @@ function testutils.get_fixtures(fixture) } 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