Skip to content

Commit fb8a019

Browse files
committed
Added Null and IsNull to eventually replace Empty
1 parent 7d559f7 commit fb8a019

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

Pathy.ApiVerificationTests/ApprovedApi/pathy.net47.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ namespace Pathy
1111
public bool FileExists { get; }
1212
public bool IsDirectory { get; }
1313
public bool IsFile { get; }
14+
public bool IsNull { get; }
1415
public bool IsRooted { get; }
1516
public string Name { get; }
1617
public Pathy.ChainablePath Parent { get; }
1718
public Pathy.ChainablePath Root { get; }
1819
public static Pathy.ChainablePath Current { get; }
1920
public static Pathy.ChainablePath Empty { get; }
2021
public static Pathy.ChainablePath New { get; }
22+
public static Pathy.ChainablePath Null { get; }
2123
public static Pathy.ChainablePath Temp { get; }
2224
public Pathy.ChainablePath FindParentWithFileMatching(params string[] wildcards) { }
2325
public bool HasExtension(string extension) { }

Pathy.ApiVerificationTests/ApprovedApi/pathy.net8.0.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ namespace Pathy
1111
public bool FileExists { get; }
1212
public bool IsDirectory { get; }
1313
public bool IsFile { get; }
14+
public bool IsNull { get; }
1415
public bool IsRooted { get; }
1516
public string Name { get; }
1617
public Pathy.ChainablePath Parent { get; }
1718
public Pathy.ChainablePath Root { get; }
1819
public static Pathy.ChainablePath Current { get; }
1920
public static Pathy.ChainablePath Empty { get; }
2021
public static Pathy.ChainablePath New { get; }
22+
public static Pathy.ChainablePath Null { get; }
2123
public static Pathy.ChainablePath Temp { get; }
2224
public Pathy.ChainablePath AsRelativeTo(Pathy.ChainablePath basePath) { }
2325
public Pathy.ChainablePath FindParentWithFileMatching(params string[] wildcards) { }

Pathy.ApiVerificationTests/ApprovedApi/pathy.netstandard2.0.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ namespace Pathy
1111
public bool FileExists { get; }
1212
public bool IsDirectory { get; }
1313
public bool IsFile { get; }
14+
public bool IsNull { get; }
1415
public bool IsRooted { get; }
1516
public string Name { get; }
1617
public Pathy.ChainablePath Parent { get; }
1718
public Pathy.ChainablePath Root { get; }
1819
public static Pathy.ChainablePath Current { get; }
1920
public static Pathy.ChainablePath Empty { get; }
2021
public static Pathy.ChainablePath New { get; }
22+
public static Pathy.ChainablePath Null { get; }
2123
public static Pathy.ChainablePath Temp { get; }
2224
public Pathy.ChainablePath FindParentWithFileMatching(params string[] wildcards) { }
2325
public bool HasExtension(string extension) { }

Pathy.ApiVerificationTests/ApprovedApi/pathy.netstandard2.1.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ namespace Pathy
1111
public bool FileExists { get; }
1212
public bool IsDirectory { get; }
1313
public bool IsFile { get; }
14+
public bool IsNull { get; }
1415
public bool IsRooted { get; }
1516
public string Name { get; }
1617
public Pathy.ChainablePath Parent { get; }
1718
public Pathy.ChainablePath Root { get; }
1819
public static Pathy.ChainablePath Current { get; }
1920
public static Pathy.ChainablePath Empty { get; }
2021
public static Pathy.ChainablePath New { get; }
22+
public static Pathy.ChainablePath Null { get; }
2123
public static Pathy.ChainablePath Temp { get; }
2224
public Pathy.ChainablePath AsRelativeTo(Pathy.ChainablePath basePath) { }
2325
public Pathy.ChainablePath FindParentWithFileMatching(params string[] wildcards) { }

Pathy.Specs/ChainablePathSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ public void Empty_path_returned_when_no_match_found()
568568
var result = childDir.FindParentWithFileMatching("*.sln");
569569

570570
// Assert
571-
result.Should().Be(ChainablePath.Empty);
571+
result.Should().Be(ChainablePath.Null);
572572
}
573573

574574
[Fact]
@@ -765,7 +765,7 @@ public void Returns_empty_for_non_existing_string_paths()
765765
var result = ChainablePath.FindFirst(nonExistingFile1.ToString(), nonExistingFile2.ToString());
766766

767767
// Assert
768-
result.Should().Be(ChainablePath.Empty);
768+
result.IsNull.Should().BeTrue();
769769
}
770770

771771
[Fact]

Pathy/ChainablePath.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ private ChainablePath(string path)
3232
/// </summary>
3333
public static ChainablePath Empty { get; } = new(string.Empty);
3434

35+
/// <summary>
36+
/// Represents a <see cref="ChainablePath"/> not pointing to any file or directory.
37+
/// </summary>
38+
/// <remarks>
39+
/// Implements the Null Pattern and should be used as a replacement of <see cref="Empty"/>
40+
/// </remarks>
41+
public static ChainablePath Null { get; } = new(string.Empty);
42+
3543
/// <summary>
3644
/// Gets a default, empty <see cref="ChainablePath"/> instance.
3745
/// </summary>
@@ -221,6 +229,11 @@ private static string NormalizeSlashes(string path)
221229
return From(leftPath.ToString() + additionalPath);
222230
}
223231

232+
/// <summary>
233+
/// Gets a value indicating whether the current <see cref="ChainablePath"/> instance is equal to <see cref="ChainablePath.Null"/>.
234+
/// </summary>
235+
public bool IsNull => Equals(Null);
236+
224237
/// <summary>
225238
/// Gets the name of the file or directory represented by the current path, without the parent directory.
226239
/// </summary>

0 commit comments

Comments
 (0)