Skip to content

Commit

Permalink
PR feedback (Mihai): Cover early elimination of exclude filename patt…
Browse files Browse the repository at this point in the history
…erns
  • Loading branch information
ladipro committed Feb 22, 2021
1 parent 4fbd229 commit dd9ef62
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Shared/FileMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,10 @@ private static string[] CreateArrayWithSingleItemIfNotExcluded(string filespecUn
// The suffix is the same so there is a possibility that the two will match the same files.
searchesToExclude.Add(excludeState);
}
else
{
Console.Write("Hoho");
}
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/Shared/UnitTests/FileMatcher_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,44 @@ public static IEnumerable<object[]> GetTestData()
ExpectNoMatches = NativeMethodsShared.IsLinux,
}
};

// Hits the early elimination of exclude file patterns that do not intersect with the include.
// The exclude is redundant and can be eliminated before starting the file system walk.
yield return new object[]
{
new GetFilesComplexGlobbingMatchingInfo
{
Include = @"src\foo\**\*.cs",
Excludes = new[]
{
@"src\foo\**\foo\**",
@"src\foo\**\*.vb" // redundant exclude
},
ExpectedMatches = new[]
{
@"src\foo\foo.cs",
@"src\foo\inner\foo.cs",
@"src\foo\inner\bar\bar.cs"
},
ExpectNoMatches = NativeMethodsShared.IsLinux,
}
};

// Hits the early elimination of exclude file patterns that do not intersect with the include.
// The exclude is not redundant and must not be eliminated.
yield return new object[]
{
new GetFilesComplexGlobbingMatchingInfo
{
Include = @"src\foo\**\*.cs",
Excludes = new[]
{
@"src\foo\**\*.*" // effective exclude
},
ExpectedMatches = Array.Empty<string>(),
ExpectNoMatches = NativeMethodsShared.IsLinux,
}
};
}
}

Expand Down

0 comments on commit dd9ef62

Please sign in to comment.