tests(comment): fix
This commit is contained in:
parent
387021ce0a
commit
7495e29d4f
5 changed files with 33 additions and 19 deletions
|
|
@ -7,33 +7,39 @@ local ts = require "gopher._utils.ts"
|
||||||
local log = require "gopher._utils.log"
|
local log = require "gopher._utils.log"
|
||||||
local comment = {}
|
local comment = {}
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@return string
|
||||||
|
---@private
|
||||||
|
local function template(name)
|
||||||
|
return "// " .. (name or "") .. " "
|
||||||
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@return string
|
---@return string
|
||||||
---@private
|
---@private
|
||||||
local function generate(bufnr)
|
local function generate(bufnr)
|
||||||
local cmt = "// "
|
local sok, sres = pcall(ts.get_struct_under_cursor, bufnr)
|
||||||
|
vim.print(sok, sres)
|
||||||
local ok, res = pcall(ts.get_struct_under_cursor, bufnr)
|
if sok then
|
||||||
if ok then
|
return template(sres.name)
|
||||||
return cmt .. res.name .. " "
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ok, res = pcall(ts.get_func_under_cursor, bufnr)
|
local fok, fres = pcall(ts.get_func_under_cursor, bufnr)
|
||||||
if ok then
|
if fok then
|
||||||
return cmt .. res.name .. " "
|
return template(fres.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
ok, res = pcall(ts.get_interface_under_cursor, bufnr)
|
local iok, ires = pcall(ts.get_interface_under_cursor, bufnr)
|
||||||
if ok then
|
if iok then
|
||||||
return cmt .. res.name .. " "
|
return template(ires.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
ok, res = pcall(ts.get_package_under_cursor, bufnr)
|
local pok, pres = pcall(ts.get_package_under_cursor, bufnr)
|
||||||
if ok then
|
if pok then
|
||||||
return cmt .. "Package " .. res.name .. " provides "
|
return "// Package " .. pres.name .. " provides "
|
||||||
end
|
end
|
||||||
|
|
||||||
return cmt
|
return "// "
|
||||||
end
|
end
|
||||||
|
|
||||||
function comment.comment()
|
function comment.comment()
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ local function do_the_test(fixture, pos)
|
||||||
child.cmd "write"
|
child.cmd "write"
|
||||||
|
|
||||||
t.eq(t.readfile(tmp), fixtures.output)
|
t.eq(t.readfile(tmp), fixtures.output)
|
||||||
|
|
||||||
|
-- without it all other(not even from this module) tests are falling
|
||||||
|
t.deletefile(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
T["comment"] = MiniTest.new_set {}
|
T["comment"] = MiniTest.new_set {}
|
||||||
|
|
@ -37,11 +40,11 @@ T["comment"]["should add comment to function"] = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
T["comment"]["should add comment to method"] = function()
|
T["comment"]["should add comment to method"] = function()
|
||||||
do_the_test("func", { 5, 1 })
|
do_the_test("method", { 5, 1 })
|
||||||
end
|
end
|
||||||
|
|
||||||
T["comment"]["should add comment to interface"] = function()
|
T["comment"]["should add comment to interface"] = function()
|
||||||
do_the_test("interface", { 3, 1 })
|
do_the_test("interface", { 3, 6 })
|
||||||
end
|
end
|
||||||
|
|
||||||
T["comment"]["otherwise should add // above cursor"] = function()
|
T["comment"]["otherwise should add // above cursor"] = function()
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ function testutils.writefile(fpath, contents)
|
||||||
vim.fn.writefile(vim.split(contents, "\n"), fpath)
|
vim.fn.writefile(vim.split(contents, "\n"), fpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param fpath string
|
||||||
|
function testutils.deletefile(fpath)
|
||||||
|
vim.fn.delete(fpath)
|
||||||
|
end
|
||||||
|
|
||||||
---@param fixture string
|
---@param fixture string
|
||||||
---@return {input: string, output: string}
|
---@return {input: string, output: string}
|
||||||
function testutils.get_fixtures(fixture)
|
function testutils.get_fixtures(fixture)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue