47 lines
972 B
Go
47 lines
972 B
Go
package coverage
|
|
|
|
import "strings"
|
|
|
|
// Files contains coverage files indexed by file path
|
|
type Files struct {
|
|
packagePath string
|
|
Files map[string]File
|
|
}
|
|
|
|
// File represents every coverage chunk for a file
|
|
type File []Coverage
|
|
|
|
// Coverage represents a covered chunk
|
|
type Coverage struct {
|
|
StartLine uint64
|
|
StartColumn uint64
|
|
EndLine uint64
|
|
EndColumn uint64
|
|
}
|
|
|
|
// GetFile returns the formatted coverage for the file located at @path
|
|
func (f *Files) GetFile(path string) *Files {
|
|
var isDir bool = !strings.HasSuffix(path, ".go")
|
|
|
|
files := &Files{
|
|
packagePath: f.packagePath,
|
|
Files: make(map[string]File),
|
|
}
|
|
|
|
// search in coverage files
|
|
for fPath, fileCoverage := range f.Files {
|
|
|
|
if !isDir && path == fPath {
|
|
files.Files[fPath] = fileCoverage
|
|
// if not directory search, stop at first result
|
|
break
|
|
}
|
|
|
|
if isDir && (path == "." || strings.HasPrefix(fPath, path)) {
|
|
files.Files[fPath] = fileCoverage
|
|
}
|
|
}
|
|
|
|
return files
|
|
}
|