Skip to content

Commit

Permalink
Simplify SimulatedPath and NativePath implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Apr 29, 2024
1 parent f165dd6 commit 9b3c1c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ public string GetFullPath(string path)
string? pathRoot = System.IO.Path.GetPathRoot(path);
string? directoryRoot =
System.IO.Path.GetPathRoot(fileSystem.Storage.CurrentDirectory);
if (!string.IsNullOrEmpty(pathRoot) && !string.IsNullOrEmpty(directoryRoot))
if (pathRoot?.Length < directoryRoot?.Length)
{
if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0]))
if (pathRoot.Length > 0 &&
char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0]))
{
return System.IO.Path.GetFullPath(path);
}

if (pathRoot.Length < directoryRoot.Length)
{
path = path.Substring(pathRoot.Length);
}
path = path.Substring(pathRoot.Length);
}

return System.IO.Path.GetFullPath(System.IO.Path.Combine(
Expand Down Expand Up @@ -183,7 +181,6 @@ public string GetRandomFileName()
public string GetRelativePath(string relativeTo, string path)
{
relativeTo.EnsureValidArgument(fileSystem, nameof(relativeTo));
path.EnsureValidArgument(fileSystem, nameof(path));

relativeTo = fileSystem.Execute.Path.GetFullPath(relativeTo);
path = fileSystem.Execute.Path.GetFullPath(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ public string GetRandomFileName()
public string GetRelativePath(string relativeTo, string path)
{
relativeTo.EnsureValidArgument(fileSystem, nameof(relativeTo));
path.EnsureValidArgument(fileSystem, nameof(path));

relativeTo = fileSystem.Execute.Path.GetFullPath(relativeTo);
path = fileSystem.Execute.Path.GetFullPath(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void GetPathRoot_ShouldReturnDefaultValue(string path)
{
string? result = FileSystem.Path.GetPathRoot(path);

result.Should().Be(System.IO.Path.GetPathRoot(path));
result.Should().Be("");
}

#if FEATURE_SPAN
Expand Down

0 comments on commit 9b3c1c1

Please sign in to comment.