Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e7e77c0

Browse files
stephentoubkarelz
authored andcommitted
Fix Path tests for throwing on empty/whitespace inputs
1 parent 29a0689 commit e7e77c0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/System.Runtime.Extensions/tests/System/IO/PathTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ public static void ChangeExtension(string path, string newExtension, string expe
3434
Assert.Equal(expected, Path.ChangeExtension(path, newExtension));
3535
}
3636

37+
[Theory]
38+
[InlineData("")]
39+
[InlineData(" ")]
40+
[InlineData("\r\n")]
41+
public static void GetDirectoryName_EmptyOrWhitespace_Throws(string path)
42+
{
43+
Assert.Throws<ArgumentException>(() => Path.GetDirectoryName(path));
44+
}
45+
3746
[Theory]
3847
[InlineData(null, null)]
39-
[InlineData("", null)]
4048
[InlineData(".", "")]
4149
[InlineData("..", "")]
4250
[InlineData("baz", "")]
@@ -175,7 +183,8 @@ public static void GetFileNameWithoutExtension(string path, string expected)
175183
public static void GetPathRoot()
176184
{
177185
Assert.Null(Path.GetPathRoot(null));
178-
Assert.Equal(string.Empty, Path.GetPathRoot(string.Empty));
186+
Assert.Throws<ArgumentException>(() => Path.GetPathRoot(string.Empty));
187+
Assert.Throws<ArgumentException>(() => Path.GetPathRoot("\r\n"));
179188

180189
string cwd = Directory.GetCurrentDirectory();
181190
Assert.Equal(cwd.Substring(0, cwd.IndexOf(Path.DirectorySeparatorChar) + 1), Path.GetPathRoot(cwd));

0 commit comments

Comments
 (0)