@@ -14,10 +14,13 @@ const dummyCheckerName string = "dummy"
1414type dummyChecker struct {
1515}
1616
17- func (c dummyChecker ) CheckLine (lineNo int , filePath string , owners ... string ) []codeowners.CheckResult {
17+ func (c dummyChecker ) CheckLine (lineNo int , line string ) []codeowners.CheckResult {
1818 return []codeowners.CheckResult {
1919 {
20- LineNo : 1 ,
20+ Position : codeowners.Position {
21+ StartLine : 1 ,
22+ EndLine : 1 ,
23+ },
2124 Message : "Dummy Error" ,
2225 Severity : codeowners .Error ,
2326 CheckName : dummyCheckerName ,
@@ -58,11 +61,85 @@ func TestSeverityLevelLabels(t *testing.T) {
5861 }
5962}
6063
64+ func TestPositionString (t * testing.T ) {
65+ testCases := []struct {
66+ input codeowners.Position
67+ want string
68+ }{
69+ {
70+ input : codeowners.Position {
71+ StartLine : 1 ,
72+ StartColumn : 1 ,
73+ EndLine : 2 ,
74+ EndColumn : 2 ,
75+ },
76+ want : "1:1-2:2" ,
77+ },
78+ {
79+ input : codeowners.Position {
80+ StartLine : 1 ,
81+ StartColumn : 1 ,
82+ EndLine : 1 ,
83+ EndColumn : 2 ,
84+ },
85+ want : "1:1-2" ,
86+ },
87+ {
88+ input : codeowners.Position {
89+ StartLine : 1 ,
90+ StartColumn : 1 ,
91+ EndLine : 1 ,
92+ EndColumn : 1 ,
93+ },
94+ want : "1:1" ,
95+ },
96+ {
97+ input : codeowners.Position {
98+ StartLine : 1 ,
99+ StartColumn : 0 ,
100+ EndLine : 1 ,
101+ EndColumn : 0 ,
102+ },
103+ want : "1" ,
104+ },
105+ {
106+ input : codeowners.Position {
107+ StartLine : 1 ,
108+ StartColumn : 0 ,
109+ EndLine : 0 ,
110+ EndColumn : 0 ,
111+ },
112+ want : "1" ,
113+ },
114+ {
115+ input : codeowners.Position {
116+ StartLine : 0 ,
117+ StartColumn : 0 ,
118+ EndLine : 0 ,
119+ EndColumn : 0 ,
120+ },
121+ want : "0" ,
122+ },
123+ }
124+
125+ for _ , testCase := range testCases {
126+ got := testCase .input .String ()
127+ if got != testCase .want {
128+ t .Errorf ("Input: %v, Want: %v, Got: %v" , testCase .input , testCase .want , got )
129+ }
130+ }
131+ }
132+
61133func TestSimpleCheck (t * testing.T ) {
62134 input := "./test/data/pass"
63135 want := []codeowners.CheckResult {
64136 {
65- LineNo : 1 ,
137+ Position : codeowners.Position {
138+ StartLine : 1 ,
139+ StartColumn : 0 ,
140+ EndLine : 1 ,
141+ EndColumn : 0 ,
142+ },
66143 Message : "Dummy Error" ,
67144 Severity : codeowners .Error ,
68145 CheckName : dummyCheckerName ,
@@ -102,7 +179,6 @@ func TestNoCodeownersCheck(t *testing.T) {
102179 input := "./test/data"
103180 want := []codeowners.CheckResult {
104181 {
105- LineNo : 0 ,
106182 Message : "No CODEOWNERS file found" ,
107183 Severity : codeowners .Error ,
108184 CheckName : "NoCodeowners" ,
@@ -122,7 +198,6 @@ func TestMultipleCodeownersCheck(t *testing.T) {
122198 input := "./test/data/multiple_codeowners"
123199 want := []codeowners.CheckResult {
124200 {
125- LineNo : 0 ,
126201 Message : "Multiple CODEOWNERS files found (CODEOWNERS, docs/CODEOWNERS)" ,
127202 Severity : codeowners .Warning ,
128203 CheckName : "MultipleCodeowners" ,
@@ -144,7 +219,7 @@ func ExampleCheck() {
144219 panic (err )
145220 }
146221 for _ , check := range checks {
147- fmt .Printf ("%d ::%s:: %s [%s]\n " , check .LineNo , check .Severity , check .Message , check .CheckName )
222+ fmt .Printf ("%s ::%s:: %s [%s]\n " , check .Position , check .Severity , check .Message , check .CheckName )
148223 }
149224 //Output:
150225 //0 ::Error:: No CODEOWNERS file found [NoCodeowners]
0 commit comments