cliverage/coverage/types.go

47 lines
972 B
Go
Raw Permalink Normal View History

2019-11-23 00:04:35 +00:00
package coverage
import "strings"
// Files contains coverage files indexed by file path
type Files struct {
packagePath string
2019-11-23 01:09:06 +00:00
Files map[string]File
2019-11-23 00:04:35 +00:00
}
// 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
2019-11-23 01:09:06 +00:00
func (f *Files) GetFile(path string) *Files {
2019-11-23 00:04:35 +00:00
var isDir bool = !strings.HasSuffix(path, ".go")
2019-11-23 01:09:06 +00:00
files := &Files{
packagePath: f.packagePath,
Files: make(map[string]File),
}
2019-11-23 00:04:35 +00:00
// search in coverage files
2019-11-23 01:09:06 +00:00
for fPath, fileCoverage := range f.Files {
2019-11-23 00:04:35 +00:00
if !isDir && path == fPath {
2019-11-23 01:09:06 +00:00
files.Files[fPath] = fileCoverage
2019-11-23 00:04:35 +00:00
// if not directory search, stop at first result
break
}
if isDir && (path == "." || strings.HasPrefix(fPath, path)) {
2019-11-23 01:09:06 +00:00
files.Files[fPath] = fileCoverage
2019-11-23 00:04:35 +00:00
}
}
return files
}