@@ -31,26 +31,12 @@ func TestExcludeRulesMultiple(t *testing.T) {
31
31
Linters : []string {"lll" },
32
32
},
33
33
}, lineCache , nil )
34
- type issueCase struct {
35
- Path string
36
- Line int
37
- Text string
38
- Linter string
39
- }
40
- var newIssueCase = func (c issueCase ) result.Issue {
41
- return result.Issue {
42
- Text : c .Text ,
43
- FromLinter : c .Linter ,
44
- Pos : token.Position {
45
- Filename : c .Path ,
46
- Line : c .Line ,
47
- },
48
- }
49
- }
34
+
50
35
cases := []issueCase {
51
36
{Path : "e.go" , Text : "exclude" , Linter : "linter" },
52
37
{Path : "e.go" , Text : "some" , Linter : "linter" },
53
38
{Path : "e_test.go" , Text : "normal" , Linter : "testlinter" },
39
+ {Path : "e_Test.go" , Text : "normal" , Linter : "testlinter" },
54
40
{Path : "e_test.go" , Text : "another" , Linter : "linter" },
55
41
{Path : "e_test.go" , Text : "testonly" , Linter : "linter" },
56
42
{Path : filepath .Join ("testdata" , "exclude_rules.go" ), Line : 3 , Linter : "lll" },
@@ -71,11 +57,30 @@ func TestExcludeRulesMultiple(t *testing.T) {
71
57
}
72
58
expectedCases := []issueCase {
73
59
{Path : "e.go" , Text : "some" , Linter : "linter" },
60
+ {Path : "e_Test.go" , Text : "normal" , Linter : "testlinter" },
74
61
{Path : "e_test.go" , Text : "another" , Linter : "linter" },
75
62
}
76
63
assert .Equal (t , expectedCases , resultingCases )
77
64
}
78
65
66
+ type issueCase struct {
67
+ Path string
68
+ Line int
69
+ Text string
70
+ Linter string
71
+ }
72
+
73
+ func newIssueCase (c issueCase ) result.Issue {
74
+ return result.Issue {
75
+ Text : c .Text ,
76
+ FromLinter : c .Linter ,
77
+ Pos : token.Position {
78
+ Filename : c .Path ,
79
+ Line : c .Line ,
80
+ },
81
+ }
82
+ }
83
+
79
84
func TestExcludeRulesText (t * testing.T ) {
80
85
p := NewExcludeRules ([]ExcludeRule {
81
86
{
@@ -103,6 +108,96 @@ func TestExcludeRulesText(t *testing.T) {
103
108
}
104
109
assert .Equal (t , texts [1 :], processedTexts )
105
110
}
111
+
106
112
func TestExcludeRulesEmpty (t * testing.T ) {
107
113
processAssertSame (t , NewExcludeRules (nil , nil , nil ), newTextIssue ("test" ))
108
114
}
115
+
116
+ func TestExcludeRulesCaseSensitiveMultiple (t * testing.T ) {
117
+ lineCache := fsutils .NewLineCache (fsutils .NewFileCache ())
118
+ p := NewExcludeRulesCaseSensitive ([]ExcludeRule {
119
+ {
120
+ Text : "^exclude$" ,
121
+ Linters : []string {"linter" },
122
+ },
123
+ {
124
+ Linters : []string {"testlinter" },
125
+ Path : `_test\.go` ,
126
+ },
127
+ {
128
+ Text : "^testonly$" ,
129
+ Path : `_test\.go` ,
130
+ },
131
+ {
132
+ Source : "^//go:generate " ,
133
+ Linters : []string {"lll" },
134
+ },
135
+ }, lineCache , nil )
136
+
137
+ cases := []issueCase {
138
+ {Path : "e.go" , Text : "exclude" , Linter : "linter" },
139
+ {Path : "e.go" , Text : "excLude" , Linter : "linter" },
140
+ {Path : "e.go" , Text : "some" , Linter : "linter" },
141
+ {Path : "e_test.go" , Text : "normal" , Linter : "testlinter" },
142
+ {Path : "e_Test.go" , Text : "normal" , Linter : "testlinter" },
143
+ {Path : "e_test.go" , Text : "another" , Linter : "linter" },
144
+ {Path : "e_test.go" , Text : "testonly" , Linter : "linter" },
145
+ {Path : "e_test.go" , Text : "testOnly" , Linter : "linter" },
146
+ {Path : filepath .Join ("testdata" , "exclude_rules_case_sensitive.go" ), Line : 3 , Linter : "lll" },
147
+ }
148
+ var issues []result.Issue
149
+ for _ , c := range cases {
150
+ issues = append (issues , newIssueCase (c ))
151
+ }
152
+ processedIssues := process (t , p , issues ... )
153
+ var resultingCases []issueCase
154
+ for _ , i := range processedIssues {
155
+ resultingCases = append (resultingCases , issueCase {
156
+ Path : i .FilePath (),
157
+ Linter : i .FromLinter ,
158
+ Text : i .Text ,
159
+ Line : i .Line (),
160
+ })
161
+ }
162
+ expectedCases := []issueCase {
163
+ {Path : "e.go" , Text : "excLude" , Linter : "linter" },
164
+ {Path : "e.go" , Text : "some" , Linter : "linter" },
165
+ {Path : "e_Test.go" , Text : "normal" , Linter : "testlinter" },
166
+ {Path : "e_test.go" , Text : "another" , Linter : "linter" },
167
+ {Path : "e_test.go" , Text : "testOnly" , Linter : "linter" },
168
+ {Path : filepath .Join ("testdata" , "exclude_rules_case_sensitive.go" ), Line : 3 , Linter : "lll" },
169
+ }
170
+ assert .Equal (t , expectedCases , resultingCases )
171
+ }
172
+
173
+ func TestExcludeRulesCaseSensitiveText (t * testing.T ) {
174
+ p := NewExcludeRulesCaseSensitive ([]ExcludeRule {
175
+ {
176
+ Text : "^exclude$" ,
177
+ Linters : []string {
178
+ "linter" ,
179
+ },
180
+ },
181
+ }, nil , nil )
182
+ texts := []string {"exclude" , "excLude" , "1" , "" , "exclud" , "notexclude" }
183
+ var issues []result.Issue
184
+ for _ , t := range texts {
185
+ issues = append (issues , result.Issue {
186
+ Text : t ,
187
+ FromLinter : "linter" ,
188
+ })
189
+ }
190
+
191
+ processedIssues := process (t , p , issues ... )
192
+ assert .Len (t , processedIssues , len (issues )- 1 )
193
+
194
+ var processedTexts []string
195
+ for _ , i := range processedIssues {
196
+ processedTexts = append (processedTexts , i .Text )
197
+ }
198
+ assert .Equal (t , texts [1 :], processedTexts )
199
+ }
200
+
201
+ func TestExcludeRulesCaseSensitiveEmpty (t * testing.T ) {
202
+ processAssertSame (t , NewExcludeRulesCaseSensitive (nil , nil , nil ), newTextIssue ("test" ))
203
+ }
0 commit comments