commit 065069e1fd004ea5b0e3f4329a330e269c132157
parent 3e89bf6ba32a8db35967afead04c3a18fc4c072c
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 3 Dec 2017 00:03:31 -0500
path: make Path("/").join() return "/" instead of empty string
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/path.cpp b/src/path.cpp
@@ -192,6 +192,9 @@ string Path::join(const bool nativeSeparator) const
path += part;
}
+ if(m_parts.empty() && absoluteSlash)
+ path += sep;
+
#ifdef _WIN32
if(m_absolute && path.size() > MAX_PATH)
path.insert(0, "\\\\?\\");
diff --git a/test/path.cpp b/test/path.cpp
@@ -179,6 +179,25 @@ TEST_CASE("absolute path", M) {
#endif
}
+TEST_CASE("absolute path (root only)", M) {
+#ifdef _WIN32
+ const Path a("C:");
+#else
+ const Path a("/");
+#endif
+
+ REQUIRE(a.absolute());
+
+#ifdef _WIN32
+ CHECK(a.size() == 1);
+ CHECK(a[0] == "C:");
+ CHECK(a.join() == "C:");
+#else
+ CHECK(a.size() == 0);
+ CHECK(a.join() == "/");
+#endif
+}
+
TEST_CASE("append absolute path to empty path", M) {
#ifdef _WIN32
const Path abs("C:\\Windows\\");