2012-04-15 23:28:46 -04:00
|
|
|
// Copyright (C) 2011, 2012 Strahinja Val Markovic <val@markovic.io>
|
2012-04-15 19:57:10 -04:00
|
|
|
//
|
|
|
|
// This file is part of YouCompleteMe.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include "Completer.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
using ::testing::WhenSorted;
|
|
|
|
|
|
|
|
namespace YouCompleteMe
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
std::vector< std::string > Candidates( const std::string &a,
|
|
|
|
const std::string &b = std::string(),
|
|
|
|
const std::string &c = std::string(),
|
|
|
|
const std::string &d = std::string(),
|
|
|
|
const std::string &e = std::string(),
|
|
|
|
const std::string &f = std::string(),
|
|
|
|
const std::string &g = std::string(),
|
|
|
|
const std::string &h = std::string(),
|
|
|
|
const std::string &i = std::string() )
|
2012-04-15 19:57:10 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
std::vector< std::string > candidates;
|
|
|
|
candidates.push_back( a );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !b.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( b );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !c.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( c );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !d.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( d );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !e.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( e );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !f.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( f );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !g.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( g );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !h.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( h );
|
2012-04-15 23:10:39 -04:00
|
|
|
if ( !i.empty() )
|
2012-05-08 01:10:28 -04:00
|
|
|
candidates.push_back( i );
|
2012-04-15 23:10:39 -04:00
|
|
|
|
|
|
|
return candidates;
|
|
|
|
}
|
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
} // unnamed namespace
|
|
|
|
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, OneCandidate )
|
2012-04-15 19:57:10 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"foobar" ) ).CandidatesForQuery( "fbr" ),
|
|
|
|
ElementsAre( "foobar" ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, ManyCandidateSimple )
|
2012-04-15 19:57:10 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"foobar",
|
|
|
|
"foobartest",
|
|
|
|
"Foobartest" ) ).CandidatesForQuery( "fbr" ),
|
2012-04-15 19:57:10 -04:00
|
|
|
WhenSorted( ElementsAre( "Foobartest",
|
|
|
|
"foobar",
|
|
|
|
"foobartest" ) ) );
|
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, FirstCharSameAsQueryWins )
|
2012-04-15 19:57:10 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"foobar",
|
|
|
|
"afoobar" ) ).CandidatesForQuery( "fbr" ),
|
2012-04-15 19:57:10 -04:00
|
|
|
ElementsAre( "foobar",
|
|
|
|
"afoobar" ) );
|
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, CompleteMatchForWordBoundaryCharsWins )
|
2012-04-15 19:57:10 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"FooBarQux",
|
|
|
|
"FBaqux" ) ).CandidatesForQuery( "fbq" ),
|
2012-04-15 23:10:39 -04:00
|
|
|
ElementsAre( "FooBarQux",
|
|
|
|
"FBaqux" ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"CompleterTest",
|
|
|
|
"CompleteMatchForWordBoundaryCharsWins" ) )
|
|
|
|
.CandidatesForQuery( "ct" ),
|
2012-04-15 23:10:39 -04:00
|
|
|
ElementsAre( "CompleterTest",
|
|
|
|
"CompleteMatchForWordBoundaryCharsWins" ) );
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"FooBar",
|
|
|
|
"FooBarRux" ) ).CandidatesForQuery( "fbr" ),
|
2012-04-15 23:10:39 -04:00
|
|
|
ElementsAre( "FooBarRux",
|
|
|
|
"FooBar" ) );
|
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, RatioUtilizationTieBreak )
|
2012-04-15 23:10:39 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"FooBarQux",
|
|
|
|
"FooBarQuxZaa" ) ).CandidatesForQuery( "fbq" ),
|
2012-04-15 19:57:10 -04:00
|
|
|
ElementsAre( "FooBarQux",
|
2012-04-15 23:10:39 -04:00
|
|
|
"FooBarQuxZaa" ) );
|
2012-04-29 16:44:11 -04:00
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"FooBar",
|
|
|
|
"FooBarRux" ) ).CandidatesForQuery( "fba" ),
|
2012-04-29 16:44:11 -04:00
|
|
|
ElementsAre( "FooBar",
|
|
|
|
"FooBarRux" ) );
|
2012-04-15 23:10:39 -04:00
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, QueryPrefixOfCandidateWins )
|
2012-04-17 00:57:20 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"foobar",
|
|
|
|
"fbaroo" ) ).CandidatesForQuery( "foo" ),
|
2012-04-17 00:57:20 -04:00
|
|
|
ElementsAre( "foobar",
|
|
|
|
"fbaroo" ) );
|
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, ShorterCandidateWins )
|
2012-04-15 23:10:39 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"FooBarQux",
|
|
|
|
"FaBarQux" ) ).CandidatesForQuery( "fbq" ),
|
2012-04-15 23:10:39 -04:00
|
|
|
ElementsAre( "FaBarQux",
|
|
|
|
"FooBarQux" ) );
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"CompleterT",
|
|
|
|
"CompleterTest" ) ).CandidatesForQuery( "co" ),
|
2012-04-15 23:10:39 -04:00
|
|
|
ElementsAre( "CompleterT",
|
|
|
|
"CompleterTest" ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2012-05-08 01:10:28 -04:00
|
|
|
TEST( CompleterTest, SameLowercaseCandidateWins )
|
2012-04-17 01:13:05 -04:00
|
|
|
{
|
2012-05-08 01:10:28 -04:00
|
|
|
EXPECT_THAT( Completer( Candidates(
|
|
|
|
"foobar",
|
|
|
|
"Foobar" ) ).CandidatesForQuery( "foo" ),
|
2012-04-17 01:13:05 -04:00
|
|
|
ElementsAre( "foobar",
|
|
|
|
"Foobar" ) );
|
|
|
|
}
|
|
|
|
|
2012-04-29 22:56:16 -04:00
|
|
|
// TODO: tests for filepath and filetype candidate storing
|
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
} // namespace YouCompleteMe
|
|
|
|
|