[libcxx] [test] Fix path.decompose for windows

Add ifdefs to the test reference tables for cases where paths are
interpreted differently (paths that contain a root name).

Fix test assumptions regarding has_root_name() and is_absolute() and
add logic to verify the results of is_absolute() for the test cases in
the table.

Also add a testcase for the path "//net/", which seemed like an
omission.

Differential Revision: https://reviews.llvm.org/D89943
This commit is contained in:
Martin Storsjö 2020-10-15 12:52:56 +03:00
parent 2da21a1bd4
commit 1adaf48d23
1 changed files with 49 additions and 0 deletions

View File

@ -86,8 +86,15 @@ const PathDecomposeTestcase PathTestCases[] =
, {"/foo/", {"/", "foo", ""}, "/", "", "/", "foo/", "/foo", ""}
, {"foo/bar", {"foo","bar"}, "", "", "", "foo/bar", "foo", "bar"}
, {"/foo//bar", {"/","foo","bar"}, "/", "", "/", "foo/bar", "/foo", "bar"}
#ifdef _WIN32
, {"//net", {"//net"}, "//net", "//net", "", "", "//net", ""}
, {"//net/", {"//net", "/"}, "//net/", "//net", "/", "", "//net/", ""}
, {"//net/foo", {"//net", "/", "foo"}, "//net/", "//net", "/", "foo", "//net/", "foo"}
#else
, {"//net", {"/", "net"}, "/", "", "/", "net", "/", "net"}
, {"//net/", {"/", "net", ""}, "/", "", "/", "net/", "//net", ""}
, {"//net/foo", {"/", "net", "foo"}, "/", "", "/", "net/foo", "/net", "foo"}
#endif
, {"///foo///", {"/", "foo", ""}, "/", "", "/", "foo///", "///foo", ""}
, {"///foo///bar", {"/", "foo", "bar"}, "/", "", "/", "foo///bar", "///foo", "bar"}
, {"/.", {"/", "."}, "/", "", "/", ".", "/", "."}
@ -100,6 +107,15 @@ const PathDecomposeTestcase PathTestCases[] =
, {"foo/./bar", {"foo", ".", "bar"}, "", "", "", "foo/./bar", "foo/.", "bar"}
, {"foo/../", {"foo", "..", ""}, "", "", "", "foo/../", "foo/..", ""}
, {"foo/../bar", {"foo", "..", "bar"}, "", "", "", "foo/../bar", "foo/..", "bar"}
#ifdef _WIN32
, {"c:", {"c:"}, "c:", "c:", "", "", "c:", ""}
, {"c:/", {"c:", "/"}, "c:/", "c:", "/", "", "c:/", ""}
, {"c:foo", {"c:", "foo"}, "c:", "c:", "", "foo", "c:", "foo"}
, {"c:/foo", {"c:", "/", "foo"}, "c:/", "c:", "/", "foo", "c:/", "foo"}
, {"c:foo/", {"c:", "foo", ""}, "c:", "c:", "", "foo/", "c:foo", ""}
, {"c:/foo/", {"c:", "/", "foo", ""}, "c:/", "c:", "/", "foo/", "c:/foo", ""}
, {"c:/foo/bar", {"c:", "/", "foo", "bar"}, "c:/", "c:", "/", "foo/bar", "c:/foo", "bar"}
#else
, {"c:", {"c:"}, "", "", "", "c:", "", "c:"}
, {"c:/", {"c:", ""}, "", "", "", "c:/", "c:", ""}
, {"c:foo", {"c:foo"}, "", "", "", "c:foo", "", "c:foo"}
@ -107,13 +123,23 @@ const PathDecomposeTestcase PathTestCases[] =
, {"c:foo/", {"c:foo", ""}, "", "", "", "c:foo/", "c:foo", ""}
, {"c:/foo/", {"c:", "foo", ""}, "", "", "", "c:/foo/", "c:/foo", ""}
, {"c:/foo/bar", {"c:", "foo", "bar"}, "", "", "", "c:/foo/bar", "c:/foo", "bar"}
#endif
, {"prn:", {"prn:"}, "", "", "", "prn:", "", "prn:"}
#ifdef _WIN32
, {"c:\\", {"c:", "\\"}, "c:\\", "c:", "\\", "", "c:\\", ""}
, {"c:\\foo", {"c:", "\\", "foo"}, "c:\\", "c:", "\\", "foo", "c:\\", "foo"}
, {"c:foo\\", {"c:", "foo", ""}, "c:", "c:", "", "foo\\", "c:foo", ""}
, {"c:\\foo\\", {"c:", "\\", "foo", ""}, "c:\\", "c:", "\\", "foo\\", "c:\\foo", ""}
, {"c:\\foo/", {"c:", "\\", "foo", ""}, "c:\\", "c:", "\\", "foo/", "c:\\foo", ""}
, {"c:/foo\\bar", {"c:", "/", "foo", "bar"}, "c:\\", "c:", "\\", "foo\\bar", "c:/foo", "bar"}
#else
, {"c:\\", {"c:\\"}, "", "", "", "c:\\", "", "c:\\"}
, {"c:\\foo", {"c:\\foo"}, "", "", "", "c:\\foo", "", "c:\\foo"}
, {"c:foo\\", {"c:foo\\"}, "", "", "", "c:foo\\", "", "c:foo\\"}
, {"c:\\foo\\", {"c:\\foo\\"}, "", "", "", "c:\\foo\\", "", "c:\\foo\\"}
, {"c:\\foo/", {"c:\\foo", ""}, "", "", "", "c:\\foo/", "c:\\foo", ""}
, {"c:/foo\\bar", {"c:", "foo\\bar"}, "", "", "", "c:/foo\\bar", "c:", "foo\\bar"}
#endif
, {"//", {"/"}, "/", "", "/", "", "/", ""}
};
@ -127,7 +153,9 @@ void decompPathTest()
assert(p.root_path() == TC.root_path);
assert(p.has_root_path() != TC.root_path.empty());
#ifndef _WIN32
assert(p.root_name().native().empty());
#endif
assert(p.root_name() == TC.root_name);
assert(p.has_root_name() != TC.root_name.empty());
@ -143,7 +171,28 @@ void decompPathTest()
assert(p.filename() == TC.filename);
assert(p.has_filename() != TC.filename.empty());
#ifdef _WIN32
if (!p.has_root_name()) {
assert(p.is_absolute() == false);
} else {
std::string root_name = p.root_name().string();
assert(root_name.length() >= 2);
if (root_name[1] == ':') {
// Drive letter, absolute if has a root directory
assert(p.is_absolute() == p.has_root_directory());
} else {
// Possibly a server path
// Convert to one separator style, for simplicity
std::replace(root_name.begin(), root_name.end(), '\\', '/');
if (root_name[0] == '/' && root_name[1] == '/')
assert(p.is_absolute() == true);
else
assert(p.is_absolute() == false);
}
}
#else
assert(p.is_absolute() == p.has_root_directory());
#endif
assert(p.is_relative() != p.is_absolute());
if (p.empty())
assert(p.is_relative());