@@ -2066,128 +2066,155 @@ func BenchmarkPathUnescape(b *testing.B) {
2066
2066
2067
2067
func TestJoinPath (t * testing.T ) {
2068
2068
tests := []struct {
2069
- base string
2070
- elem []string
2071
- out string
2069
+ base string
2070
+ elem []string
2071
+ out string
2072
+ wantPath string
2073
+ wantRawPath string
2072
2074
}{
2073
2075
{
2074
- base : "https://go.googlesource.com" ,
2075
- elem : []string {"go" },
2076
- out : "https://go.googlesource.com/go" ,
2076
+ base : "https://go.googlesource.com" ,
2077
+ elem : []string {"go" },
2078
+ out : "https://go.googlesource.com/go" ,
2079
+ wantPath : "/go" ,
2077
2080
},
2078
2081
{
2079
- base : "https://go.googlesource.com/a/b/c" ,
2080
- elem : []string {"../../../go" },
2081
- out : "https://go.googlesource.com/go" ,
2082
+ base : "https://go.googlesource.com/a/b/c" ,
2083
+ elem : []string {"../../../go" },
2084
+ out : "https://go.googlesource.com/go" ,
2085
+ wantPath : "/go" ,
2082
2086
},
2083
2087
{
2084
- base : "https://go.googlesource.com/" ,
2085
- elem : []string {"../go" },
2086
- out : "https://go.googlesource.com/go" ,
2088
+ base : "https://go.googlesource.com/" ,
2089
+ elem : []string {"../go" },
2090
+ out : "https://go.googlesource.com/go" ,
2091
+ wantPath : "/go" ,
2087
2092
},
2088
2093
{
2089
- base : "https://go.googlesource.com" ,
2090
- elem : []string {"../go" },
2091
- out : "https://go.googlesource.com/go" ,
2094
+ base : "https://go.googlesource.com" ,
2095
+ elem : []string {"../go" },
2096
+ out : "https://go.googlesource.com/go" ,
2097
+ wantPath : "/go" ,
2092
2098
},
2093
2099
{
2094
- base : "https://go.googlesource.com" ,
2095
- elem : []string {"../go" , "../../go" , "../../../go" },
2096
- out : "https://go.googlesource.com/go" ,
2100
+ base : "https://go.googlesource.com" ,
2101
+ elem : []string {"../go" , "../../go" , "../../../go" },
2102
+ out : "https://go.googlesource.com/go" ,
2103
+ wantPath : "/go" ,
2097
2104
},
2098
2105
{
2099
- base : "https://go.googlesource.com/../go" ,
2100
- elem : nil ,
2101
- out : "https://go.googlesource.com/go" ,
2106
+ base : "https://go.googlesource.com/../go" ,
2107
+ elem : nil ,
2108
+ out : "https://go.googlesource.com/go" ,
2109
+ wantPath : "/go" ,
2102
2110
},
2103
2111
{
2104
- base : "https://go.googlesource.com/" ,
2105
- elem : []string {"./go" },
2106
- out : "https://go.googlesource.com/go" ,
2112
+ base : "https://go.googlesource.com/" ,
2113
+ elem : []string {"./go" },
2114
+ out : "https://go.googlesource.com/go" ,
2115
+ wantPath : "/go" ,
2107
2116
},
2108
2117
{
2109
- base : "https://go.googlesource.com//" ,
2110
- elem : []string {"/go" },
2111
- out : "https://go.googlesource.com/go" ,
2118
+ base : "https://go.googlesource.com//" ,
2119
+ elem : []string {"/go" },
2120
+ out : "https://go.googlesource.com/go" ,
2121
+ wantPath : "/go" ,
2112
2122
},
2113
2123
{
2114
- base : "https://go.googlesource.com//" ,
2115
- elem : []string {"/go" , "a" , "b" , "c" },
2116
- out : "https://go.googlesource.com/go/a/b/c" ,
2124
+ base : "https://go.googlesource.com//" ,
2125
+ elem : []string {"/go" , "a" , "b" , "c" },
2126
+ out : "https://go.googlesource.com/go/a/b/c" ,
2127
+ wantPath : "/go/a/b/c" ,
2117
2128
},
2118
2129
{
2119
2130
base : "http://[fe80::1%en0]:8080/" ,
2120
2131
elem : []string {"/go" },
2121
2132
},
2122
2133
{
2123
- base : "https://go.googlesource.com" ,
2124
- elem : []string {"go/" },
2125
- out : "https://go.googlesource.com/go/" ,
2134
+ base : "https://go.googlesource.com" ,
2135
+ elem : []string {"go/" },
2136
+ out : "https://go.googlesource.com/go/" ,
2137
+ wantPath : "/go/" ,
2126
2138
},
2127
2139
{
2128
- base : "https://go.googlesource.com" ,
2129
- elem : []string {"go//" },
2130
- out : "https://go.googlesource.com/go/" ,
2140
+ base : "https://go.googlesource.com" ,
2141
+ elem : []string {"go//" },
2142
+ out : "https://go.googlesource.com/go/" ,
2143
+ wantPath : "/go/" ,
2131
2144
},
2132
2145
{
2133
- base : "https://go.googlesource.com" ,
2134
- elem : nil ,
2135
- out : "https://go.googlesource.com/" ,
2146
+ base : "https://go.googlesource.com" ,
2147
+ elem : nil ,
2148
+ out : "https://go.googlesource.com/" ,
2149
+ wantPath : "/" ,
2136
2150
},
2137
2151
{
2138
- base : "https://go.googlesource.com/" ,
2139
- elem : nil ,
2140
- out : "https://go.googlesource.com/" ,
2152
+ base : "https://go.googlesource.com/" ,
2153
+ elem : nil ,
2154
+ out : "https://go.googlesource.com/" ,
2155
+ wantPath : "/" ,
2141
2156
},
2142
2157
{
2143
- base : "https://go.googlesource.com/a%2fb" ,
2144
- elem : []string {"c" },
2145
- out : "https://go.googlesource.com/a%2fb/c" ,
2158
+ base : "https://go.googlesource.com/a%2fb" ,
2159
+ elem : []string {"c" },
2160
+ out : "https://go.googlesource.com/a%2fb/c" ,
2161
+ wantPath : "/a/b/c" ,
2162
+ wantRawPath : "/a%2fb/c" ,
2146
2163
},
2147
2164
{
2148
- base : "https://go.googlesource.com/a%2fb" ,
2149
- elem : []string {"c%2fd" },
2150
- out : "https://go.googlesource.com/a%2fb/c%2fd" ,
2165
+ base : "https://go.googlesource.com/a%2fb" ,
2166
+ elem : []string {"c%2fd" },
2167
+ out : "https://go.googlesource.com/a%2fb/c%2fd" ,
2168
+ wantPath : "/a/b/c/d" ,
2169
+ wantRawPath : "/a%2fb/c%2fd" ,
2151
2170
},
2152
2171
{
2153
- base : "https://go.googlesource.com/a/b" ,
2154
- elem : []string {"/go" },
2155
- out : "https://go.googlesource.com/a/b/go" ,
2172
+ base : "https://go.googlesource.com/a/b" ,
2173
+ elem : []string {"/go" },
2174
+ out : "https://go.googlesource.com/a/b/go" ,
2175
+ wantPath : "/a/b/go" ,
2156
2176
},
2157
2177
{
2158
- base : "/" ,
2159
- elem : nil ,
2160
- out : "/" ,
2178
+ base : "/" ,
2179
+ elem : nil ,
2180
+ out : "/" ,
2181
+ wantPath : "/" ,
2161
2182
},
2162
2183
{
2163
- base : "a" ,
2164
- elem : nil ,
2165
- out : "a" ,
2184
+ base : "a" ,
2185
+ elem : nil ,
2186
+ out : "a" ,
2187
+ wantPath : "a" ,
2166
2188
},
2167
2189
{
2168
- base : "a" ,
2169
- elem : []string {"b" },
2170
- out : "a/b" ,
2190
+ base : "a" ,
2191
+ elem : []string {"b" },
2192
+ out : "a/b" ,
2193
+ wantPath : "a/b" ,
2171
2194
},
2172
2195
{
2173
- base : "a" ,
2174
- elem : []string {"../b" },
2175
- out : "b" ,
2196
+ base : "a" ,
2197
+ elem : []string {"../b" },
2198
+ out : "b" ,
2199
+ wantPath : "b" ,
2176
2200
},
2177
2201
{
2178
- base : "a" ,
2179
- elem : []string {"../../b" },
2180
- out : "b" ,
2202
+ base : "a" ,
2203
+ elem : []string {"../../b" },
2204
+ out : "b" ,
2205
+ wantPath : "b" ,
2181
2206
},
2182
2207
{
2183
- base : "" ,
2184
- elem : []string {"a" },
2185
- out : "a" ,
2208
+ base : "" ,
2209
+ elem : []string {"a" },
2210
+ out : "/a" ,
2211
+ wantPath : "/a" ,
2186
2212
},
2187
2213
{
2188
- base : "" ,
2189
- elem : []string {"../a" },
2190
- out : "a" ,
2214
+ base : "" ,
2215
+ elem : []string {"../a" },
2216
+ out : "/a" ,
2217
+ wantPath : "/a" ,
2191
2218
},
2192
2219
}
2193
2220
for _ , tt := range tests {
@@ -2207,5 +2234,14 @@ func TestJoinPath(t *testing.T) {
2207
2234
if out != tt .out || (err == nil ) != (tt .out != "" ) {
2208
2235
t .Errorf ("Parse(%q).JoinPath(%q) = %q, %v, want %q, %v" , tt .base , tt .elem , out , err , tt .out , wantErr )
2209
2236
}
2237
+ if u == nil {
2238
+ continue
2239
+ }
2240
+ if got , want := u .Path , tt .wantPath ; got != want {
2241
+ t .Errorf ("Parse(%q).JoinPath(%q).Path = %q, want %q" , tt .base , tt .elem , got , want )
2242
+ }
2243
+ if got , want := u .RawPath , tt .wantRawPath ; got != want {
2244
+ t .Errorf ("Parse(%q).JoinPath(%q).RawPath = %q, want %q" , tt .base , tt .elem , got , want )
2245
+ }
2210
2246
}
2211
2247
}
0 commit comments