2 * Copyright 2013 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "folly/Uri.h"
19 #include <glog/logging.h>
20 #include <gtest/gtest.h>
22 using namespace folly;
30 fbstring s("http://www.facebook.com/hello/world?query#fragment");
32 EXPECT_EQ("http", u.scheme());
33 EXPECT_EQ("", u.username());
34 EXPECT_EQ("", u.password());
35 EXPECT_EQ("www.facebook.com", u.host());
36 EXPECT_EQ(0, u.port());
37 EXPECT_EQ("/hello/world", u.path());
38 EXPECT_EQ("query", u.query());
39 EXPECT_EQ("fragment", u.fragment());
40 EXPECT_EQ(s, u.fbstr()); // canonical
44 fbstring s("http://www.facebook.com:8080/hello/world?query#fragment");
46 EXPECT_EQ("http", u.scheme());
47 EXPECT_EQ("", u.username());
48 EXPECT_EQ("", u.password());
49 EXPECT_EQ("www.facebook.com", u.host());
50 EXPECT_EQ(8080, u.port());
51 EXPECT_EQ("/hello/world", u.path());
52 EXPECT_EQ("query", u.query());
53 EXPECT_EQ("fragment", u.fragment());
54 EXPECT_EQ(s, u.fbstr()); // canonical
58 fbstring s("http://127.0.0.1:8080/hello/world?query#fragment");
60 EXPECT_EQ("http", u.scheme());
61 EXPECT_EQ("", u.username());
62 EXPECT_EQ("", u.password());
63 EXPECT_EQ("127.0.0.1", u.host());
64 EXPECT_EQ(8080, u.port());
65 EXPECT_EQ("/hello/world", u.path());
66 EXPECT_EQ("query", u.query());
67 EXPECT_EQ("fragment", u.fragment());
68 EXPECT_EQ(s, u.fbstr()); // canonical
72 fbstring s("http://[::1]:8080/hello/world?query#fragment");
74 EXPECT_EQ("http", u.scheme());
75 EXPECT_EQ("", u.username());
76 EXPECT_EQ("", u.password());
77 EXPECT_EQ("[::1]", u.host());
78 EXPECT_EQ(8080, u.port());
79 EXPECT_EQ("/hello/world", u.path());
80 EXPECT_EQ("query", u.query());
81 EXPECT_EQ("fragment", u.fragment());
82 EXPECT_EQ(s, u.fbstr()); // canonical
86 fbstring s("http://user:pass@host.com/");
88 EXPECT_EQ("http", u.scheme());
89 EXPECT_EQ("user", u.username());
90 EXPECT_EQ("pass", u.password());
91 EXPECT_EQ("host.com", u.host());
92 EXPECT_EQ(0, u.port());
93 EXPECT_EQ("/", u.path());
94 EXPECT_EQ("", u.query());
95 EXPECT_EQ("", u.fragment());
96 EXPECT_EQ(s, u.fbstr());
100 fbstring s("http://user@host.com/");
102 EXPECT_EQ("http", u.scheme());
103 EXPECT_EQ("user", u.username());
104 EXPECT_EQ("", u.password());
105 EXPECT_EQ("host.com", u.host());
106 EXPECT_EQ(0, u.port());
107 EXPECT_EQ("/", u.path());
108 EXPECT_EQ("", u.query());
109 EXPECT_EQ("", u.fragment());
110 EXPECT_EQ(s, u.fbstr());
114 fbstring s("http://user:@host.com/");
116 EXPECT_EQ("http", u.scheme());
117 EXPECT_EQ("user", u.username());
118 EXPECT_EQ("", u.password());
119 EXPECT_EQ("host.com", u.host());
120 EXPECT_EQ(0, u.port());
121 EXPECT_EQ("/", u.path());
122 EXPECT_EQ("", u.query());
123 EXPECT_EQ("", u.fragment());
124 EXPECT_EQ("http://user@host.com/", u.fbstr());
128 fbstring s("http://:pass@host.com/");
130 EXPECT_EQ("http", u.scheme());
131 EXPECT_EQ("", u.username());
132 EXPECT_EQ("pass", u.password());
133 EXPECT_EQ("host.com", u.host());
134 EXPECT_EQ(0, u.port());
135 EXPECT_EQ("/", u.path());
136 EXPECT_EQ("", u.query());
137 EXPECT_EQ("", u.fragment());
138 EXPECT_EQ(s, u.fbstr());
142 fbstring s("http://@host.com/");
144 EXPECT_EQ("http", u.scheme());
145 EXPECT_EQ("", u.username());
146 EXPECT_EQ("", u.password());
147 EXPECT_EQ("host.com", u.host());
148 EXPECT_EQ(0, u.port());
149 EXPECT_EQ("/", u.path());
150 EXPECT_EQ("", u.query());
151 EXPECT_EQ("", u.fragment());
152 EXPECT_EQ("http://host.com/", u.fbstr());
156 fbstring s("http://:@host.com/");
158 EXPECT_EQ("http", u.scheme());
159 EXPECT_EQ("", u.username());
160 EXPECT_EQ("", u.password());
161 EXPECT_EQ("host.com", u.host());
162 EXPECT_EQ(0, u.port());
163 EXPECT_EQ("/", u.path());
164 EXPECT_EQ("", u.query());
165 EXPECT_EQ("", u.fragment());
166 EXPECT_EQ("http://host.com/", u.fbstr());
170 fbstring s("file:///etc/motd");
172 EXPECT_EQ("file", u.scheme());
173 EXPECT_EQ("", u.username());
174 EXPECT_EQ("", u.password());
175 EXPECT_EQ("", u.host());
176 EXPECT_EQ(0, u.port());
177 EXPECT_EQ("/etc/motd", u.path());
178 EXPECT_EQ("", u.query());
179 EXPECT_EQ("", u.fragment());
180 EXPECT_EQ(s, u.fbstr());
184 fbstring s("file:/etc/motd");
186 EXPECT_EQ("file", u.scheme());
187 EXPECT_EQ("", u.username());
188 EXPECT_EQ("", u.password());
189 EXPECT_EQ("", u.host());
190 EXPECT_EQ(0, u.port());
191 EXPECT_EQ("/etc/motd", u.path());
192 EXPECT_EQ("", u.query());
193 EXPECT_EQ("", u.fragment());
194 EXPECT_EQ("file:///etc/motd", u.fbstr());
198 fbstring s("file://etc/motd");
200 EXPECT_EQ("file", u.scheme());
201 EXPECT_EQ("", u.username());
202 EXPECT_EQ("", u.password());
203 EXPECT_EQ("etc", u.host());
204 EXPECT_EQ(0, u.port());
205 EXPECT_EQ("/motd", u.path());
206 EXPECT_EQ("", u.query());
207 EXPECT_EQ("", u.fragment());
208 EXPECT_EQ(s, u.fbstr());
211 EXPECT_THROW({Uri("2http://www.facebook.com/");},
212 std::invalid_argument);