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)
|
2022-07-01 09:15:12 +00:00
|
|
|
local status = require("plenary.reload").reload_module("go.nvim")
|
2021-08-25 15:42:17 +00:00
|
|
|
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]])
|
2021-09-02 10:57:20 +00:00
|
|
|
require('go').setup({
|
|
|
|
trace = true,
|
|
|
|
lsp_cfg = true,
|
|
|
|
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log"
|
|
|
|
})
|
2021-08-25 15:42:17 +00:00
|
|
|
|
|
|
|
local cover = require("go.coverage")
|
|
|
|
local result = cover.read_cov(path)
|
|
|
|
|
|
|
|
-- print(vim.inspect(result))
|
2021-08-26 00:33:17 +00:00
|
|
|
local n = "branch.go"
|
2021-08-25 15:42:17 +00:00
|
|
|
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)
|
2022-07-01 09:15:12 +00:00
|
|
|
eq(result[n].file_lines, 9)
|
|
|
|
eq(result[n].file_covered, 4)
|
|
|
|
|
2022-12-28 00:46:31 +00:00
|
|
|
range = {['end'] = {character = 13, line = 11}, start = {character = 2, line = 11}}
|
|
|
|
eq(result[n][3].range, range)
|
2022-07-01 09:15:12 +00:00
|
|
|
eq(result.total_lines, 9)
|
|
|
|
eq(result.total_covered, 4)
|
2021-08-25 15:42:17 +00:00
|
|
|
-- 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,
|
2021-09-02 10:57:20 +00:00
|
|
|
lsp_cfg = true,
|
2021-08-25 15:42:17 +00:00
|
|
|
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
|
|
|
|
gocoverage_sign = '|'
|
|
|
|
})
|
|
|
|
|
|
|
|
local cover = require("go.coverage")
|
|
|
|
cover.highlight()
|
|
|
|
|
|
|
|
local coverage = {
|
|
|
|
{
|
2022-12-28 04:03:29 +00:00
|
|
|
covered = 1,
|
2021-08-25 15:42:17 +00:00
|
|
|
file = "github.com/go.nvim/branch.go",
|
|
|
|
filename = "branch.go",
|
|
|
|
num = 1,
|
|
|
|
range = {['end'] = {character = 13, line = 4}, start = {character = 27, line = 3}}
|
|
|
|
}, {
|
2022-12-28 04:03:29 +00:00
|
|
|
covered = 1,
|
2021-08-25 15:42:17 +00:00
|
|
|
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)
|
2022-12-28 04:03:29 +00:00
|
|
|
print(vim.inspect(result))
|
2021-08-25 15:42:17 +00:00
|
|
|
local sign = {
|
|
|
|
buffer = 1,
|
|
|
|
group = 'gocoverage_ns',
|
|
|
|
id = 3,
|
|
|
|
lnum = 3,
|
|
|
|
name = 'goCoverageCovered',
|
2022-08-05 10:24:42 +00:00
|
|
|
priority = 7
|
2021-08-25 15:42:17 +00:00
|
|
|
}
|
|
|
|
eq(result[1], sign)
|
|
|
|
-- eq(result[n][1], "github.com/go.nvim/branch.go")
|
|
|
|
end)
|
|
|
|
end)
|