Skip to content

Commit b0ec137

Browse files
committed
add test to safe guard exact matches
1 parent 11c4aea commit b0ec137

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,31 @@ public void WhenGivenAQueryResultsShouldGiveMoreScoreWeightToStartOfNewWord(stri
253253
$"Should be greater than{ Environment.NewLine}" +
254254
$"CompareString2: \"{compareString2}\", Score: {compareString1Result.Score}{Environment.NewLine}");
255255
}
256+
257+
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
258+
public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
259+
string queryString, string firstName, string firstDescription, string firstExecutableName,
260+
string secondName, string secondDescription, string secondExecutableName)
261+
{
262+
// Act
263+
var matcher = new StringMatcher();
264+
var firstNameMatch = matcher.FuzzyMatch(queryString, firstName).RawScore;
265+
var firstDescriptionMatch = matcher.FuzzyMatch(queryString, firstDescription).RawScore;
266+
var firstExecutableNameMatch = matcher.FuzzyMatch(queryString, firstExecutableName).RawScore;
267+
268+
var secondNameMatch = matcher.FuzzyMatch(queryString, secondName).RawScore;
269+
var secondDescriptionMatch = matcher.FuzzyMatch(queryString, secondDescription).RawScore;
270+
var secondExecutableNameMatch = matcher.FuzzyMatch(queryString, secondExecutableName).RawScore;
271+
272+
var firstScore = new[] { firstNameMatch, firstDescriptionMatch, firstExecutableNameMatch }.Max();
273+
var secondScore = new[] { secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch }.Max();
274+
275+
// Assert
276+
Assert.IsTrue(firstScore > secondScore,
277+
$"Query: \"{queryString}\"{Environment.NewLine} " +
278+
$"Name of first: \"{firstName}\", Final Score: {firstScore}{Environment.NewLine}" +
279+
$"Should be greater than{ Environment.NewLine}" +
280+
$"Name of second: \"{secondName}\", Final Score: {secondScore}{Environment.NewLine}");
281+
}
256282
}
257283
}

0 commit comments

Comments
 (0)