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

feat: implement HasExtension and TrimEndingDirectorySeparator for simulated Path #574

Merged
merged 3 commits into from
Apr 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,15 @@ public bool HasExtension(ReadOnlySpan<char> path)

/// <inheritdoc cref="IPath.HasExtension(string)" />
public bool HasExtension([NotNullWhen(true)] string? path)
=> System.IO.Path.HasExtension(path);
{
if (path == null)
{
return false;
}

return TryGetExtensionIndex(path, out var dotIndex)
&& dotIndex < path.Length - 1;
}

#if FEATURE_SPAN
/// <inheritdoc cref="IPath.IsPathFullyQualified(ReadOnlySpan{char})" />
Expand Down Expand Up @@ -406,7 +414,11 @@ public ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path)
#if FEATURE_PATH_ADVANCED
/// <inheritdoc cref="IPath.TrimEndingDirectorySeparator(string)" />
public string TrimEndingDirectorySeparator(string path)
=> System.IO.Path.TrimEndingDirectorySeparator(path);
{
return EndsInDirectorySeparator(path) && path.Length != GetRootLength(path)
? path.Substring(0, path.Length - 1)
: path;
}
#endif

#if FEATURE_PATH_JOIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,11 @@ private bool IncludeSimulatedTests(ClassModel @class)
"GetPathRootTests",
"GetRandomFileNameTests",
"GetTempPathTests",
"HasExtensionTests",
"IsPathRootedTests",
"JoinTests",
"Tests",
"TrimEndingDirectorySeparatorTests",
"TryJoinTests"
];
return @class.Namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void HasExtension_Null_ShouldReturnFalse()
}

[SkippableTheory]
[InlineAutoData("abc.", false)]
[InlineAutoData(".foo", true)]
[InlineAutoData(".abc.xyz", true)]
[InlineAutoData("foo", false)]
Expand All @@ -30,6 +31,7 @@ public void HasExtension_ShouldReturnExpectedResult(

#if FEATURE_SPAN
[SkippableTheory]
[InlineAutoData("abc.", false)]
[InlineAutoData(".foo", true)]
[InlineAutoData(".abc.xyz", true)]
[InlineAutoData("foo", false)]
Expand Down
Loading