11package processors
22
33import (
4+ "go/token"
45 "testing"
56
67 "github.com/stretchr/testify/assert"
@@ -9,25 +10,88 @@ import (
910)
1011
1112func TestExcludeRules (t * testing.T ) {
12- p := NewExcludeRules ([]ExcludeRule {
13- {
14- Text : "^exclude$" ,
15- },
13+ t .Run ("Multiple" , func (t * testing.T ) {
14+ p := NewExcludeRules ([]ExcludeRule {
15+ {
16+ Text : "^exclude$" ,
17+ Linters : []string {"linter" },
18+ },
19+ {
20+ Linters : []string {"testlinter" },
21+ Path : `_test\.go` ,
22+ },
23+ {
24+ Text : "^testonly$" ,
25+ Path : `_test\.go` ,
26+ },
27+ })
28+ type issueCase struct {
29+ Path string
30+ Text string
31+ Linter string
32+ }
33+ var newIssueCase = func (c issueCase ) result.Issue {
34+ return result.Issue {
35+ Text : c .Text ,
36+ FromLinter : c .Linter ,
37+ Pos : token.Position {
38+ Filename : c .Path ,
39+ },
40+ }
41+ }
42+ cases := []issueCase {
43+ {Path : "e.go" , Text : "exclude" , Linter : "linter" },
44+ {Path : "e.go" , Text : "some" , Linter : "linter" },
45+ {Path : "e_test.go" , Text : "normal" , Linter : "testlinter" },
46+ {Path : "e_test.go" , Text : "another" , Linter : "linter" },
47+ {Path : "e_test.go" , Text : "testonly" , Linter : "linter" },
48+ }
49+ var issues []result.Issue
50+ for _ , c := range cases {
51+ issues = append (issues , newIssueCase (c ))
52+ }
53+ processedIssues := process (t , p , issues ... )
54+ var resultingCases []issueCase
55+ for _ , i := range processedIssues {
56+ resultingCases = append (resultingCases , issueCase {
57+ Path : i .FilePath (),
58+ Linter : i .FromLinter ,
59+ Text : i .Text ,
60+ })
61+ }
62+ expectedCases := []issueCase {
63+ {Path : "e.go" , Text : "some" , Linter : "linter" },
64+ {Path : "e_test.go" , Text : "another" , Linter : "linter" },
65+ }
66+ assert .Equal (t , expectedCases , resultingCases )
1667 })
17- texts := []string {"excLude" , "1" , "" , "exclud" , "notexclude" }
18- var issues []result.Issue
19- for _ , t := range texts {
20- issues = append (issues , newTextIssue (t ))
21- }
68+ t .Run ("Text" , func (t * testing.T ) {
69+ p := NewExcludeRules ([]ExcludeRule {
70+ {
71+ Text : "^exclude$" ,
72+ Linters : []string {
73+ "linter" ,
74+ },
75+ },
76+ })
77+ texts := []string {"excLude" , "1" , "" , "exclud" , "notexclude" }
78+ var issues []result.Issue
79+ for _ , t := range texts {
80+ issues = append (issues , result.Issue {
81+ Text : t ,
82+ FromLinter : "linter" ,
83+ })
84+ }
2285
23- processedIssues := process (t , p , issues ... )
24- assert .Len (t , processedIssues , len (issues )- 1 )
86+ processedIssues := process (t , p , issues ... )
87+ assert .Len (t , processedIssues , len (issues )- 1 )
2588
26- var processedTexts []string
27- for _ , i := range processedIssues {
28- processedTexts = append (processedTexts , i .Text )
29- }
30- assert .Equal (t , texts [1 :], processedTexts )
89+ var processedTexts []string
90+ for _ , i := range processedIssues {
91+ processedTexts = append (processedTexts , i .Text )
92+ }
93+ assert .Equal (t , texts [1 :], processedTexts )
94+ })
3195 t .Run ("Empty" , func (t * testing.T ) {
3296 processAssertSame (t , NewExcludeRules (nil ), newTextIssue ("test" ))
3397 })
0 commit comments