mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-05 14:34:55 +00:00
Don't treat .foo as two path components in path::iterators
We were treating '/.foo' as ['/', '.', 'foo'] instead of ['/', '.foo'], which lead to insanity. Same for '..'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231727 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8829ba195c
commit
5cb5adbe01
@ -49,7 +49,6 @@ namespace {
|
|||||||
// * empty (in this case we return an empty string)
|
// * empty (in this case we return an empty string)
|
||||||
// * either C: or {//,\\}net.
|
// * either C: or {//,\\}net.
|
||||||
// * {/,\}
|
// * {/,\}
|
||||||
// * {.,..}
|
|
||||||
// * {file,directory}name
|
// * {file,directory}name
|
||||||
|
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
@ -76,12 +75,6 @@ namespace {
|
|||||||
if (is_separator(path[0]))
|
if (is_separator(path[0]))
|
||||||
return path.substr(0, 1);
|
return path.substr(0, 1);
|
||||||
|
|
||||||
if (path.startswith(".."))
|
|
||||||
return path.substr(0, 2);
|
|
||||||
|
|
||||||
if (path[0] == '.')
|
|
||||||
return path.substr(0, 1);
|
|
||||||
|
|
||||||
// * {file,directory}name
|
// * {file,directory}name
|
||||||
size_t end = path.find_first_of(separators);
|
size_t end = path.find_first_of(separators);
|
||||||
return path.substr(0, end);
|
return path.substr(0, end);
|
||||||
|
@ -168,6 +168,26 @@ TEST(Support, RelativePathIterator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Support, RelativePathDotIterator) {
|
||||||
|
SmallString<64> Path(StringRef(".c/.d/../."));
|
||||||
|
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) {
|
TEST(Support, AbsolutePathIterator) {
|
||||||
SmallString<64> Path(StringRef("/c/d/e/foo.txt"));
|
SmallString<64> Path(StringRef("/c/d/e/foo.txt"));
|
||||||
typedef SmallVector<StringRef, 4> PathComponents;
|
typedef SmallVector<StringRef, 4> PathComponents;
|
||||||
@ -191,6 +211,29 @@ TEST(Support, AbsolutePathIterator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Support, AbsolutePathDotIterator) {
|
||||||
|
SmallString<64> Path(StringRef("/.c/.d/../."));
|
||||||
|
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
|
#ifdef LLVM_ON_WIN32
|
||||||
TEST(Support, AbsolutePathIteratorWin32) {
|
TEST(Support, AbsolutePathIteratorWin32) {
|
||||||
SmallString<64> Path(StringRef("c:\\c\\e\\foo.txt"));
|
SmallString<64> Path(StringRef("c:\\c\\e\\foo.txt"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user