@@ -31,26 +31,12 @@ func TestExcludeRulesMultiple(t *testing.T) {
3131 Linters : []string {"lll" },
3232 },
3333 }, 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+
5035 cases := []issueCase {
5136 {Path : "e.go" , Text : "exclude" , Linter : "linter" },
5237 {Path : "e.go" , Text : "some" , Linter : "linter" },
5338 {Path : "e_test.go" , Text : "normal" , Linter : "testlinter" },
39+ {Path : "e_Test.go" , Text : "normal" , Linter : "testlinter" },
5440 {Path : "e_test.go" , Text : "another" , Linter : "linter" },
5541 {Path : "e_test.go" , Text : "testonly" , Linter : "linter" },
5642 {Path : filepath .Join ("testdata" , "exclude_rules.go" ), Line : 3 , Linter : "lll" },
@@ -71,11 +57,30 @@ func TestExcludeRulesMultiple(t *testing.T) {
7157 }
7258 expectedCases := []issueCase {
7359 {Path : "e.go" , Text : "some" , Linter : "linter" },
60+ {Path : "e_Test.go" , Text : "normal" , Linter : "testlinter" },
7461 {Path : "e_test.go" , Text : "another" , Linter : "linter" },
7562 }
7663 assert .Equal (t , expectedCases , resultingCases )
7764}
7865
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+
7984func TestExcludeRulesText (t * testing.T ) {
8085 p := NewExcludeRules ([]ExcludeRule {
8186 {
@@ -103,6 +108,96 @@ func TestExcludeRulesText(t *testing.T) {
103108 }
104109 assert .Equal (t , texts [1 :], processedTexts )
105110}
111+
106112func TestExcludeRulesEmpty (t * testing.T ) {
107113 processAssertSame (t , NewExcludeRules (nil , nil , nil ), newTextIssue ("test" ))
108114}
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