@@ -3,6 +3,7 @@ package codeowners_test
33import (
44 "fmt"
55 "reflect"
6+ "strconv"
67 "strings"
78 "testing"
89
@@ -15,8 +16,8 @@ func exec(input string) ([][]string, int) {
1516 c := 0
1617 for decoder .More () {
1718 c ++
18- token := decoder .Token ()
19- got = append (got , append ([]string {token .Path ()}, token .Owners ()... ))
19+ token , line := decoder .Token ()
20+ got = append (got , append ([]string {strconv . Itoa ( line ), token .Path ()}, token .Owners ()... ))
2021 }
2122 return got , c
2223}
@@ -33,27 +34,27 @@ func assert(t *testing.T, input string, want [][]string) {
3334
3435func TestSimple (t * testing.T ) {
3536 assert (t , `* test@example.org` , [][]string {
36- {"*" , "test@example.org" },
37+ {"1" , " *" , "test@example.org" },
3738 })
3839}
3940
4041func TestMultipleOwners (t * testing.T ) {
4142 assert (t , `* test@example.org @owner @company/team` , [][]string {
42- {"*" , "test@example.org" , "@owner" , "@company/team" },
43+ {"1" , " *" , "test@example.org" , "@owner" , "@company/team" },
4344 })
4445}
4546
4647func TestFilesWithSpaces (t * testing.T ) {
4748 assert (t , `file\ with\ spaces @owner` , [][]string {
48- {"file with spaces" , "@owner" },
49+ {"1" , " file with spaces" , "@owner" },
4950 })
5051}
5152
5253func TestMultipleLines (t * testing.T ) {
5354 assert (t , `* test@example.org
5455file @owner` , [][]string {
55- {"*" , "test@example.org" },
56- {"file" , "@owner" },
56+ {"1" , " *" , "test@example.org" },
57+ {"2" , " file" , "@owner" },
5758 })
5859}
5960
@@ -72,23 +73,23 @@ file @owner
7273
7374
7475` , [][]string {
75- {"*" , "test@example.org" },
76- {"file" , "@owner" },
76+ {"1" , " *" , "test@example.org" },
77+ {"5" , " file" , "@owner" },
7778 })
7879}
7980
8081func TestIgnoreComments (t * testing.T ) {
8182 assert (t , `* test@example.org # comment
8283# comment
8384file @owner` , [][]string {
84- {"*" , "test@example.org" },
85- {"file" , "@owner" },
85+ {"1" , " *" , "test@example.org" },
86+ {"3" , " file" , "@owner" },
8687 })
8788}
8889
8990func TestNoOwners (t * testing.T ) {
9091 assert (t , `*` , [][]string {
91- {"*" },
92+ {"1" , " *" },
9293 })
9394}
9495
@@ -98,7 +99,10 @@ func TestLastToken(t *testing.T) {
9899 t .Error ("More should be true" )
99100 }
100101 for i := 0 ; i < 3 ; i ++ { //calling 3 times to prove it always returns the last line
101- token := decoder .Token ()
102+ token , line := decoder .Token ()
103+ if line != 1 {
104+ t .Error ("Line should be '1'" )
105+ }
102106 if token .Path () != "filepattern" {
103107 t .Error ("Path should be 'filepattern'" )
104108 }
@@ -114,7 +118,7 @@ func TestLastToken(t *testing.T) {
114118
115119func TestMoreNotCalled (t * testing.T ) {
116120 decoder := codeowners .NewDecoder (strings .NewReader (`filepattern @owner` ))
117- token := decoder .Token ()
121+ token , _ := decoder .Token ()
118122 if token .Path () != "" {
119123 t .Error ("Path should be empty" )
120124 }
@@ -127,13 +131,16 @@ func ExampleDecoder() {
127131 decoder := codeowners .NewDecoder (strings .NewReader (`* test@example.org
128132filepattern @owner` ))
129133 for decoder .More () {
130- token := decoder .Token ()
134+ token , line := decoder .Token ()
135+ fmt .Printf ("Line: %d\n " , line )
131136 fmt .Printf ("File Pattern: %s\n " , token .Path ())
132137 fmt .Printf ("Owners: %v\n " , token .Owners ())
133138 }
134139 // Output:
140+ // Line: 1
135141 // File Pattern: *
136142 // Owners: [test@example.org]
143+ // Line: 2
137144 // File Pattern: filepattern
138145 // Owners: [@owner]
139146}
0 commit comments