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
9 changes: 8 additions & 1 deletion TextFilter.Test/ReadmeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace TextFilter.Test;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -89,7 +90,10 @@ public void EveryMethodInTheReadmeApiReferenceExistsWithItsDocumentedDefaults()
foreach (Match row in rows)
{
string methodName = row.Groups["method"].Value;
MethodInfo[] overloads = [.. methods.Where(m => m.Name == methodName)];
// The binary-compatibility overloads are hidden from IntelliSense and deliberately carry no
// defaults, since defaults on both sets would make calls ambiguous. The README documents the
// visible overloads, so only those are held to its defaults.
MethodInfo[] overloads = [.. methods.Where(m => m.Name == methodName && !IsHiddenFromCallers(m))];
if (overloads.Length == 0)
{
problems.Add($"{methodName} does not exist");
Expand All @@ -115,6 +119,9 @@ public void EveryMethodInTheReadmeApiReferenceExistsWithItsDocumentedDefaults()
Assert.IsEmpty(problems, string.Join("; ", problems));
}

private static bool IsHiddenFromCallers(MethodInfo method) =>
method.GetCustomAttribute<EditorBrowsableAttribute>()?.State == EditorBrowsableState.Never;

[TestMethod]
public void ReadmeMatchOptionsSampleGivesTheDocumentedResults()
{
Expand Down
9 changes: 9 additions & 0 deletions TextFilter.Test/TextFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,8 @@
public void FilterWithAClassFollowedByALiteralBracketKeepsAndExcludesTheRightItems()
{
List<string> items = ["items[3]", "items[3", "notes.txt"];
CollectionAssert.AreEqual(new List<string> { "items[3]" }, TextFilter.Filter(items, "*[[][0-9]]").ToList());

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.AreSequenceEqual' instead of 'CollectionAssert.AreEqual'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2Tb8UJaCetOmTOrI&open=AaGk2Tb8UJaCetOmTOrI&pullRequest=187
CollectionAssert.AreEqual(new List<string> { "items[3", "notes.txt" }, TextFilter.Filter(items, "-*[[][0-9]]").ToList());

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.AreSequenceEqual' instead of 'CollectionAssert.AreEqual'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2Tb8UJaCetOmTOrJ&open=AaGk2Tb8UJaCetOmTOrJ&pullRequest=187
}

[TestMethod]
Expand Down Expand Up @@ -1303,6 +1303,15 @@
Assert.IsTrue(TextFilter.IsMatch(text, filter, TextFilterType.Glob, TextFilterMatchOptions.ByWholeString));
}

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

[TestMethod]
public void GlobStarSlashFiltersPathItems()
{
Expand All @@ -1326,7 +1335,7 @@
{
List<string> result = [.. TextFilter.Filter(["readme.md", "src/a.cs", "docs/", "a b"], filter)];

Assert.AreEqual(1, result.Count);

Check warning on line 1338 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=AaGk2Tb8UJaCetOmTOrK&open=AaGk2Tb8UJaCetOmTOrK&pullRequest=187
Assert.AreEqual("docs/", result[0]);
}

Expand All @@ -1337,7 +1346,7 @@
{
List<string> result = [.. TextFilter.Filter(["readme.md", "src/a.cs", "docs/", "a b"], filter)];

Assert.AreEqual(3, result.Count);

Check warning on line 1349 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=AaGk2Tb8UJaCetOmTOrM&open=AaGk2Tb8UJaCetOmTOrM&pullRequest=187
Assert.AreEqual("readme.md", result[0]);
Assert.AreEqual("src/a.cs", result[1]);
Assert.AreEqual("a b", result[2]);
Expand All @@ -1348,7 +1357,7 @@
{
List<string> result = [.. TextFilter.Filter(["readme.md", "src/a.cs", "docs/"], "+**/")];

Assert.AreEqual(1, result.Count);

Check warning on line 1360 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=AaGk2Tb8UJaCetOmTOrL&open=AaGk2Tb8UJaCetOmTOrL&pullRequest=187
Assert.AreEqual("docs/", result[0]);
}

Expand Down Expand Up @@ -1559,11 +1568,11 @@
[TestMethod]
public void Pre17GenericFilterSignatureStillExists()
{
Assert.IsTrue(typeof(TextFilter).GetMethods().Any(m =>
m.Name == nameof(TextFilter.Filter)
&& m.IsGenericMethodDefinition
&& m.GetParameters().Length == 5
&& m.GetParameters()[4].ParameterType == typeof(TextFilterMatchOptions)));

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.Contains' instead of 'Assert.IsTrue'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2Tb8UJaCetOmTOrN&open=AaGk2Tb8UJaCetOmTOrN&pullRequest=187
}

[TestMethod]
Expand Down
10 changes: 9 additions & 1 deletion 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.

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 @@ -334,7 +334,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 337 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 337 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 337 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 failure on line 337 in TextFilter/TextFilter.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2TXFUJaCetOmTOrD&open=AaGk2TXFUJaCetOmTOrD&pullRequest=187
{
Ensure.NotNull(text);
Ensure.NotNull(filter);
Expand Down Expand Up @@ -408,7 +408,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 411 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 failure on line 411 in TextFilter/TextFilter.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2TXFUJaCetOmTOrE&open=AaGk2TXFUJaCetOmTOrE&pullRequest=187
{
Ensure.NotNull(filterToken);
Ensure.NotNull(textTokens);
Expand All @@ -425,7 +425,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 428 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 failure on line 428 in TextFilter/TextFilter.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2TXFUJaCetOmTOrF&open=AaGk2TXFUJaCetOmTOrF&pullRequest=187
{
Ensure.NotNull(filterToken);
Ensure.NotNull(textTokens);
Expand Down Expand Up @@ -471,6 +471,7 @@
{
string literal = maskedToken[start..index];
bool expandBothWays = expanded < MaxExpandedGlobStarSegments;
bool doubled = false;
List<string> next = new(expansions.Count * 2);

foreach (string prefix in expansions)
Expand All @@ -483,11 +484,18 @@
if (expandBothWays && (before.Length == 0 || before[^1] == MaskedPathSeparator))
{
next.Add(before);
doubled = true;
}
}

// Only a "**/" that actually added a zero-segment form counts against the cap, so ones
// joined to a literal don't use it up before a later whole-segment "**/" is reached.
expansions = next;
expanded++;
if (doubled)
{
expanded++;
}

start = index + MaskedGlobStarSegment.Length;
}

Expand All @@ -509,7 +517,7 @@
// MaxGlobClassMembers characters, or that has no members at all because every range is reversed.
private const int MaxGlobClassMembers = 4096;

internal static string? ExpandGlobClasses(string token)

Check warning on line 520 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 16 to the 15 allowed.

Check failure on line 520 in TextFilter/TextFilter.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2TXFUJaCetOmTOrG&open=AaGk2TXFUJaCetOmTOrG&pullRequest=187
{
if (!token.Contains(']'))
{
Expand Down Expand Up @@ -712,7 +720,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 723 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.

Check failure on line 723 in TextFilter/TextFilter.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_TextFilter&issues=AaGk2TXFUJaCetOmTOrH&open=AaGk2TXFUJaCetOmTOrH&pullRequest=187
{
Ensure.NotNull(text);
Ensure.NotNull(filter);
Expand Down
Loading