-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdiffResult.go
50 lines (43 loc) · 1.28 KB
/
diffResult.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bytes"
"strconv"
)
//result contains an analysis of a set of commit
type diffResult struct {
//The name of the files seen
files []string
//How many region we have (i.e. seperated by @@)
regions int
//How many line were added total
lineAdded int
//How many line were deleted totla
lineDeleted int
//How many times the function seen in the code are called.
functionCalls map[string]int
}
//String returns the value of results as a formated string
func (r *diffResult) String() string {
var buffer bytes.Buffer
buffer.WriteString("Files: \n")
for _, file := range r.files {
buffer.WriteString(" -")
buffer.WriteString(file)
buffer.WriteString("\n")
}
r.appendIntValueToBuffer(r.regions, "Regions", &buffer)
r.appendIntValueToBuffer(r.lineAdded, "LA", &buffer)
r.appendIntValueToBuffer(r.lineDeleted, "LD", &buffer)
buffer.WriteString("Functions calls: \n")
for key, value := range r.functionCalls {
r.appendIntValueToBuffer(value, key, &buffer)
}
return buffer.String()
}
//appendIntValueToBuffer appends int value to a bytes buffer
func (r diffResult) appendIntValueToBuffer(value int, label string, buffer *bytes.Buffer) {
buffer.WriteString(label)
buffer.WriteString(" : ")
buffer.WriteString(strconv.Itoa(value))
buffer.WriteString("\n")
}