Fixing a bug with word-boundary ratio calculation

This commit is contained in:
Strahinja Val Markovic 2012-06-24 15:11:58 -07:00
parent a8f095ec0a
commit adb31abef2
2 changed files with 15 additions and 3 deletions

View File

@ -36,11 +36,11 @@ int NumWordBoundaryCharMatches( const std::string &query,
while ( j < query.size() && i < word_boundary_chars.size() ) while ( j < query.size() && i < word_boundary_chars.size() )
{ {
if ( toupper( query[ j ] ) == toupper( word_boundary_chars[ i ] ) ) if ( toupper( query[ j ] ) == toupper( word_boundary_chars[ i ] ) )
++i; ++j;
++j; ++i;
} }
return i; return j;
} }
} // unnamed namespace } // unnamed namespace

View File

@ -116,6 +116,18 @@ TEST( CompleterTest, CompleteMatchForWordBoundaryCharsWins )
TEST( CompleterTest, RatioUtilizationTieBreak ) TEST( CompleterTest, RatioUtilizationTieBreak )
{ {
EXPECT_THAT( Completer( Candidates(
"aGaaFooBarQux",
"aBaafbq" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "aGaaFooBarQux",
"aBaafbq" ) );
EXPECT_THAT( Completer( Candidates(
"aFooBarQux",
"afbq" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "aFooBarQux",
"afbq" ) );
EXPECT_THAT( Completer( Candidates( EXPECT_THAT( Completer( Candidates(
"FooBarQux", "FooBarQux",
"FooBarQuxZaa" ) ).CandidatesForQuery( "fbq" ), "FooBarQuxZaa" ) ).CandidatesForQuery( "fbq" ),