gopher.nvim/spec/testutils.lua
Smirnov Oleksandr e9f2eef5e7
refactor: treesitter utils (#91)
* refactor(ts_utils): i dont know why event it was here

* fix: typos

* fix(struct_tags)!: remove statement that i used for debug

* refactor(ts_util): start from scratch

* refactor(struct_tags): use new ts_util

* fixup! refactor(struct_tags): use new ts_util

* test(struct_tags): add support for multiple structs

* fix(gotests): use new api

* fix(impl): refactor some logic, use new api

* docs(ts): add an explanation

* refactor(_utils.ts): all public methods are just adapters

* fix(comment): now it works

* fixup! refactor(_utils.ts): all public methods are just adapters

* fixup! fixup! refactor(_utils.ts): all public methods are just adapters

* test(comment): e2e

* tests(comment): fix

* refactor(utils.ts): fix, docs

* test(comment): fix tests again

* fix(tests/comments): well, now i fell stupid

* refactor(ts): add assert just to be sure that all elements are in the result

* fix(ts): type annotations

* fix(ts): pass bufnr to vim.treesitter.get_node

* chore(ci): disable nightly

* chore(ci): reorganize
2025-03-19 15:09:57 +02:00

48 lines
1.2 KiB
Lua

local base_dir = vim.env.GOPHER_DIR or vim.fn.expand "%:p:h"
---@class gopher.TestUtils
local testutils = {}
testutils.mininit_path = vim.fs.joinpath(base_dir, "scripts", "minimal_init.lua")
testutils.fixtures_dir = vim.fs.joinpath(base_dir, "spec/fixtures")
---@generic T
---@param a T
---@param b T
---@return boolean
function testutils.eq(a, b)
return MiniTest.expect.equality(a, b)
end
---@return string
function testutils.tmpfile()
return vim.fn.tempname() .. ".go"
end
---@param path string
---@return string
function testutils.readfile(path)
return vim.fn.join(vim.fn.readfile(path), "\n")
end
---@param fpath string
---@param contents string
function testutils.writefile(fpath, contents)
vim.fn.writefile(vim.split(contents, "\n"), fpath)
end
---@param fpath string
function testutils.deletefile(fpath)
vim.fn.delete(fpath)
end
---@param fixture string
---@return {input: string, output: string}
function testutils.get_fixtures(fixture)
return {
input = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_input.go"),
output = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_output.go"),
}
end
return testutils