This file is indexed.

/usr/share/gocode/src/github.com/peterhellberg/link/link_test.go is in golang-github-peterhellberg-link-dev 1.0.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package link

import (
	"fmt"
	"net/http"
	"testing"
)

func TestLinkString(t *testing.T) {
	l := Parse(`<https://example.com/?page=2>; rel="next"; title="foo"`)["next"]

	if got, want := l.String(), "https://example.com/?page=2"; got != want {
		t.Fatalf(`l.String() = %q, want %q`, got, want)
	}
}

func TestParseRequest(t *testing.T) {
	req, _ := http.NewRequest("GET", "", nil)
	req.Header.Set("Link", `<https://example.com/?page=2>; rel="next"`)

	g := ParseRequest(req)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["next"] == nil {
		t.Fatalf(`g["next"] == nil`)
	}

	if got, want := g["next"].URI, "https://example.com/?page=2"; got != want {
		t.Fatalf(`g["next"].URI = %q, want %q`, got, want)
	}

	if got, want := g["next"].Rel, "next"; got != want {
		t.Fatalf(`g["next"].Rel = %q, want %q`, got, want)
	}

	if got, want := len(ParseRequest(nil)), 0; got != want {
		t.Fatalf(`len(ParseRequest(nil)) = %d, want %d`, got, want)
	}
}

func TestParseResponse(t *testing.T) {
	resp := &http.Response{Header: http.Header{}}
	resp.Header.Set("Link", `<https://example.com/?page=2>; rel="next"`)

	g := ParseResponse(resp)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["next"] == nil {
		t.Fatalf(`g["next"] == nil`)
	}

	if got, want := g["next"].URI, "https://example.com/?page=2"; got != want {
		t.Fatalf(`g["next"].URI = %q, want %q`, got, want)
	}

	if got, want := g["next"].Rel, "next"; got != want {
		t.Fatalf(`g["next"].Rel = %q, want %q`, got, want)
	}

	if got, want := len(ParseResponse(nil)), 0; got != want {
		t.Fatalf(`len(ParseResponse(nil)) = %d, want %d`, got, want)
	}
}

func TestParseHeader_single(t *testing.T) {
	h := http.Header{}
	h.Set("Link", `<https://example.com/?page=2>; rel="next"`)

	g := ParseHeader(h)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["next"] == nil {
		t.Fatalf(`g["next"] == nil`)
	}

	if got, want := g["next"].URI, "https://example.com/?page=2"; got != want {
		t.Fatalf(`g["next"].URI = %q, want %q`, got, want)
	}

	if got, want := g["next"].Rel, "next"; got != want {
		t.Fatalf(`g["next"].Rel = %q, want %q`, got, want)
	}
}

func TestParseHeader_multiple(t *testing.T) {
	h := http.Header{}
	h.Add("Link", `<https://example.com/?page=2>; rel="next",<https://example.com/?page=34>; rel="last"`)

	g := ParseHeader(h)

	if got, want := len(g), 2; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["next"] == nil {
		t.Fatalf(`g["next"] == nil`)
	}

	if got, want := g["next"].URI, "https://example.com/?page=2"; got != want {
		t.Fatalf(`g["next"].URI = %q, want %q`, got, want)
	}

	if got, want := g["next"].Rel, "next"; got != want {
		t.Fatalf(`g["next"].Rel = %q, want %q`, got, want)
	}

	if g["last"] == nil {
		t.Fatalf(`g["last"] == nil`)
	}

	if got, want := g["last"].URI, "https://example.com/?page=34"; got != want {
		t.Fatalf(`g["last"].URI = %q, want %q`, got, want)
	}

	if got, want := g["last"].Rel, "last"; got != want {
		t.Fatalf(`g["last"].Rel = %q, want %q`, got, want)
	}
}

func TestParseHeader_multiple_headers(t *testing.T) {
	h := http.Header{}
	h.Add("Link", `<https://example.com/?page=2>; rel="next",<https://example.com/?page=34>; rel="last"`)
	h.Add("Link", `<https://example.com/?page=foo>; rel="foo",<https://example.com/?page=bar>; rel="bar"`)

	g := ParseHeader(h)

	if got, want := len(g), 4; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["foo"] == nil {
		t.Fatalf(`g["foo"] == nil`)
	}

	if got, want := g["bar"].URI, "https://example.com/?page=bar"; got != want {
		t.Fatalf(`g["bar"].URI = %q, want %q`, got, want)
	}

	if got, want := g["next"].Rel, "next"; got != want {
		t.Fatalf(`g["next"].Rel = %q, want %q`, got, want)
	}

	if g["last"] == nil {
		t.Fatalf(`g["last"] == nil`)
	}

	if got, want := g["last"].URI, "https://example.com/?page=34"; got != want {
		t.Fatalf(`g["last"].URI = %q, want %q`, got, want)
	}

	if got, want := g["last"].Rel, "last"; got != want {
		t.Fatalf(`g["last"].Rel = %q, want %q`, got, want)
	}
}

