-
Notifications
You must be signed in to change notification settings - Fork 0
/
link_test.go
83 lines (78 loc) · 1.9 KB
/
link_test.go
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
package golem
import (
"net/url"
"testing"
)
type ResolvData struct {
link url.URL
rel url.URL
result string
}
func TestResolveLink(t *testing.T) {
var ResolvTestData []ResolvData = []ResolvData{
{ // 1
link: parseUrl("../bar"),
rel: parseUrl("http://example.com/foo"),
result: "http://example.com/bar",
},
{ // 2
link: parseUrl("../bar"),
rel: parseUrl("http://example.com/foo/"),
result: "http://example.com/bar",
},
{ // 3
link: parseUrl("../../bar"),
rel: parseUrl("http://example.com/foo"),
result: "http://example.com/bar",
},
{ // 4
link: parseUrl("/bar"),
rel: parseUrl("http://example.com/foo"),
result: "http://example.com/bar",
},
{ // 5
link: parseUrl("bar"),
rel: parseUrl("http://example.com/foo"),
result: "http://example.com/foo/bar",
},
{ // 6
link: parseUrl("../bar"),
rel: parseUrl("http://example.com/foo/tar"),
result: "http://example.com/foo/bar",
},
{ // 7
link: parseUrl("../"),
rel: parseUrl("http://example.com/foo/"),
result: "http://example.com/",
},
{ // 8
link: parseUrl("/"),
rel: parseUrl("http://example.com/foo/"),
result: "http://example.com/",
},
{ // 9
link: parseUrl("//"),
rel: parseUrl("http://example.com/foo/"),
result: "http://example.com",
},
{ // 10
link: parseUrl("/../"),
rel: parseUrl("http://example.com/foo/"),
result: "http://example.com/../", // Note: is this correct?
},
{ // 10
link: parseUrl("%2E%2E/"),
rel: parseUrl("http://example.com/foo/"),
result: "http://example.com/foo/../",
},
}
for i, test := range ResolvTestData {
if result := ResolveLink(&test.link, &test.rel); result.String() != test.result {
t.Errorf("test %v: Expected %v got %v", i+1, test.result, result.String())
}
}
}
func parseUrl(l string) url.URL {
link, _ := url.Parse(l)
return *link
}