-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prepare simulating other file systems (#546)
* Allow simulating other file systems * Simulate `Path.IsPathRooted` * Fix or skip failing tests
- Loading branch information
Showing
11 changed files
with
356 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Source/Testably.Abstractions.Testing/Helpers/Execute.LinuxPath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.IO; | ||
#if FEATURE_SPAN | ||
using System; | ||
#endif | ||
|
||
namespace Testably.Abstractions.Testing.Helpers; | ||
|
||
internal partial class Execute | ||
{ | ||
private class LinuxPath(MockFileSystem fileSystem) : NativePath(fileSystem) | ||
{ | ||
#if FEATURE_SPAN | ||
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" /> | ||
public override bool IsPathRooted(ReadOnlySpan<char> path) | ||
=> IsPathRooted(path.ToString()); | ||
#endif | ||
|
||
/// <inheritdoc cref="Path.IsPathRooted(string)" /> | ||
public override bool IsPathRooted(string? path) | ||
=> path?.Length > 0 && path[0] == '/'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Source/Testably.Abstractions.Testing/Helpers/Execute.MacPath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#if FEATURE_SPAN | ||
#endif | ||
#if FEATURE_FILESYSTEM_NET7 | ||
using Testably.Abstractions.Testing.Storage; | ||
#endif | ||
|
||
namespace Testably.Abstractions.Testing.Helpers; | ||
|
||
internal partial class Execute | ||
{ | ||
private sealed class MacPath(MockFileSystem fileSystem) : LinuxPath(fileSystem); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Source/Testably.Abstractions.Testing/Helpers/Execute.WindowsPath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.IO; | ||
#if FEATURE_SPAN | ||
using System; | ||
#endif | ||
|
||
namespace Testably.Abstractions.Testing.Helpers; | ||
|
||
internal partial class Execute | ||
{ | ||
private sealed class WindowsPath(MockFileSystem fileSystem) : NativePath(fileSystem) | ||
{ | ||
#if FEATURE_SPAN | ||
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" /> | ||
public override bool IsPathRooted(ReadOnlySpan<char> path) | ||
=> IsPathRooted(path.ToString()); | ||
#endif | ||
|
||
/// <inheritdoc cref="Path.IsPathRooted(string)" /> | ||
public override bool IsPathRooted(string? path) | ||
{ | ||
int? length = path?.Length; | ||
return (length >= 1 && IsDirectorySeparator(path![0])) || | ||
(length >= 2 && IsValidDriveChar(path![0]) && path[1] == VolumeSeparatorChar); | ||
} | ||
|
||
/// <summary> | ||
/// True if the given character is a directory separator. | ||
/// </summary> | ||
/// <remarks>https://github.com/dotnet/runtime/blob/v8.0.3/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L280</remarks> | ||
private static bool IsDirectorySeparator(char c) | ||
=> c == '\\' || c == '/'; | ||
|
||
/// <summary> | ||
/// Returns true if the given character is a valid drive letter | ||
/// </summary> | ||
/// <remarks>https://github.com/dotnet/runtime/blob/v8.0.3/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L72</remarks> | ||
private static bool IsValidDriveChar(char value) | ||
=> (uint)((value | 0x20) - 'a') <= 'z' - 'a'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.