@@ -39,25 +39,33 @@ func TestDocumentLink(t *testing.T) {
3939 protoFile : "testdata/document_link/main.proto" ,
4040 expectedLinks : []expectedLink {
4141 {
42- line : 4 , // import "types.proto" on line 5 (0-indexed line 4)
42+ line : 4 , // import "types.proto" on line 5 (0-indexed line 4)
43+ startChar : 7 , // Start of "types.proto" (including opening quote)
44+ endChar : 20 , // End of "types.proto" (after closing quote)
4345 description : "local import to types.proto" ,
4446 targetType : linkTargetTypeLocal ,
4547 localPath : "testdata/document_link/types.proto" ,
4648 },
4749 {
4850 line : 7 , // https://example.com/docs on line 8
51+ startChar : 7 ,
52+ endChar : 31 ,
4953 description : "comment URL 1" ,
5054 targetType : linkTargetTypeURL ,
5155 targetURL : "https://example.com/docs" ,
5256 },
5357 {
5458 line : 8 , // https://github.com/example/repo on line 9
59+ startChar : 14 ,
60+ endChar : 45 ,
5561 description : "comment URL 2" ,
5662 targetType : linkTargetTypeURL ,
5763 targetURL : "https://github.com/example/repo" ,
5864 },
5965 {
6066 line : 11 , // https://example.com/status on line 12
67+ startChar : 43 ,
68+ endChar : 69 ,
6169 description : "comment URL 3" ,
6270 targetType : linkTargetTypeURL ,
6371 targetURL : "https://example.com/status" ,
@@ -69,13 +77,17 @@ func TestDocumentLink(t *testing.T) {
6977 protoFile : "testdata/document_link/wkt.proto" ,
7078 expectedLinks : []expectedLink {
7179 {
72- line : 4 , // import "google/protobuf/timestamp.proto" on line 5
80+ line : 4 , // import "google/protobuf/timestamp.proto" on line 5
81+ startChar : 7 , // Start of "google/protobuf/timestamp.proto" (including opening quote)
82+ endChar : 40 , // End of "google/protobuf/timestamp.proto" (after closing quote)
7383 description : "WKT Timestamp import" ,
7484 targetType : linkTargetTypeURL ,
7585 targetURL : "https://buf.build/protocolbuffers/wellknowntypes/file/main:google/protobuf/timestamp.proto" ,
7686 },
7787 {
78- line : 5 , // import "google/protobuf/duration.proto" on line 6
88+ line : 5 , // import "google/protobuf/duration.proto" on line 6
89+ startChar : 7 , // Start of "google/protobuf/duration.proto" (including opening quote)
90+ endChar : 39 , // End of "google/protobuf/duration.proto" (after closing quote)
7991 description : "WKT Duration import" ,
8092 targetType : linkTargetTypeURL ,
8193 targetURL : "https://buf.build/protocolbuffers/wellknowntypes/file/main:google/protobuf/duration.proto" ,
@@ -105,7 +117,10 @@ func TestDocumentLink(t *testing.T) {
105117
106118 for i , expected := range tt .expectedLinks {
107119 link := links [i ]
108- assert .Equal (t , expected .line , link .Range .Start .Line , "link %d (%s): wrong line" , i , expected .description )
120+ assert .Equal (t , expected .line , link .Range .Start .Line , "link %d (%s): wrong start line" , i , expected .description )
121+ assert .Equal (t , expected .startChar , link .Range .Start .Character , "link %d (%s): wrong start character" , i , expected .description )
122+ assert .Equal (t , expected .line , link .Range .End .Line , "link %d (%s): wrong end line" , i , expected .description )
123+ assert .Equal (t , expected .endChar , link .Range .End .Character , "link %d (%s): wrong end character" , i , expected .description )
109124
110125 switch expected .targetType {
111126 case linkTargetTypeLocal :
@@ -133,6 +148,8 @@ const (
133148
134149type expectedLink struct {
135150 line uint32
151+ startChar uint32 // expected starting character position
152+ endChar uint32 // expected ending character position
136153 description string
137154 targetType linkTargetType
138155 localPath string // used when targetType is linkTargetTypeLocal
0 commit comments