edit coverage

This commit is contained in:
Adrien Marquès 2019-11-23 02:09:06 +01:00
parent 965d445aa9
commit 0ea53661f8
2 changed files with 13 additions and 10 deletions

View File

@ -16,7 +16,7 @@ func Parse(r io.Reader, gopkg string) (*Files, error) {
var n uint = 0 var n uint = 0
files := &Files{ files := &Files{
files: make(map[string]File), Files: make(map[string]File),
packagePath: gopkg, packagePath: gopkg,
} }
@ -104,11 +104,11 @@ func Parse(r io.Reader, gopkg string) (*Files, error) {
} }
// append to files // append to files
_, isset := files.files[filename] _, isset := files.Files[filename]
if !isset { if !isset {
files.files[filename] = make(File, 0) files.Files[filename] = make(File, 0)
} }
files.files[filename] = append(files.files[filename], cover) files.Files[filename] = append(files.Files[filename], cover)
} }

View File

@ -5,7 +5,7 @@ import "strings"
// Files contains coverage files indexed by file path // Files contains coverage files indexed by file path
type Files struct { type Files struct {
packagePath string packagePath string
files map[string]File Files map[string]File
} }
// File represents every coverage chunk for a file // File represents every coverage chunk for a file
@ -20,22 +20,25 @@ type Coverage struct {
} }
// GetFile returns the formatted coverage for the file located at @path // GetFile returns the formatted coverage for the file located at @path
func (f *Files) GetFile(path string) []File { func (f *Files) GetFile(path string) *Files {
var isDir bool = !strings.HasSuffix(path, ".go") var isDir bool = !strings.HasSuffix(path, ".go")
files := make([]File, 0) files := &Files{
packagePath: f.packagePath,
Files: make(map[string]File),
}
// search in coverage files // search in coverage files
for fPath, fileCoverage := range f.files { for fPath, fileCoverage := range f.Files {
if !isDir && path == fPath { if !isDir && path == fPath {
files = append(files, fileCoverage) files.Files[fPath] = fileCoverage
// if not directory search, stop at first result // if not directory search, stop at first result
break break
} }
if isDir && (path == "." || strings.HasPrefix(fPath, path)) { if isDir && (path == "." || strings.HasPrefix(fPath, path)) {
files = append(files, fileCoverage) files.Files[fPath] = fileCoverage
} }
} }