Skip to content

Commit

Permalink
(cake-build#3352) Add (DirectoryPath + ConvertableDirectoryPath) oper…
Browse files Browse the repository at this point in the history
…ator to ConvertableDirectoryPath
  • Loading branch information
augustoproiete committed Oct 5, 2021
1 parent f033c46 commit 83d3f86
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,57 @@ public void Should_Throw_If_Right_Operand_Is_Null()
}
}

public sealed class AddingDirectoryPathAndConvertableDirectoryPath
{
[Fact]
public void Should_Combine_The_Two_Paths()
{
// Given
var path = new DirectoryPath("./root");

// When
var result = path + new ConvertableDirectoryPath("other");

// Then
Assert.Equal("root/other", result.Path.FullPath);
}

[Fact]
public void Should_Return_A_New_Convertable_Directory_Path()
{
// Given
var path = new DirectoryPath("./root");

// When
var result = path + new ConvertableDirectoryPath("other");

// Then
Assert.IsType<ConvertableDirectoryPath>(result);
}

[Fact]
public void Should_Throw_If_Left_Operand_Is_Null()
{
// Given, When
var result = Record.Exception(() =>
(DirectoryPath)null + new ConvertableDirectoryPath("other"));

// Then
AssertEx.IsArgumentNullException(result, "left");
}

[Fact]
public void Should_Throw_If_Right_Operand_Is_Null()
{
// Given, When
var result = Record.Exception(() =>
new DirectoryPath("./root") + (ConvertableDirectoryPath)null);

// Then
AssertEx.IsArgumentNullException(result, "right");
}
}

public sealed class AddingConvertableFilePath
{
[Fact]
Expand Down
22 changes: 22 additions & 0 deletions src/Cake.Common/IO/Paths/ConvertableDirectoryPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ internal ConvertableDirectoryPath(DirectoryPath path)
return new ConvertableDirectoryPath(left.Path.Combine(right.Path));
}

/// <summary>
/// Operator that combines A <see cref="DirectoryPath"/> instance
/// with a <see cref="ConvertableDirectoryPath"/> instance.
/// </summary>
/// <param name="left">The left directory path operand.</param>
/// <param name="right">The right directory path operand.</param>
/// <returns>A new directory path representing a combination of the two provided paths.</returns>
public static ConvertableDirectoryPath operator +(DirectoryPath left, ConvertableDirectoryPath right)
{
if (left is null)
{
throw new ArgumentNullException(nameof(left));
}

if (right is null)
{
throw new ArgumentNullException(nameof(right));
}

return new ConvertableDirectoryPath(left.Combine(right));
}

/// <summary>
/// Operator that combines A <see cref="ConvertableDirectoryPath"/> instance
/// with a <see cref="DirectoryPath"/> instance.
Expand Down
45 changes: 44 additions & 1 deletion tests/integration/Cake.Common/IO/DirectoryAliases.cake
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,45 @@ Task("Cake.Common.IO.DirectoryAliases.MakeRelative.WorkingDirectory")
Assert.Equal("temp/hello/world/test.cake", relativeFilePath.ToString());
});

Task("Cake.Common.IO.Paths.ConvertableDirectoryPath.DirectoryPathPlusConvertableDirectoryPath")
.Does(context =>
{
// Given
var directoryPath = new DirectoryPath("./root");
// When
var result = directoryPath + context.Directory("other");
// Then
Assert.Equal("root/other", result.ToString());
});

Task("Cake.Common.IO.Paths.ConvertableDirectoryPath.ConvertableDirectoryPathPlusDirectoryPath")
.Does(context =>
{
// Given
var convertableDirectoryPath = context.Directory("./root");
// When
var result = convertableDirectoryPath + new DirectoryPath("other");
// Then
Assert.Equal("root/other", result.ToString());
});

Task("Cake.Common.IO.Paths.ConvertableDirectoryPath.ConvertableDirectoryPathPlusConvertableDirectoryPath")
.Does(context =>
{
// Given
var convertableDirectoryPath = context.Directory("./root");
// When
var result = convertableDirectoryPath + context.Directory("other");
// Then
Assert.Equal("root/other", result.ToString());
});

//////////////////////////////////////////////////////////////////////////////

Task("Cake.Common.IO.DirectoryAliases")
Expand All @@ -215,4 +254,8 @@ Task("Cake.Common.IO.DirectoryAliases")
.IsDependentOn("Cake.Common.IO.DirectoryAliases.DeleteDirectories")
.IsDependentOn("Cake.Common.IO.DirectoryAliases.DeleteDirectories.Recurse")
.IsDependentOn("Cake.Common.IO.DirectoryAliases.MakeRelative.DefinedRootPath")
.IsDependentOn("Cake.Common.IO.DirectoryAliases.MakeRelative.WorkingDirectory");
.IsDependentOn("Cake.Common.IO.DirectoryAliases.MakeRelative.WorkingDirectory")
.IsDependentOn("Cake.Common.IO.Paths.ConvertableDirectoryPath.DirectoryPathPlusConvertableDirectoryPath")
.IsDependentOn("Cake.Common.IO.Paths.ConvertableDirectoryPath.ConvertableDirectoryPathPlusDirectoryPath")
.IsDependentOn("Cake.Common.IO.Paths.ConvertableDirectoryPath.ConvertableDirectoryPathPlusConvertableDirectoryPath")
;

0 comments on commit 83d3f86

Please sign in to comment.