aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/Path.cpp
diff options
context:
space:
mode:
authorTareq A. Siraj <tareq.a.siraj@intel.com>2013-08-12 17:10:49 +0000
committerTareq A. Siraj <tareq.a.siraj@intel.com>2013-08-12 17:10:49 +0000
commit73537eac3d149f425e1c0febf03c6f2b6562ecbd (patch)
treef948a594a5e51dcf43c184aff1f6886727e0cee7 /llvm/unittests/Support/Path.cpp
parentf068d9ff14e78aa7d9b04647ff1783513b8c0370 (diff)
downloadllvm-73537eac3d149f425e1c0febf03c6f2b6562ecbd.zip
llvm-73537eac3d149f425e1c0febf03c6f2b6562ecbd.tar.gz
llvm-73537eac3d149f425e1c0febf03c6f2b6562ecbd.tar.bz2
Fixes a bug when iterating on paths
This fixes the incorrect implementation of iterating on file/directory paths. Differential Review: http://llvm-reviews.chandlerc.com/D1277 llvm-svn: 188183
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r--llvm/unittests/Support/Path.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index 6f5992b..cc8731b 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -141,6 +141,75 @@ TEST(Support, Path) {
}
}
+TEST(Support, RelativePathIterator) {
+ SmallString<64> Path(StringRef("c/d/e/foo.txt"));
+ typedef SmallVector<StringRef, 4> PathComponents;
+ PathComponents ExpectedPathComponents;
+ PathComponents ActualPathComponents;
+
+ StringRef(Path).split(ExpectedPathComponents, "/");
+
+ for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E;
+ ++I) {
+ ActualPathComponents.push_back(*I);
+ }
+
+ ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size());
+
+ for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) {
+ EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str());
+ }
+}
+
+TEST(Support, AbsolutePathIterator) {
+ SmallString<64> Path(StringRef("/c/d/e/foo.txt"));
+ typedef SmallVector<StringRef, 4> PathComponents;
+ PathComponents ExpectedPathComponents;
+ PathComponents ActualPathComponents;
+
+ StringRef(Path).split(ExpectedPathComponents, "/");
+
+ // The root path will also be a component when iterating
+ ExpectedPathComponents[0] = "/";
+
+ for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E;
+ ++I) {
+ ActualPathComponents.push_back(*I);
+ }
+
+ ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size());
+
+ for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) {
+ EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str());
+ }
+}
+
+#ifdef LLVM_ON_WIN32
+TEST(Support, AbsolutePathIteratorWin32) {
+ SmallString<64> Path(StringRef("c:\\c\\e\\foo.txt"));
+ typedef SmallVector<StringRef, 4> PathComponents;
+ PathComponents ExpectedPathComponents;
+ PathComponents ActualPathComponents;
+
+ StringRef(Path).split(ExpectedPathComponents, "\\");
+
+ // The root path (which comes after the drive name) will also be a component
+ // when iterating.
+ ExpectedPathComponents.insert(ExpectedPathComponents.begin()+1, "\\");
+
+ for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E;
+ ++I) {
+ ActualPathComponents.push_back(*I);
+ }
+
+ ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size());
+
+ for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) {
+ EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str());
+ }
+}
+#endif // LLVM_ON_WIN32
+
class FileSystemTest : public testing::Test {
protected:
/// Unique temporary directory in which all created filesystem entities must