-
Notifications
You must be signed in to change notification settings - Fork 36
/
analysis_test.go
131 lines (111 loc) · 2.62 KB
/
analysis_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package lookout
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAnalyzerCommentsGroupsFilter(t *testing.T) {
assert := assert.New(t)
g := AnalyzerCommentsGroups{
{
Comments: []*Comment{
{Text: "survive"},
{Text: "skip"},
{Text: "survive"},
},
},
{
Comments: []*Comment{
{Text: "survive"},
},
},
{
Comments: []*Comment{
{Text: "skip"},
},
},
}
result, err := g.Filter(func(c *Comment) (skip bool, err error) {
return c.Text == "skip", nil
})
assert.NoError(err)
assert.Len(result, 2)
assert.Len(result[0].Comments, 2)
assert.Len(result[1].Comments, 1)
e := errors.New("test-error")
_, err = g.Filter(func(c *Comment) (skip bool, err error) {
return false, e
})
assert.Equal(e, err)
}
func TestAnalyzerCommentsGroupsCount(t *testing.T) {
assert := assert.New(t)
g := AnalyzerCommentsGroups{}
assert.Equal(g.Count(), 0)
g = AnalyzerCommentsGroups{
{
Comments: []*Comment{
{Text: "some text"},
},
},
}
assert.Equal(g.Count(), 1)
g = AnalyzerCommentsGroups{
{
Comments: []*Comment{
{Text: "some text"},
},
},
{
Comments: []*Comment{
{Text: "some text"},
{Text: "some text"},
},
},
}
assert.Equal(g.Count(), 3)
}
func TestAnalyzerCommentsGroupsDedup(t *testing.T) {
assert := assert.New(t)
g := AnalyzerCommentsGroups{
{
Comments: []*Comment{
{File: "f1.go", Line: 1, Text: "some-text", Confidence: 1},
{File: "f1.go", Line: 1, Text: "some-text", Confidence: 2},
{File: "f1.go", Line: 2, Text: "some-text", Confidence: 4},
{File: "f2.go", Line: 1, Text: "some-text", Confidence: 8},
},
Config: AnalyzerConfig{Name: "analyzer1"},
},
{
Comments: []*Comment{
{File: "f1.go", Line: 1, Text: "some-text", Confidence: 1},
{File: "f2.go", Line: 1, Text: "some-text", Confidence: 2},
{File: "f2.go", Line: 1, Text: "another-text", Confidence: 4},
},
Config: AnalyzerConfig{Name: "analyzer2"},
},
{
Comments: []*Comment{
{File: "f1.go", Line: 1, Text: "some-text", Confidence: 1},
},
Config: AnalyzerConfig{Name: "analyzer3"},
},
}
result := g.Dedup()
assert.Len(result, 3)
assert.Len(result[0].Comments, 3)
assert.Len(result[1].Comments, 3)
assert.Len(result[2].Comments, 1)
// for testing use confidence as id, the confidence used in the fixtures
// has been chosen so that the sum of every possible combination has a
// unique value (similarly to unix permissions)
expected := []int{13, 7, 1}
for i, exp := range expected {
sum := 0
for _, c := range result[i].Comments {
sum += int(c.Confidence)
}
assert.Equal(sum, exp)
}
}