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
|
#include <mbgl/test/util.hpp>
#include <mbgl/util/url.hpp>
#include <memory>
using namespace mbgl::util;
TEST(URL, isURL) {
EXPECT_TRUE(isURL("mapbox://foo"));
EXPECT_TRUE(isURL("mapbox://"));
EXPECT_TRUE(isURL("mapbox-test-scheme://foo"));
EXPECT_TRUE(isURL("mapbox+style://foo"));
EXPECT_TRUE(isURL("mapbox-2.0://foo"));
EXPECT_TRUE(isURL("mapbox99://foo"));
EXPECT_FALSE(isURL("mapbox:/"));
EXPECT_FALSE(isURL(" mapbox://"));
EXPECT_FALSE(isURL("://"));
EXPECT_FALSE(isURL("mapbox"));
EXPECT_FALSE(isURL("mapbox:foo"));
EXPECT_FALSE(isURL("mapbox:/foo"));
EXPECT_FALSE(isURL("test/mapbox://foo"));
EXPECT_FALSE(isURL("123://foo"));
}
TEST(URL, Scheme) {
EXPECT_EQ(URL::Segment({ 0, 4 }), URL("http://example.com/test?query=foo").scheme);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL("htt").scheme);
EXPECT_EQ(URL::Segment({ 0, 6 }), URL("mapbox://").scheme);
EXPECT_EQ(URL::Segment({ 0, 6 }), URL("mapbox:/#").scheme);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL("://").scheme);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL("").scheme);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL("http?query://baz").scheme);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL(":::").scheme);
EXPECT_EQ(URL::Segment({ 0, 4 }), URL("data:,Hello%2C%20World!").scheme);
EXPECT_EQ(URL::Segment({ 0, 4 }), URL("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D").scheme);
}
TEST(URL, Query) {
EXPECT_EQ(URL::Segment({ 23, 10 }), URL("http://example.com/test?query=foo").query);
EXPECT_EQ(URL::Segment({ 23, 10 }), URL("http://example.com/test?query=foo#page-2").query);
EXPECT_EQ(URL::Segment({ 23, 0 }), URL("http://example.com/test#query=foo?page-2").query);
EXPECT_EQ(URL::Segment({ 0, 10 }), URL("?query=foo").query);
EXPECT_EQ(URL::Segment({ 0, 10 }), URL("?query=foo#bar").query);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL("#?query=foo#bar").query);
EXPECT_EQ(URL::Segment({ 4, 12 }), URL("http?query://baz").query);
EXPECT_EQ(URL::Segment({ 9, 4 }), URL("mapbox://?bar").query);
EXPECT_EQ(URL::Segment({ 12, 0 }), URL("mapbox://bar").query);
EXPECT_EQ(URL::Segment({ 0, 0 }), URL("").query);
EXPECT_EQ(URL::Segment({ 3, 0 }), URL(":::").query);
EXPECT_EQ(URL::Segment({ 23, 0 }), URL("data:,Hello%2C%20World!").query);
EXPECT_EQ(URL::Segment({ 47, 0 }), URL("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D").query);
}
TEST(URL, Domain) {
EXPECT_EQ(URL::Segment({ 7, 11 }), URL("http://example.com/test?query=foo").domain);
EXPECT_EQ(URL::Segment({ 5, 11 }), URL("http:example.com/test?query=foo").domain);
EXPECT_EQ(URL::Segment({ 0, 3 }), URL("htt").domain);
EXPECT_EQ(URL::Segment({ 0, 4 }), URL("http?query://baz").domain);
EXPECT_EQ(URL::Segment({ 0, 6 }), URL("domain/foo?bar").domain);
EXPECT_EQ(URL::Segment({ 7, 0 }), URL("http://").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain#bar").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain/").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain/foo").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain/foo?").domain);
EXPECT_EQ(URL::Segment({ 0, 1 }), URL("h##p://domain/foo?bar").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain/foo?bar").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain/?").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain?").domain);
EXPECT_EQ(URL::Segment({ 7, 6 }), URL("http://domain?foo").domain);
EXPECT_EQ(URL::Segment({ 3, 0 }), URL(":::").domain);
EXPECT_EQ(URL::Segment({ 5, 0 }), URL("data:,Hello%2C%20World!").domain);
EXPECT_EQ(URL::Segment({ 5, 17 }), URL("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D").domain);
}
TEST(URL, Path) {
EXPECT_EQ(URL::Segment({ 19, 4 }), URL("http://example.com/test?query=foo").path);
EXPECT_EQ(URL::Segment({ 19, 4 }), URL("http://example.com/test?query=foo#bar").path);
EXPECT_EQ(URL::Segment({ 19, 4 }), URL("http://example.com/test#bar").path);
EXPECT_EQ(URL::Segment({ 18, 0 }), URL("http://example.com?query=foo").path);
EXPECT_EQ(URL::Segment({ 18, 0 }), URL("http://example.com#?query=foo").path);
EXPECT_EQ(URL::Segment({ 19, 0 }), URL("http://example.com/?query=foo").path);
EXPECT_EQ(URL::Segment({ 3, 0 }), URL(":::").path);
EXPECT_EQ(URL::Segment({ 13, 0 }), URL("http://domain").path);
EXPECT_EQ(URL::Segment({ 7, 3 }), URL("domain/foo?bar").path);
EXPECT_EQ(URL::Segment({ 6, 17 }), URL("data:,Hello%2C%20World!").path);
EXPECT_EQ(URL::Segment({ 23, 24 }), URL("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D").path);
}
auto URLPath = [](const char* str) { const URL url(str); return Path(str, url.path.first, url.path.second); };
TEST(Path, Directory) {
EXPECT_EQ(Path::Segment({ 0, 8 }), Path("foo/bar/baz.ext").directory);
EXPECT_EQ(Path::Segment({ 0, 8 }), Path("foo.bar/baz.ext").directory);
EXPECT_EQ(Path::Segment({ 0, 8 }), Path("foo.bar/baz").directory);
EXPECT_EQ(Path::Segment({ 0, 8 }), Path("foo/bar/.ext").directory);
EXPECT_EQ(Path::Segment({ 0, 4 }), Path("foo/bar@2x.png").directory);
EXPECT_EQ(Path::Segment({ 0, 4 }), Path("foo/b").directory);
EXPECT_EQ(Path::Segment({ 0, 4 }), Path("foo/").directory);
EXPECT_EQ(Path::Segment({ 0, 0 }), Path("foo").directory);
EXPECT_EQ(Path::Segment({ 0, 0 }), Path("foo.png").directory);
EXPECT_EQ(Path::Segment({ 0, 0 }), Path("").directory);
}
TEST(Path, URLDirectory) {
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/baz.ext").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/baz.ext?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz.ext").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz.ext?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/.ext").directory);
EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/.ext?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/bar@2x.png").directory);
EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/bar@2x.png?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/b").directory);
EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/b?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/").directory);
EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo").directory);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo.png").directory);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo.png?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/").directory);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com").directory);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com?query=foo.bar").directory);
}
TEST(Path, Extension) {
EXPECT_EQ(Path::Segment({ 11, 4 }), Path("foo/bar/baz.ext").extension);
EXPECT_EQ(Path::Segment({ 11, 4 }), Path("foo.bar/baz.ext").extension);
EXPECT_EQ(Path::Segment({ 18, 4 }), Path("foo.bar/baz.vector.pbf").extension);
EXPECT_EQ(Path::Segment({ 11, 0 }), Path("foo.bar/baz").extension);
EXPECT_EQ(Path::Segment({ 8, 4 }), Path("foo/bar/.ext").extension);
EXPECT_EQ(Path::Segment({ 7, 7 }), Path("foo/bar@2x.png").extension);
EXPECT_EQ(Path::Segment({ 5, 0 }), Path("foo/b").extension);
EXPECT_EQ(Path::Segment({ 4, 0 }), Path("foo/").extension);
EXPECT_EQ(Path::Segment({ 3, 0 }), Path("foo").extension);
EXPECT_EQ(Path::Segment({ 3, 4 }), Path("foo.png").extension);
EXPECT_EQ(Path::Segment({ 0, 0 }), Path("").extension);
}
TEST(Path, URLExtension) {
EXPECT_EQ(Path::Segment({ 30, 4 }), URLPath("http://example.com/foo/bar/baz.ext").extension);
EXPECT_EQ(Path::Segment({ 30, 4 }), URLPath("http://example.com/foo/bar/baz.ext?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 30, 4 }), URLPath("http://example.com/foo.bar/baz.ext").extension);
EXPECT_EQ(Path::Segment({ 30, 4 }), URLPath("http://example.com/foo.bar/baz.ext?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 30, 0 }), URLPath("http://example.com/foo.bar/baz").extension);
EXPECT_EQ(Path::Segment({ 30, 0 }), URLPath("http://example.com/foo.bar/baz?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 27, 4 }), URLPath("http://example.com/foo/bar/.ext").extension);
EXPECT_EQ(Path::Segment({ 27, 4 }), URLPath("http://example.com/foo/bar/.ext?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 26, 7 }), URLPath("http://example.com/foo/bar@2x.png").extension);
EXPECT_EQ(Path::Segment({ 26, 7 }), URLPath("http://example.com/foo/bar@2x.png?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 24, 0 }), URLPath("http://example.com/foo/b").extension);
EXPECT_EQ(Path::Segment({ 24, 0 }), URLPath("http://example.com/foo/b?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 23, 0 }), URLPath("http://example.com/foo/").extension);
EXPECT_EQ(Path::Segment({ 23, 0 }), URLPath("http://example.com/foo/?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 22, 0 }), URLPath("http://example.com/foo").extension);
EXPECT_EQ(Path::Segment({ 22, 0 }), URLPath("http://example.com/foo?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 22, 4 }), URLPath("http://example.com/foo.png").extension);
EXPECT_EQ(Path::Segment({ 22, 4 }), URLPath("http://example.com/foo.png?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/").extension);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/?query=foo.bar").extension);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com").extension);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com?query=foo.bar").extension);
}
TEST(Path, Filename) {
EXPECT_EQ(Path::Segment({ 8, 3 }), Path("foo/bar/baz.ext").filename);
EXPECT_EQ(Path::Segment({ 8, 3 }), Path("foo.bar/baz.ext").filename);
EXPECT_EQ(Path::Segment({ 8, 3 }), Path("foo.bar/baz").filename);
EXPECT_EQ(Path::Segment({ 8, 0 }), Path("foo/bar/.ext").filename);
EXPECT_EQ(Path::Segment({ 4, 3 }), Path("foo/bar@2x.png").filename);
EXPECT_EQ(Path::Segment({ 4, 1 }), Path("foo/b").filename);
EXPECT_EQ(Path::Segment({ 4, 0 }), Path("foo/").filename);
EXPECT_EQ(Path::Segment({ 0, 3 }), Path("foo").filename);
EXPECT_EQ(Path::Segment({ 0, 3 }), Path("foo.png").filename);
EXPECT_EQ(Path::Segment({ 0, 0 }), Path("").filename);
}
TEST(Path, URLFilename) {
EXPECT_EQ(Path::Segment({ 27, 3 }), URLPath("http://example.com/foo/bar/baz.ext").filename);
EXPECT_EQ(Path::Segment({ 27, 3 }), URLPath("http://example.com/foo/bar/baz.ext?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 27, 3 }), URLPath("http://example.com/foo.bar/baz.ext").filename);
EXPECT_EQ(Path::Segment({ 27, 3 }), URLPath("http://example.com/foo.bar/baz.ext?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 27, 3 }), URLPath("http://example.com/foo.bar/baz").filename);
EXPECT_EQ(Path::Segment({ 27, 3 }), URLPath("http://example.com/foo.bar/baz?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 27, 0 }), URLPath("http://example.com/foo/bar/.ext").filename);
EXPECT_EQ(Path::Segment({ 27, 0 }), URLPath("http://example.com/foo/bar/.ext?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 23, 3 }), URLPath("http://example.com/foo/bar@2x.png").filename);
EXPECT_EQ(Path::Segment({ 23, 3 }), URLPath("http://example.com/foo/bar@2x.png?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 23, 1 }), URLPath("http://example.com/foo/b").filename);
EXPECT_EQ(Path::Segment({ 23, 1 }), URLPath("http://example.com/foo/b?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 23, 0 }), URLPath("http://example.com/foo/").filename);
EXPECT_EQ(Path::Segment({ 23, 0 }), URLPath("http://example.com/foo/?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 19, 3 }), URLPath("http://example.com/foo").filename);
EXPECT_EQ(Path::Segment({ 19, 3 }), URLPath("http://example.com/foo?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 19, 3 }), URLPath("http://example.com/foo.png").filename);
EXPECT_EQ(Path::Segment({ 19, 3 }), URLPath("http://example.com/foo.png?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/").filename);
EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/?query=foo.bar").filename);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com").filename);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com?query=foo.bar").filename);
}
|