diff --git a/Semantics.Paths/Primitives/DirectoryPath.cs b/Semantics.Paths/Primitives/DirectoryPath.cs index 3406dab..2edfcb4 100644 --- a/Semantics.Paths/Primitives/DirectoryPath.cs +++ b/Semantics.Paths/Primitives/DirectoryPath.cs @@ -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(combinedPath); } @@ -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(combinedPath); } @@ -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(combinedPath); } @@ -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(combinedPath); } } diff --git a/Semantics.Test/Paths/DirectoryNameRebuildTests.cs b/Semantics.Test/Paths/DirectoryNameRebuildTests.cs index 9308bf6..cd36e7d 100644 --- a/Semantics.Test/Paths/DirectoryNameRebuildTests.cs +++ b/Semantics.Test/Paths/DirectoryNameRebuildTests.cs @@ -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("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("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(".") / RelativeFilePath.Create("x.txt"); + + Assert.AreEqual("x.txt", combined.WeakString); + } + + [TestMethod] + public void DirectoryPath_Dot_SlashRelativeDirectoryPath_IsTheRelativeDirectoryPath() + { + DirectoryPath combined = DirectoryPath.Create(".") / RelativeDirectoryPath.Create("a"); + + Assert.AreEqual("a", combined.WeakString); + } + [TestMethod] public void RelativeDirectoryPath_ParentSlashName_IsTheSameDirectory() {