Skip to content
Open
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
40 changes: 39 additions & 1 deletion TextFilter.Test/TextFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,45 @@
}

[TestMethod]
[DataRow("x[**]", "x[**]")]
[DataRow("a/x.cs", "***/x.cs")]
[DataRow("x.cs", "***/x.cs")]
[DataRow("a/b", "***/b")]
[DataRow("a/b", "****/b")]
[DataRow("a/b", "*****/b")]
[DataRow("b", "*****/b")]
[DataRow("a/b/c", "a/***/c")]
[DataRow("a/c", "a/***/c")]
[DataRow("a/b/c", "a/*****/c")]
[DataRow("x.cs", "***x.cs")]
public void WholeSegmentStarRunMatchesLikeGlobStar(string text, string filter)
{
Assert.IsTrue(TextFilter.IsMatch(text, filter, TextFilterType.Glob, TextFilterMatchOptions.ByWholeString));
Assert.IsTrue(TextFilter.IsMatch(text, filter));
}

[TestMethod]
[DataRow("a/y.cs", "***/x.cs")]
[DataRow("a/b/d", "a/***/c")]
public void WholeSegmentStarRunStillRequiresTheLiteral(string text, string filter)
{
Assert.IsFalse(TextFilter.IsMatch(text, filter, TextFilterType.Glob, TextFilterMatchOptions.ByWholeString));
}

[TestMethod]
public void WholeSegmentStarRunExclusionExcludesItems()
{
List<string> result = [.. TextFilter.Filter(["a/tmp", "a/keep"], "-***/tmp")];

Assert.AreEqual(1, result.Count);

Check warning on line 1456 in TextFilter.Test/TextFilterTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.HasCount' instead of 'Assert.AreEqual'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaHN38-fmvW8gAcaZybE&open=AaHN38-fmvW8gAcaZybE&pullRequest=206
Assert.AreEqual("a/keep", result[0]);
}

[TestMethod]
[DataRow("***/x.cs", "**/x.cs")]
[DataRow("a/*****/c", "a/**/c")]
[DataRow("***", "**")]
[DataRow("x[***]", "x[***]")]

[DataRow("x[!**]", "x[!**]")]
[DataRow("**/a", "**/a")]
[DataRow("a/**", "a/**")]
Expand Down
7 changes: 4 additions & 3 deletions TextFilter/TextFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@

return ExcludedTokenPrefixes.Contains(prefix)
? TextFilterTokenType.Excluded
: RequiredTokenPrefixes.Contains(prefix)

Check warning on line 306 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Extract this nested ternary operation into an independent statement.

Check warning on line 306 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Extract this nested ternary operation into an independent statement.
? TextFilterTokenType.Required
: TextFilterTokenType.Optional;
})
Expand Down Expand Up @@ -346,7 +346,7 @@
/// matches nor rejects anything; as a required token it matches everything; and as an excluded
/// token it excludes nothing.
/// </remarks>
public static bool DoesMatchGlob(string text, string filter, TextFilterMatchOptions textFilterMatchOptions, TextFilterCaseSensitivity caseSensitivity = TextFilterCaseSensitivity.CaseSensitive)

Check warning on line 349 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 35 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.

Check warning on line 349 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 35 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.
{
Ensure.NotNull(text);
Ensure.NotNull(filter);
Expand Down Expand Up @@ -420,7 +420,7 @@
/// <param name="textTokens">The set of text tokens to match against.</param>
/// <param name="caseSensitivity">Whether the match distinguishes uppercase from lowercase.</param>
/// <returns><c>true</c> if any token matches the glob filter token; otherwise, <c>false</c>.</returns>
public static bool AnyTokenMatchesGlobFilter(string filterToken, HashSet<string> textTokens, TextFilterCaseSensitivity caseSensitivity = TextFilterCaseSensitivity.CaseSensitive)

Check warning on line 423 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 45 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.

Check warning on line 423 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 45 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.
{
Ensure.NotNull(filterToken);
Ensure.NotNull(textTokens);
Expand All @@ -437,7 +437,7 @@
/// <param name="textTokens">The set of text tokens to match against.</param>
/// <param name="caseSensitivity">Whether the match distinguishes uppercase from lowercase.</param>
/// <returns><c>true</c> if all tokens match the glob filter token; otherwise, <c>false</c>.</returns>
public static bool AllTokensMatchGlobFilter(string filterToken, HashSet<string> textTokens, TextFilterCaseSensitivity caseSensitivity = TextFilterCaseSensitivity.CaseSensitive)

Check warning on line 440 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 50 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.

Check warning on line 440 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 50 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.
{
Ensure.NotNull(filterToken);
Ensure.NotNull(textTokens);
Expand Down Expand Up @@ -523,9 +523,10 @@
// DotNet.Glob only reads "**" as a wildcard when it is a whole path segment; joined to anything
// else, as in "**foo" or "a**b", it matches no characters at all, so a doubled star
// would empty the list where "*" matches. Outside a whole segment a run of stars means no more than
// one star does, so each such run is collapsed to "*". A whole-segment "**" ("**/x", "a/**") is left
// for ExpandGlobStarSegments, and stars inside a bracket class are members, so they are left too.
// one star does, so each such run is collapsed to "*". A whole-segment run ("**/x", "a/**") is capped at
// "**" and left for ExpandGlobStarSegments: a longer run such as "***/" would otherwise leave a stray "*"
// joined to the "**" and match nothing. Stars inside a bracket class are members, so they are left too.
internal static string CollapseJoinedGlobStars(string token)

Check warning on line 529 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.
{
if (!token.Contains("**", StringComparison.Ordinal))
{
Expand Down Expand Up @@ -564,7 +565,7 @@
bool startsSegment = index == 0 || IsPathSeparator(token[index - 1]);
bool endsSegment = runEnd == token.Length || IsPathSeparator(token[runEnd]);
int runLength = runEnd - index;
result.Append('*', runLength > 1 && !(startsSegment && endsSegment) ? 1 : runLength);
result.Append('*', runLength > 1 && !(startsSegment && endsSegment) ? 1 : Math.Min(runLength, 2));
index = runEnd;
}

Expand Down Expand Up @@ -881,7 +882,7 @@
/// <see cref="TextFilterMatchOptions.ByWholeString"/> for those.
/// </para>
/// </remarks>
public static bool DoesMatchRegex(string text, string filter, TextFilterMatchOptions textFilterMatchOptions, TextFilterCaseSensitivity caseSensitivity = TextFilterCaseSensitivity.CaseSensitive)

Check warning on line 885 in TextFilter/TextFilter.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

This method signature overlaps the one defined on line 40 in file 'TextFilter.BinaryCompatibility.cs', the default parameter value can't be used.
{
Ensure.NotNull(text);
Ensure.NotNull(filter);
Expand Down
Loading