diff --git a/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs b/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs index cca4ad123..3d2683235 100644 --- a/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs +++ b/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs @@ -319,7 +319,15 @@ public bool HasExtension(ReadOnlySpan path) /// 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 /// @@ -406,7 +414,11 @@ public ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) #if FEATURE_PATH_ADVANCED /// 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 diff --git a/Tests/Helpers/Testably.Abstractions.Tests.SourceGenerator/ClassGenerators/FileSystemClassGenerator.cs b/Tests/Helpers/Testably.Abstractions.Tests.SourceGenerator/ClassGenerators/FileSystemClassGenerator.cs index 56ee80963..a514bce74 100644 --- a/Tests/Helpers/Testably.Abstractions.Tests.SourceGenerator/ClassGenerators/FileSystemClassGenerator.cs +++ b/Tests/Helpers/Testably.Abstractions.Tests.SourceGenerator/ClassGenerators/FileSystemClassGenerator.cs @@ -273,9 +273,11 @@ private bool IncludeSimulatedTests(ClassModel @class) "GetPathRootTests", "GetRandomFileNameTests", "GetTempPathTests", + "HasExtensionTests", "IsPathRootedTests", "JoinTests", "Tests", + "TrimEndingDirectorySeparatorTests", "TryJoinTests" ]; return @class.Namespace diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Path/HasExtensionTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Path/HasExtensionTests.cs index a914c3a7b..d5fa9eaf2 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Path/HasExtensionTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Path/HasExtensionTests.cs @@ -14,6 +14,7 @@ public void HasExtension_Null_ShouldReturnFalse() } [SkippableTheory] + [InlineAutoData("abc.", false)] [InlineAutoData(".foo", true)] [InlineAutoData(".abc.xyz", true)] [InlineAutoData("foo", false)] @@ -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)]