diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-03-05 19:56:30 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-03-05 19:56:30 +0000 |
commit | 8d1163961293ae0d3bceb9d39693548824b59f18 (patch) | |
tree | d2a2ad200bb2c513c5a842ce7d5f32bc340eb1a5 /llvm/unittests/Support/Path.cpp | |
parent | d6ad741e5e78afb93b61abe9fb7c021702dab3d7 (diff) | |
download | llvm-8d1163961293ae0d3bceb9d39693548824b59f18.zip llvm-8d1163961293ae0d3bceb9d39693548824b59f18.tar.gz llvm-8d1163961293ae0d3bceb9d39693548824b59f18.tar.bz2 |
Fix an inconsistency in treatment of trailing / in path::const_iterator
When using a //net/ path, we were transforming the trailing / into a '.'
when the path was just the root path and we were iterating backwards.
Forwards iteration and other kinds of root path (C:\, /) were already
correct.
llvm-svn: 202999
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index c4067b9..29a77f3 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -210,6 +210,35 @@ TEST(Support, AbsolutePathIteratorWin32) { } #endif // LLVM_ON_WIN32 +TEST(Support, AbsolutePathIteratorEnd) { + // Trailing slashes are converted to '.' unless they are part of the root path. + SmallVector<StringRef, 4> Paths; + Paths.push_back("/foo/"); + Paths.push_back("/foo//"); + Paths.push_back("//net//"); +#ifdef LLVM_ON_WIN32 + Paths.push_back("c:\\\\"); +#endif + + for (StringRef Path : Paths) { + StringRef LastComponent = *--path::end(Path); + EXPECT_EQ(".", LastComponent); + } + + SmallVector<StringRef, 3> RootPaths; + RootPaths.push_back("/"); + RootPaths.push_back("//net/"); +#ifdef LLVM_ON_WIN32 + RootPaths.push_back("c:\\"); +#endif + + for (StringRef Path : RootPaths) { + StringRef LastComponent = *--path::end(Path); + EXPECT_EQ(1u, LastComponent.size()); + EXPECT_TRUE(path::is_separator(LastComponent[0])); + } +} + TEST(Support, HomeDirectory) { #ifdef LLVM_ON_UNIX // This test only makes sense on Unix if $HOME is set. |