Skip to content

Commit adf9d60

Browse files
Fix BenchmarkSwitcher user input matching (#2151)
1 parent db8f8d8 commit adf9d60

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/BenchmarkDotNet/Running/UserInteraction.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,23 @@ private static IEnumerable<Type> GetMatching(IReadOnlyList<Type> allTypes, strin
9090
if (userInput.IsEmpty())
9191
yield break;
9292

93+
var integerInput = userInput.Where(arg => IsInteger(arg)).ToArray();
94+
var stringInput = userInput.Where(arg => !IsInteger(arg)).ToArray();
95+
9396
for (int i = 0; i < allTypes.Count; i++)
9497
{
9598
var type = allTypes[i];
9699

97-
if (userInput.Any(arg => type.GetDisplayName().ContainsWithIgnoreCase(arg))
98-
|| userInput.Contains($"#{i}")
99-
|| userInput.Contains(i.ToString())
100-
|| userInput.Contains("*"))
100+
if (stringInput.Any(arg => type.GetDisplayName().ContainsWithIgnoreCase(arg))
101+
|| stringInput.Contains($"#{i}")
102+
|| integerInput.Contains($"{i}")
103+
|| stringInput.Contains("*"))
101104
{
102105
yield return type;
103106
}
104107
}
108+
109+
static bool IsInteger(string str) => int.TryParse(str, out _);
105110
}
106111

107112
private static void PrintAvailable([NotNull] IReadOnlyList<Type> allTypes, ILogger logger)

0 commit comments

Comments
 (0)