Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Semantics.Paths/Primitives/DirectoryPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public RelativeDirectoryPath AsRelative(AbsoluteDirectoryPath baseDirectory)
Ensure.NotNull(left);
Ensure.NotNull(right);

string combinedPath = Path.Combine(left.WeakString, right.WeakString);
string combinedPath = PooledStringBuilder.CombinePaths(left.WeakString, right.WeakString);
return Create<DirectoryPath>(combinedPath);
}

Expand All @@ -101,7 +101,7 @@ public RelativeDirectoryPath AsRelative(AbsoluteDirectoryPath baseDirectory)
Ensure.NotNull(left);
Ensure.NotNull(right);

string combinedPath = Path.Combine(left.WeakString, right.WeakString);
string combinedPath = PooledStringBuilder.CombinePaths(left.WeakString, right.WeakString);
return FilePath.Create<FilePath>(combinedPath);
}

Expand All @@ -117,7 +117,7 @@ public RelativeDirectoryPath AsRelative(AbsoluteDirectoryPath baseDirectory)
Ensure.NotNull(left);
Ensure.NotNull(right);

string combinedPath = Path.Combine(left.WeakString, right.WeakString);
string combinedPath = PooledStringBuilder.CombinePaths(left.WeakString, right.WeakString);
return Create<DirectoryPath>(combinedPath);
}

Expand All @@ -133,7 +133,7 @@ public RelativeDirectoryPath AsRelative(AbsoluteDirectoryPath baseDirectory)
Ensure.NotNull(left);
Ensure.NotNull(right);

string combinedPath = Path.Combine(left.WeakString, right.WeakString);
string combinedPath = PooledStringBuilder.CombinePaths(left.WeakString, right.WeakString);
return FilePath.Create<FilePath>(combinedPath);
}
}
39 changes: 39 additions & 0 deletions Semantics.Test/Paths/DirectoryNameRebuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,45 @@ public void DirectoryPath_ParentSlashName_IsTheSameDirectory()
Assert.AreEqual(dir, rebuilt);
}

[TestMethod]
public void DirectoryPath_SingleSegment_ParentSlashName_IsTheSameDirectory()
{
// The parent of "a" is "." (#504); combining it back must not give "./a" (#539).
DirectoryPath dir = DirectoryPath.Create<DirectoryPath>("a");

DirectoryPath rebuilt = dir.Parent / dir.Name;

Assert.AreEqual("a", rebuilt.WeakString);
Assert.AreEqual(dir, rebuilt);
}

[TestMethod]
public void FilePath_BareFileName_DirectorySlashFileName_IsTheSameFile()
{
FilePath file = FilePath.Create<FilePath>("x.txt");

FilePath rebuilt = file.DirectoryPath / file.FileName;

Assert.AreEqual("x.txt", rebuilt.WeakString);
Assert.AreEqual(file, rebuilt);
}

[TestMethod]
public void DirectoryPath_Dot_SlashRelativeFilePath_IsTheRelativeFilePath()
{
FilePath combined = DirectoryPath.Create<DirectoryPath>(".") / RelativeFilePath.Create<RelativeFilePath>("x.txt");

Assert.AreEqual("x.txt", combined.WeakString);
}

[TestMethod]
public void DirectoryPath_Dot_SlashRelativeDirectoryPath_IsTheRelativeDirectoryPath()
{
DirectoryPath combined = DirectoryPath.Create<DirectoryPath>(".") / RelativeDirectoryPath.Create<RelativeDirectoryPath>("a");

Assert.AreEqual("a", combined.WeakString);
}

[TestMethod]
public void RelativeDirectoryPath_ParentSlashName_IsTheSameDirectory()
{
Expand Down
Loading