Skip to content

Commit afd698f

Browse files
authored
Fix Path.GetFullPath() (#100)
***NO_CI***
1 parent 4d587f9 commit afd698f

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

System.IO.FileSystem.UnitTests/PathUnitTests.cs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using nanoFramework.TestFramework;
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
5+
using nanoFramework.TestFramework;
26

37
namespace System.IO.FileSystem.UnitTests
48
{
@@ -103,7 +107,7 @@ public void Combine_throws_if_path2_is_null()
103107
[TestMethod]
104108
public void GetDirectoryName_returns_directory()
105109
{
106-
var tests = new[] { @"I:\directory", @"I:\directory\", @"I:\directory\file.ext" };
110+
var tests = new[] { @"I:\directory", @"I:\directory\", @"I:\directory\file.ext" };
107111
var answers = new[] { @"I:\", @"I:\directory", @"I:\directory" };
108112

109113
for (var i = 0; i < tests.Length; i++)
@@ -311,26 +315,27 @@ public void GetPathRoot_returns_root_UNC_paths()
311315
}
312316
}
313317

318+
[DataRow(@"\dir1\dir2\file.ext")]
319+
[DataRow(@"\dir1\dir2\file.ext")]
320+
[DataRow(@"\dir1\..\dir2\file.ext")]
321+
[DataRow(@"\dir1\..\dir2\..\dir3\file.ext")]
314322
[TestMethod]
315-
public void GetFullPath0()
316-
{
317-
string fullPath = Path.GetFullPath(@"dir1\dir2\file.ext");
318-
319-
Assert.AreEqual(@"\dir1\dir2\file.ext", fullPath);
320-
}
321-
322-
[TestMethod]
323-
public void GetFullPath1()
323+
public void GetFullPathWithFiles(string pathToTest)
324324
{
325-
string fullPath = Path.GetFullPath(@"\dir1\dir2\file.ext");
326-
Assert.AreEqual(@"\dir1\dir2\file.ext", fullPath);
327-
}
325+
string fullPath = Path.GetFullPath(pathToTest);
326+
Assert.AreEqual(pathToTest, fullPath);
327+
}
328328

329+
[DataRow(@"\dir1\..\..\dir2\", @"\dir1\..\..\dir2\")]
330+
[DataRow(@"\dir1\..\..\dir2", @"\dir1\..\..\dir2")]
331+
[DataRow(@"dir1\dir2\", @"dir1\dir2\")]
332+
[DataRow(@"dir1\dir2", @"dir1\dir2")]
333+
[DataRow(@"\dir1\dir2\", @"\dir1\dir2\")]
329334
[TestMethod]
330-
public void GetFullPath2()
335+
public void GetFullPathWithDirectories(string pathToTest, string expectedPath)
331336
{
332-
string fullPath = Path.GetFullPath(@"\dir1\..\dir2\file.ext");
333-
Assert.AreEqual(@"\dir1\..\dir2\file.ext", fullPath);
337+
string fullPath = Path.GetFullPath(pathToTest);
338+
Assert.AreEqual(expectedPath, fullPath);
334339
}
335340

336341
[TestMethod]
@@ -398,7 +403,7 @@ public void IsPathRooted_returns_true()
398403
{
399404
var tests = new[]
400405
{
401-
@"\", "/", "I:", @"I:\", @"I:\file.ext", @"I:\directory\file.ext"
406+
@"\", "/", "I:", @"I:\", @"I:\file.ext", @"I:\directory\file.ext"
402407
};
403408

404409
for (var i = 0; i < tests.Length; i++)

System.IO.FileSystem/Path.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ public static string GetFullPath(string path)
288288
// path = Combine(currDir, path);
289289
}
290290

291-
return Combine(
292-
GetDirectoryName(path),
293-
GetFileName(path));
291+
return PathInternal.NormalizeDirectorySeparators(path);
294292
}
295293

296294
/// <summary>

0 commit comments

Comments
 (0)