summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-09-07 23:58:19 +0200
committerMax Kellermann <max@musicpd.org>2019-09-08 00:07:37 +0200
commit9caf90f74f536f0f92449b3feacacd6e20827637 (patch)
tree67d4937632bba240f1acb0cfab67a8e335b38d71 /test
parent71448e645c9e7c30486a0d3a2a021b9de6ecd8a0 (diff)
util/UriRelative: add uri_apply_relative()
Diffstat (limited to 'test')
-rw-r--r--test/TestUriRelative.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/TestUriRelative.cxx b/test/TestUriRelative.cxx
index 762a1e04e..75f52a1a2 100644
--- a/test/TestUriRelative.cxx
+++ b/test/TestUriRelative.cxx
@@ -50,3 +50,47 @@ TEST(UriRelative, ApplyBase)
EXPECT_STREQ(uri_apply_base(i.uri, i.base).c_str(), i.result);
}
}
+
+TEST(UriRelative, ApplyRelative)
+{
+ static constexpr struct {
+ const char *relative;
+ const char *base;
+ const char *result;
+ } tests[] = {
+ { "", "bar", "bar" },
+ { ".", "bar", "" },
+ { "foo", "bar", "foo" },
+ { "", "/bar", "/bar" },
+ { ".", "/bar", "/" },
+ { "foo", "/bar", "/foo" },
+ { "", "/bar/", "/bar/" },
+ { ".", "/bar/", "/bar/" },
+ { ".", "/bar/foo", "/bar/" },
+ { "/foo", "/bar/", "/foo" },
+ { "foo", "/bar/", "/bar/foo" },
+ { "../foo", "/bar/", "/foo" },
+ { "./foo", "/bar/", "/bar/foo" },
+ { "./../foo", "/bar/", "/foo" },
+ { ".././foo", "/bar/", "/foo" },
+ { "../../foo", "/bar/", "" },
+ { "/foo", "http://localhost/bar/", "http://localhost/foo" },
+ { "/foo", "http://localhost/bar", "http://localhost/foo" },
+ { "/foo", "http://localhost/", "http://localhost/foo" },
+ { "/foo", "http://localhost", "http://localhost/foo" },
+ { "/", "http://localhost", "http://localhost/" },
+ { "/", "http://localhost/bar", "http://localhost/" },
+ { "/", "http://localhost/bar/", "http://localhost/" },
+ { "/", "http://localhost/bar/foo", "http://localhost/" },
+ { "../foo", "http://localhost/bar/", "http://localhost/foo" },
+ { "../foo", "http://localhost/bar", "" },
+ { "../foo", "http://localhost/", "" },
+ { "../foo", "http://localhost", "" },
+ { ".", "http://localhost", "http://localhost/" },
+ };
+
+ for (const auto &i : tests) {
+ EXPECT_STREQ(uri_apply_relative(i.relative, i.base).c_str(),
+ i.result);
+ }
+}