Skip to content

Commit

Permalink
Change ParentDirectory extension method to handle a case with the giv…
Browse files Browse the repository at this point in the history
…en path ends with a directory separator character
  • Loading branch information
roend83 committed Feb 22, 2013
1 parent 268516c commit 402657f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/FubuCore.Testing/StringExtensionsTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public void parent_directory()
path.ParentDirectory().ShouldEqual(Path.GetDirectoryName(path));
}

[Test]
public void parent_directory_ending_with_directory_seperator()
{
var path = ".".ToFullPath();
(path + Path.DirectorySeparatorChar).ParentDirectory().ShouldEqual(Path.GetDirectoryName(path));
}

[Test]
public void if_not_null_positive()
{
Expand All @@ -47,7 +54,7 @@ public void if_not_null_negative()
[Test]
public void combine_to_path_when_rooted()
{
var rooted = Path.Combine(Path.GetPathRoot(AppDomain.CurrentDomain.BaseDirectory), "here");
var rooted = Path.Combine(Path.GetPathRoot(AppDomain.CurrentDomain.BaseDirectory), "here");
rooted.CombineToPath("there").ShouldEqual(rooted);
}

Expand Down
2 changes: 1 addition & 1 deletion src/FubuCore/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static string ToFullPath(this string path)
/// <returns></returns>
public static string ParentDirectory(this string path)
{
return Path.GetDirectoryName(path);
return Path.GetDirectoryName(path.TrimEnd(Path.DirectorySeparatorChar));
}

/// <summary>
Expand Down

0 comments on commit 402657f

Please sign in to comment.