44 lines
913 B
Go
44 lines
913 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) []File {
|
||
|
var isDir bool = !strings.HasSuffix(path, ".go")
|
||
|
|
||
|
files := make([]File, 0)
|
||
|
|
||
|
// search in coverage files
|
||
|
for fPath, fileCoverage := range f.files {
|
||
|
|
||
|
if !isDir && path == fPath {
|
||
|
files = append(files, fileCoverage)
|
||
|
// if not directory search, stop at first result
|
||
|
break
|
||
|
}
|
||
|
|
||
|
if isDir && (path == "." || strings.HasPrefix(fPath, path)) {
|
||
|
files = append(files, fileCoverage)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return files
|
||
|
}
|