func TestParseHeader_extra(t *testing.T) {
	h := http.Header{}
	h.Add("Link", `<https://example.com/?page=2>; rel="next"; title="foo"`)

	g := ParseHeader(h)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["next"] == nil {
		t.Fatalf(`g["next"] == nil`)
	}

	if got, want := g["next"].Extra["title"], "foo"; got != want {
		t.Fatalf(`g["next"].Extra["title"] = %q, want %q`, got, want)
	}
}

func TestParseHeader_noLink(t *testing.T) {
	if ParseHeader(http.Header{}) != nil {
		t.Fatalf(`Parse(http.Header{}) != nil`)
	}
}

func TestParseHeader_nilHeader(t *testing.T) {
	if ParseHeader(nil) != nil {
		t.Fatalf(`ParseHeader(nil) != nil`)
	}
}

func TestParse_emptyString(t *testing.T) {
	if Parse("") != nil {
		t.Fatalf(`Parse("") != nil`)
	}
}

func TestParse_valuesWithComma(t *testing.T) {
	g := Parse(`<//www.w3.org/wiki/LinkHeader>; rel="original latest-version",<//www.w3.org/wiki/Special:TimeGate/LinkHeader>; rel="timegate",<//www.w3.org/wiki/Special:TimeMap/LinkHeader>; rel="timemap"; type="application/link-format"; from="Mon, 03 Sep 2007 14:52:48 GMT"; until="Tue, 16 Jun 2015 22:59:23 GMT",<//www.w3.org/wiki/index.php?title=LinkHeader&oldid=10152>; rel="first memento"; datetime="Mon, 03 Sep 2007 14:52:48 GMT",<//www.w3.org/wiki/index.php?title=LinkHeader&oldid=84697>; rel="last memento"; datetime="Tue, 16 Jun 2015 22:59:23 GMT"`)

	if got, want := len(g), 5; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if got, want := g["original latest-version"].URI, "//www.w3.org/wiki/LinkHeader"; got != want {
		t.Fatalf(`g["original latest-version"].URI = %q, want %q`, got, want)
	}

	if got, want := g["last memento"].Extra["datetime"], "Tue 16 Jun 2015 22:59:23 GMT"; got != want {
		t.Fatalf(`g["last memento"].Extra["datetime"] = %q, want %q`, got, want)
	}
}

func TestParse_rfc5988Example1(t *testing.T) {
	g := Parse(`<http://example.com/TheBook/chapter2>; rel="previous"; title="previous chapter"`)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["previous"] == nil {
		t.Fatalf(`g["previous"] == nil`)
	}

	if got, want := g["previous"].Extra["title"], "previous chapter"; got != want {
		t.Fatalf(`g["previous"].Extra["title"] = %q, want %q`, got, want)
	}
}

func TestParse_rfc5988Example2(t *testing.T) {
	g := Parse(`</>; rel="http://example.net/foo"`)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["http://example.net/foo"] == nil {
		t.Fatalf(`g["http://example.net/foo"] == nil`)
	}

	l := g["http://example.net/foo"]

	if got, want := l.URI, "/"; got != want {
		t.Fatalf(`l.URI = %q, want %q`, got, want)
	}
}

func TestParse_rfc5988Example3(t *testing.T) {
	// Extended notation is not supported yet
	// g := Parse(`</TheBook/chapter2>; rel="previous"; title*=UTF-8'de'letztes%20Kapitel, </TheBook/chapter4>; rel="next"; title*=UTF-8'de'n%c3%a4chstes%20Kapitel`)
}

func TestParse_rfc5988Example4(t *testing.T) {
	// Extension relation types are ignored for now
	g := Parse(`<http://example.org/>; rel="start http://example.net/relation/other"`)

	if got, want := len(g), 1; got != want {
		t.Fatalf(`len(g) = %d, want %d`, got, want)
	}

	if g["start"] == nil {
		t.Fatalf(`g["start"] == nil`)
	}

	if got, want := g["start"].URI, "http://example.org/"; got != want {
		t.Fatalf(`g["start"].URI = %q, want %q`, got, want)
	}
}

func TestParse_fuzzCrashers(t *testing.T) {
	Parse("0")
}

func ExampleParse() {
	l := Parse(`<https://example.com/?page=2>; rel="next"; title="foo"`)["next"]

	fmt.Printf("URI: %q, Rel: %q, Extra: %+v\n", l.URI, l.Rel, l.Extra)
	// Output: URI: "https://example.com/?page=2", Rel: "next", Extra: map[title:foo]
}