Skip to content

Commit fbb10c1

Browse files
authored
fix: start implementing Path simulation (#564)
Implement - AltDirectorySeparatorChar - DirectorySeparatorChar - PathSeparator - VolumeSeparatorChar - GetInvalidFileNameChars() - GetInvalidPathChars()
1 parent 2466577 commit fbb10c1

File tree

6 files changed

+523
-285
lines changed

6 files changed

+523
-285
lines changed

Source/Testably.Abstractions.Testing/Helpers/Execute.LinuxPath.cs

+37-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
1-
using System.IO;
2-
#if FEATURE_SPAN
3-
using System;
4-
#endif
5-
6-
namespace Testably.Abstractions.Testing.Helpers;
1+
namespace Testably.Abstractions.Testing.Helpers;
72

83
internal partial class Execute
94
{
10-
private class LinuxPath(MockFileSystem fileSystem) : NativePath(fileSystem)
5+
private class LinuxPath(MockFileSystem fileSystem) : SimulatedPath(fileSystem)
116
{
12-
#if FEATURE_SPAN
13-
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" />
14-
public override bool IsPathRooted(ReadOnlySpan<char> path)
15-
=> IsPathRooted(path.ToString());
16-
#endif
7+
/// <inheritdoc cref="IPath.AltDirectorySeparatorChar" />
8+
public override char AltDirectorySeparatorChar => '/';
9+
10+
/// <inheritdoc cref="IPath.DirectorySeparatorChar" />
11+
public override char DirectorySeparatorChar => '/';
12+
13+
/// <inheritdoc cref="IPath.PathSeparator" />
14+
public override char PathSeparator => ':';
15+
16+
/// <inheritdoc cref="IPath.VolumeSeparatorChar" />
17+
public override char VolumeSeparatorChar => '/';
18+
19+
/// <inheritdoc cref="IPath.GetInvalidFileNameChars()" />
20+
public override char[] GetInvalidFileNameChars() => ['\0', '/'];
21+
22+
/// <inheritdoc cref="IPath.GetInvalidPathChars()" />
23+
public override char[] GetInvalidPathChars() => ['\0'];
24+
25+
/// <inheritdoc cref="IPath.GetPathRoot(string?)" />
26+
public override string? GetPathRoot(string? path)
27+
{
28+
if (string.IsNullOrEmpty(path))
29+
{
30+
return null;
31+
}
32+
33+
return IsPathRooted(path)
34+
? $"{DirectorySeparatorChar}"
35+
: string.Empty;
36+
}
37+
38+
/// <inheritdoc cref="IPath.GetTempPath()" />
39+
public override string GetTempPath()
40+
=> "/tmp/";
1741

18-
/// <inheritdoc cref="Path.IsPathRooted(string)" />
42+
/// <inheritdoc cref="IPath.IsPathRooted(string)" />
1943
public override bool IsPathRooted(string? path)
2044
=> path?.Length > 0 && path[0] == '/';
2145
}

Source/Testably.Abstractions.Testing/Helpers/Execute.MacPath.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
#if FEATURE_SPAN
2-
#endif
3-
#if FEATURE_FILESYSTEM_NET7
4-
using Testably.Abstractions.Testing.Storage;
5-
#endif
6-
7-
namespace Testably.Abstractions.Testing.Helpers;
1+
namespace Testably.Abstractions.Testing.Helpers;
82

93
internal partial class Execute
104
{

Source/Testably.Abstractions.Testing/Helpers/Execute.NativePath.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#if FEATURE_SPAN
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.IO;
3+
#if FEATURE_SPAN
24
using System;
35
#endif
4-
using System.Diagnostics.CodeAnalysis;
5-
using System.IO;
66
#if FEATURE_FILESYSTEM_NET7
77
using Testably.Abstractions.Testing.Storage;
88
#endif
@@ -11,7 +11,7 @@ namespace Testably.Abstractions.Testing.Helpers;
1111

1212
internal partial class Execute
1313
{
14-
private class NativePath(MockFileSystem fileSystem) : IPath
14+
private sealed class NativePath(MockFileSystem fileSystem) : IPath
1515
{
1616
#region IPath Members
1717

@@ -228,12 +228,12 @@ public bool IsPathFullyQualified(string path)
228228

229229
#if FEATURE_SPAN
230230
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" />
231-
public virtual bool IsPathRooted(ReadOnlySpan<char> path)
231+
public bool IsPathRooted(ReadOnlySpan<char> path)
232232
=> System.IO.Path.IsPathRooted(path);
233233
#endif
234234

235235
/// <inheritdoc cref="Path.IsPathRooted(string)" />
236-
public virtual bool IsPathRooted(string? path)
236+
public bool IsPathRooted(string? path)
237237
=> System.IO.Path.IsPathRooted(path);
238238

239239
#if FEATURE_PATH_JOIN

0 commit comments

Comments
 (0)