Skip to content
Browse files

Change ParentDirectory extension method to handle a case with the giv…

…en path ends with a directory separator character
  • Loading branch information...
1 parent 268516c commit 402657f7586f299a5f3c26053f5cb8c9dae014ba @roend83 roend83 committed Feb 21, 2013
Showing with 9 additions and 2 deletions.
  1. +8 −1 src/FubuCore.Testing/StringExtensionsTester.cs
  2. +1 −1 src/FubuCore/StringExtensions.cs
View
9 src/FubuCore.Testing/StringExtensionsTester.cs
@@ -24,6 +24,13 @@ public void parent_directory()
}
[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()
{
var action = MockRepository.GenerateMock<Action<string>>();
@@ -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);
}
View
2 src/FubuCore/StringExtensions.cs
@@ -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>

0 comments on commit 402657f

Please sign in to comment.
Something went wrong with that request. Please try again.