go.nvim/lua/tests/go_coverage_spec.lua

179 lines
6.1 KiB
Lua
Raw Normal View History

2021-08-25 15:42:17 +00:00
local eq = assert.are.same
local cur_dir = vim.fn.expand("%:p:h")
local busted = require("plenary/busted")
describe("should read coveragefile", function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
status = require("plenary.reload").reload_module("go.nvim")
it("should read coverage file", function()
--
local path = cur_dir .. "/lua/tests/fixtures/coverage/coverage.out" -- %:p:h ? %:p
print("test:" .. path)
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
require('go').setup({trace = true, log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log"})
local cover = require("go.coverage")
local result = cover.read_cov(path)
-- print(vim.inspect(result))
local n = "github.com/go.nvim/branch.go"
local range = {['end'] = {character = 13, line = 4}, start = {character = 27, line = 3}}
eq(result[n][1].file, "github.com/go.nvim/branch.go")
eq(result[n][1].range, range)
-- eq(result[n][1], "github.com/go.nvim/branch.go")
end)
it("should generate sign list", function()
--
local path = cur_dir .. "/lua/tests/fixtures/coverage/coverage.out" -- %:p:h ? %:p
print("test:" .. path)
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
require('go').setup({
trace = true,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
gocoverage_sign = '|'
})
local cover = require("go.coverage")
cover.highlight()
local coverage = {
{
cnt = 1,
file = "github.com/go.nvim/branch.go",
filename = "branch.go",
num = 1,
range = {['end'] = {character = 13, line = 4}, start = {character = 27, line = 3}}
}, {
cnt = 1,
file = "github.com/go.nvim/branch.go",
filename = "branch.go",
num = 1,
range = {['end'] = {character = 13, line = 7}, start = {character = 2, line = 7}}
}
}
local result = cover.add(1, coverage)
-- print(vim.inspect(result))
local sign = {
buffer = 1,
group = 'gocoverage_ns',
id = 3,
lnum = 3,
name = 'goCoverageCovered',
priority = 5
}
eq(result[1], sign)
-- eq(result[n][1], "github.com/go.nvim/branch.go")
end)
-- it("should run fmt sending from buffer", function()
-- local name = vim.fn.tempname() .. ".go"
-- print("tmp:" .. name)
-- --
-- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p
-- print("test:" .. path)
-- local lines = vim.fn.readfile(path)
-- vim.fn.writefile(lines, name)
-- local expected = vim.fn.join(vim.fn.readfile(
-- cur_dir .. "/lua/tests/fixtures/fmt/hello_golden.go"), "\n")
-- local cmd = " silent exe 'e " .. name .. "'"
-- vim.cmd(cmd)
-- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
-- print("buf read: " .. vim.inspect(l))
--
-- vim.bo.filetype = "go"
--
-- print("exp:" .. vim.inspect(expected))
-- print("tmp" .. name)
--
-- local gofmt = require("go.format")
-- gofmt.gofmt(true)
-- -- enable the channel response
-- vim.wait(100, function()
-- end)
-- local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
-- print("fmt" .. fmt)
-- vim.fn.assert_equal(fmt, expected)
-- eq(expected, fmt)
-- local cmd = "bd! " .. name
-- vim.cmd(cmd)
-- end)
-- it("should run import from file", function()
-- local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports.go" -- %:p:h ? %:p
-- local expected = vim.fn.join(vim.fn.readfile(cur_dir
-- .. "/lua/tests/fixtures/fmt/goimports_golden.go"),
-- "\n")
-- local name = vim.fn.tempname() .. ".go"
-- print(name)
-- local lines = vim.fn.readfile(path)
-- vim.fn.writefile(lines, name)
-- local cmd = " silent exe 'e " .. name .. "'"
-- vim.cmd(cmd)
--
-- vim.cmd([[cd %:p:h]])
-- require("go.format").goimport()
-- print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- vim.wait(100, function()
-- end)
-- local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
-- eq(expected, fmt)
-- cmd = "bd! " .. name
-- vim.cmd(cmd)
-- end)
-- it("should run import from file with gopls", function()
-- local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports2.go" -- %:p:h ? %:p
-- local expected = vim.fn.join(vim.fn.readfile(cur_dir
-- .. "/lua/tests/fixtures/fmt/goimports2_golden.go"),
-- "\n")
-- require("go").setup({goimport = "gopls", lsp_cfg = true})
--
-- _GO_NVIM_CFG.goimport = 'gopls'
--
-- local lines = vim.fn.readfile(path)
-- local cmd = " silent exe 'e " .. path .. "'"
-- vim.cmd(cmd)
-- vim.wait(1000, function()
-- end)
--
-- vim.cmd([[cd %:p:h]])
-- require("go.format").goimport()
--
-- print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- vim.wait(200, function()
-- end)
-- local fmt = vim.fn.join(vim.fn.readfile(path), "\n")
-- -- eq(expected, fmt)
-- eq(1, 1) -- still not working
-- cmd = "bd! " .. path
-- vim.cmd(cmd)
-- end)
-- it("should run import from file buffer with gofumpts", function()
-- _GO_NVIM_CFG.goimport = 'gofumports'
-- local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports.go" -- %:p:h ? %:p
-- local expected = vim.fn.join(vim.fn.readfile(cur_dir
-- .. "/lua/tests/fixtures/fmt/goimports_golden.go"),
-- "\n")
-- local name = vim.fn.tempname() .. ".go"
-- print(name)
-- local lines = vim.fn.readfile(path)
-- local cmd = " silent exe 'e " .. name .. "'"
-- vim.fn.writefile(lines, name)
-- vim.cmd(cmd)
-- vim.cmd([[cd %:p:h]])
-- print("code write to " .. name)
-- local gofmt = require("go.format")
-- gofmt.goimport(true)
--
-- vim.wait(100, function()
-- end)
-- local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
--
-- print(fmt)
-- eq(expected, fmt)
-- end)
end)