summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/util/mapbox.test.cpp5
-rw-r--r--test/util/url.test.cpp182
2 files changed, 186 insertions, 1 deletions
diff --git a/test/util/mapbox.test.cpp b/test/util/mapbox.test.cpp
index 70bb8d0700..452106d6e6 100644
--- a/test/util/mapbox.test.cpp
+++ b/test/util/mapbox.test.cpp
@@ -91,7 +91,7 @@ TEST(Mapbox, SpriteURL) {
"https://api.mapbox.com/styles/v1/mapbox/streets-v8/draft/sprite@2x.png?access_token=key",
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "mapbox://sprites/mapbox/streets-v8/draft@2x.png", "key"));
EXPECT_EQ(
- "mapbox://sprites/mapbox/streets-v9?fresh=true.png",
+ "https://api.mapbox.com/styles/v1/mapbox/streets-v9/sprite?access_token=key&fresh=true.png",
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL,
"mapbox://sprites/mapbox/streets-v9?fresh=true.png",
"key"));
@@ -139,6 +139,9 @@ TEST(Mapbox, CanonicalURL) {
"mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf",
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector, 512));
EXPECT_EQ(
+ "mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf",
+ mbgl::util::mapbox::canonicalizeTileURL("https://api.mapbox.cn/v4/a.b/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector, 512));
+ EXPECT_EQ(
"mapbox://tiles/a.b,c.d/{z}/{x}/{y}.vector.pbf",
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b,c.d/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector, 512));
EXPECT_EQ(
diff --git a/test/util/url.test.cpp b/test/util/url.test.cpp
index c0ee30efab..00b761ce2e 100644
--- a/test/util/url.test.cpp
+++ b/test/util/url.test.cpp
@@ -23,3 +23,185 @@ TEST(URL, isURL) {
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);
+}