Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start implementing Path simulation #564

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions Source/Testably.Abstractions.Testing/Helpers/Execute.LinuxPath.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
using System.IO;
#if FEATURE_SPAN
using System;
#endif

namespace Testably.Abstractions.Testing.Helpers;
namespace Testably.Abstractions.Testing.Helpers;

internal partial class Execute
{
private class LinuxPath(MockFileSystem fileSystem) : NativePath(fileSystem)
private class LinuxPath(MockFileSystem fileSystem) : SimulatedPath(fileSystem)
{
#if FEATURE_SPAN
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" />
public override bool IsPathRooted(ReadOnlySpan<char> path)
=> IsPathRooted(path.ToString());
#endif
/// <inheritdoc cref="IPath.AltDirectorySeparatorChar" />
public override char AltDirectorySeparatorChar => '/';

/// <inheritdoc cref="IPath.DirectorySeparatorChar" />
public override char DirectorySeparatorChar => '/';

/// <inheritdoc cref="IPath.PathSeparator" />
public override char PathSeparator => ':';

/// <inheritdoc cref="IPath.VolumeSeparatorChar" />
public override char VolumeSeparatorChar => '/';

/// <inheritdoc cref="IPath.GetInvalidFileNameChars()" />
public override char[] GetInvalidFileNameChars() => ['\0', '/'];

/// <inheritdoc cref="IPath.GetInvalidPathChars()" />
public override char[] GetInvalidPathChars() => ['\0'];

/// <inheritdoc cref="IPath.GetPathRoot(string?)" />
public override string? GetPathRoot(string? path)
{
if (string.IsNullOrEmpty(path))
{
return null;
}

return IsPathRooted(path)
? $"{DirectorySeparatorChar}"
: string.Empty;
}

/// <inheritdoc cref="IPath.GetTempPath()" />
public override string GetTempPath()
=> "/tmp/";

/// <inheritdoc cref="Path.IsPathRooted(string)" />
/// <inheritdoc cref="IPath.IsPathRooted(string)" />
public override bool IsPathRooted(string? path)
=> path?.Length > 0 && path[0] == '/';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#if FEATURE_SPAN
#endif
#if FEATURE_FILESYSTEM_NET7
using Testably.Abstractions.Testing.Storage;
#endif

namespace Testably.Abstractions.Testing.Helpers;
namespace Testably.Abstractions.Testing.Helpers;

internal partial class Execute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if FEATURE_SPAN
using System.Diagnostics.CodeAnalysis;
using System.IO;
#if FEATURE_SPAN
using System;
#endif
using System.Diagnostics.CodeAnalysis;
using System.IO;
#if FEATURE_FILESYSTEM_NET7
using Testably.Abstractions.Testing.Storage;
#endif
Expand All @@ -11,7 +11,7 @@ namespace Testably.Abstractions.Testing.Helpers;

internal partial class Execute
{
private class NativePath(MockFileSystem fileSystem) : IPath
private sealed class NativePath(MockFileSystem fileSystem) : IPath
{
#region IPath Members

Expand Down Expand Up @@ -228,12 +228,12 @@ public bool IsPathFullyQualified(string path)

#if FEATURE_SPAN
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" />
public virtual bool IsPathRooted(ReadOnlySpan<char> path)
public bool IsPathRooted(ReadOnlySpan<char> path)
=> System.IO.Path.IsPathRooted(path);
#endif

/// <inheritdoc cref="Path.IsPathRooted(string)" />
public virtual bool IsPathRooted(string? path)
public bool IsPathRooted(string? path)
=> System.IO.Path.IsPathRooted(path);

#if FEATURE_PATH_JOIN
Expand Down
Loading
Loading