[llvm] 0c1b88e - [Support][NFC] Tests for root_name(), root_directory() and root_path()
Jan Korous via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 01:13:48 PDT 2020
Author: Jan Korous
Date: 2020-06-04T01:13:35-07:00
New Revision: 0c1b88ec21926d79f28759d16a9386e0d7dc8a07
URL: https://github.com/llvm/llvm-project/commit/0c1b88ec21926d79f28759d16a9386e0d7dc8a07
DIFF: https://github.com/llvm/llvm-project/commit/0c1b88ec21926d79f28759d16a9386e0d7dc8a07.diff
LOG: [Support][NFC] Tests for root_name(), root_directory() and root_path()
It's literally just doc comments converted to unittests.
Added:
Modified:
llvm/unittests/Support/Path.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index 8e842a95b2b2..a0ddeb6c8c23 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -204,6 +204,71 @@ TEST(Support, Path) {
}
}
+TEST(Support, PathRoot) {
+ ASSERT_EQ(path::root_name("//net/hello", path::Style::posix).str(), "//net");
+ ASSERT_EQ(path::root_name("c:/hello", path::Style::posix).str(), "");
+ ASSERT_EQ(path::root_name("c:/hello", path::Style::windows).str(), "c:");
+ ASSERT_EQ(path::root_name("/hello", path::Style::posix).str(), "");
+
+ ASSERT_EQ(path::root_directory("/goo/hello", path::Style::posix).str(), "/");
+ ASSERT_EQ(path::root_directory("c:/hello", path::Style::windows).str(), "/");
+ ASSERT_EQ(path::root_directory("d/file.txt", path::Style::posix).str(), "");
+ ASSERT_EQ(path::root_directory("d/file.txt", path::Style::windows).str(), "");
+
+ SmallVector<StringRef, 40> paths;
+ paths.push_back("");
+ paths.push_back(".");
+ paths.push_back("..");
+ paths.push_back("foo");
+ paths.push_back("/");
+ paths.push_back("/foo");
+ paths.push_back("foo/");
+ paths.push_back("/foo/");
+ paths.push_back("foo/bar");
+ paths.push_back("/foo/bar");
+ paths.push_back("//net");
+ paths.push_back("//net/");
+ paths.push_back("//net/foo");
+ paths.push_back("///foo///");
+ paths.push_back("///foo///bar");
+ paths.push_back("/.");
+ paths.push_back("./");
+ paths.push_back("/..");
+ paths.push_back("../");
+ paths.push_back("foo/.");
+ paths.push_back("foo/..");
+ paths.push_back("foo/./");
+ paths.push_back("foo/./bar");
+ paths.push_back("foo/..");
+ paths.push_back("foo/../");
+ paths.push_back("foo/../bar");
+ paths.push_back("c:");
+ paths.push_back("c:/");
+ paths.push_back("c:foo");
+ paths.push_back("c:/foo");
+ paths.push_back("c:foo/");
+ paths.push_back("c:/foo/");
+ paths.push_back("c:/foo/bar");
+ paths.push_back("prn:");
+ paths.push_back("c:\\");
+ paths.push_back("c:foo");
+ paths.push_back("c:\\foo");
+ paths.push_back("c:foo\\");
+ paths.push_back("c:\\foo\\");
+ paths.push_back("c:\\foo/");
+ paths.push_back("c:/foo\\bar");
+
+ for (StringRef p : paths) {
+ ASSERT_EQ(
+ path::root_name(p, path::Style::posix).str() + path::root_directory(p, path::Style::posix).str(),
+ path::root_path(p, path::Style::posix).str());
+
+ ASSERT_EQ(
+ path::root_name(p, path::Style::windows).str() + path::root_directory(p, path::Style::windows).str(),
+ path::root_path(p, path::Style::windows).str());
+ }
+}
+
TEST(Support, FilenameParent) {
EXPECT_EQ("/", path::filename("/"));
EXPECT_EQ("", path::parent_path("/"));
More information about the llvm-commits
mailing list