-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
core_url_test.go
111 lines (107 loc) · 2.11 KB
/
core_url_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
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
package requests
import (
"testing"
"github.com/carlmjohnson/requests/internal/be"
)
// PathCases is exported to share tests with requests_test
var PathCases = map[string]struct {
Base string
Paths []string
Result string
}{
"base-only": {
"example",
[]string{},
"https://example",
},
"base+abspath": {
"https://example",
[]string{"/a"},
"https://example/a",
},
"multi-abs-paths": {
"https://example",
[]string{"/a", "/b/", "/c"},
"https://example/c",
},
"base+rel-path": {
"https://example/a/",
[]string{"./b"},
"https://example/a/b",
},
"base+rel-paths": {
"https://example/a/",
[]string{"./b/", "./c"},
"https://example/a/b/c",
},
"rel-path": {
"https://example/",
[]string{"a/", "./b"},
"https://example/a/b",
},
"base+multi-paths": {
"https://example/a/",
[]string{"b/", "c"},
"https://example/a/b/c",
},
"base+slash+multi-paths": {
"https://example/a/",
[]string{"b/", "c"},
"https://example/a/b/c",
},
"multi-root": {
"https://example/",
[]string{"a", "b", "c"},
"https://example/c",
},
"dot-dot-paths": {
"https://example/",
[]string{"a/", "b/", "../c"},
"https://example/a/c",
},
"more-dot-dot-paths": {
"https://example/",
[]string{"a/b/c/", "../d/", "../e"},
"https://example/a/b/e",
},
"more-dot-dot-paths+rel-path": {
"https://example/",
[]string{"a/b/c/", "../d/", "../e/", "./f"},
"https://example/a/b/e/f",
},
"even-more-dot-dot-paths+base": {
"https://example/a/b/c/",
[]string{"../../d"},
"https://example/a/d",
},
"too-many-dot-dot-paths": {
"https://example",
[]string{"../a"},
"https://example/a",
},
"too-many-dot-dot-paths+base": {
"https://example/",
[]string{"../a"},
"https://example/a",
},
"last-abs-path-wins": {
"https://example/a/",
[]string{"b/", "c/", "/d"},
"https://example/d",
},
}
func TestCorePath(t *testing.T) {
t.Parallel()
for name, tc := range PathCases {
t.Run(name, func(t *testing.T) {
var b urlBuilder
b.BaseURL(tc.Base)
for _, p := range tc.Paths {
b.Path(p)
}
u, err := b.URL()
be.NilErr(t, err)
be.Equal(t, tc.Result, u.String())
})
}
}