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(439): Pattern "*." returns only files with no extension #516

Merged
merged 4 commits into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,12 +39,14 @@ private MockFileSystem SetupFileSystem()
{ XFS.Path(@"c:\a.gif"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\b.txt"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\c.txt"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\d"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\a.txt"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\b.gif"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\c.txt"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\a\a.txt"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\a\b.txt"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\a\c.gif"), new MockFileData("Demo text content") },
{ XFS.Path(@"c:\a\a\d"), new MockFileData("Demo text content") }
});

}
Expand Down Expand Up @@ -221,6 +223,38 @@ public void MockDirectory_GetFiles_ShouldFilterByExtensionBasedSearchPatternAndS
Assert.That(result, Is.EquivalentTo(expected));
}

[Test]
public void MockDirectory_GetFiles_ShouldFilterForFilesWithNoExtensionsAndSearchOptionTopDirectoryOnly()
{
// Arrange
var fileSystem = SetupFileSystem();
var expected = new[] { XFS.Path(@"c:\d") };

// Act
var result = fileSystem.Directory.GetFiles(XFS.Path(@"c:\"), "*.", SearchOption.TopDirectoryOnly);

// Assert
Assert.That(result, Is.EquivalentTo(expected));
}

[Test]
public void MockDirectory_GetFiles_ShouldFilterForFilesWithNoExtensionsAndSearchOptionAllDirectories()
{
// Arrange
var fileSystem = SetupFileSystem();
var expected = new[]
{
XFS.Path(@"c:\d"),
XFS.Path(@"c:\a\a\d")
};

// Act
var result = fileSystem.Directory.GetFiles(XFS.Path(@"c:\"), "*.", SearchOption.AllDirectories);

// Assert
Assert.That(result, Is.EquivalentTo(expected));
}

private void ExecuteTimeAttributeTest(Action<IFileSystem, string, DateTime> setter, Func<IFileSystem, string, DateTime> getter)
{
string path = XFS.Path(@"c:\something\demo.txt");
Expand Down Expand Up @@ -1215,7 +1249,7 @@ public void MockDirectory_Move_ShouldMoveFiles()
{
string sourceFilePath = XFS.Path(@"c:\demo.txt");
string sourceFileContent = "this is some content";

var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ sourceFilePath, new MockFileData(sourceFileContent) }
Expand Down
4 changes: 4 additions & 0 deletions System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Expand Up @@ -237,6 +237,10 @@ public override string[] GetFiles(string path, string searchPattern, SearchOptio
{
fileNamePattern = isUnix ? @"[^/]*?/?" : @"[^\\]*?\\?";
}
else if (searchPattern == "*.")
KaliVi marked this conversation as resolved.
Show resolved Hide resolved
{
fileNamePattern = isUnix ? @"[^/.]*?/?" : @"[^\\.]*?\\?";
}
else
{
fileNamePattern = Regex.Escape(searchPattern)
Expand Down