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>
|
2012-07-11 02:13:12 -04:00
|
|
|
#include "IdentifierCompleter.h"
|
2012-04-15 19:57:10 -04:00
|
|
|
#include "Utils.h"
|
2012-07-22 18:19:28 -04:00
|
|
|
#include "TestUtils.h"
|
2012-04-15 19:57:10 -04:00
|
|
|
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
using ::testing::WhenSorted;
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
namespace YouCompleteMe {
|
2012-04-15 19:57:10 -04:00
|
|
|
|
|
|
|
|
2012-07-15 22:44:35 -04:00
|
|
|
// This differs from what we expect from the ClangCompleter. That one should
|
|
|
|
// return results for an empty query.
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, EmptyQueryNoResults ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar" ) ).CandidatesForQuery( "" ),
|
|
|
|
ElementsAre() );
|
2012-07-15 22:44:35 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, NoDuplicatesReturned ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar",
|
|
|
|
"foobar",
|
|
|
|
"foobar" ) ).CandidatesForQuery( "foo" ),
|
|
|
|
ElementsAre( "foobar" ) );
|
2012-07-21 15:06:18 -04:00
|
|
|
}
|
|
|
|
|
2012-07-15 22:44:35 -04:00
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, OneCandidate ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar" ) ).CandidatesForQuery( "fbr" ),
|
|
|
|
ElementsAre( "foobar" ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, ManyCandidateSimple ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar",
|
|
|
|
"foobartest",
|
|
|
|
"Foobartest" ) ).CandidatesForQuery( "fbr" ),
|
|
|
|
WhenSorted( ElementsAre( "Foobartest",
|
|
|
|
"foobar",
|
|
|
|
"foobartest" ) ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, FirstCharSameAsQueryWins ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar",
|
|
|
|
"afoobar" ) ).CandidatesForQuery( "fbr" ),
|
|
|
|
ElementsAre( "foobar",
|
|
|
|
"afoobar" ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, CompleteMatchForWordBoundaryCharsWins ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"FooBarQux",
|
|
|
|
"FBaqux" ) ).CandidatesForQuery( "fbq" ),
|
|
|
|
ElementsAre( "FooBarQux",
|
|
|
|
"FBaqux" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"CompleterTest",
|
|
|
|
"CompleteMatchForWordBoundaryCharsWins" ) )
|
|
|
|
.CandidatesForQuery( "ct" ),
|
|
|
|
ElementsAre( "CompleterTest",
|
|
|
|
"CompleteMatchForWordBoundaryCharsWins" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"FooBar",
|
|
|
|
"FooBarRux" ) ).CandidatesForQuery( "fbr" ),
|
|
|
|
ElementsAre( "FooBarRux",
|
|
|
|
"FooBar" ) );
|
2012-04-15 23:10:39 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, RatioUtilizationTieBreak ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"aGaaFooBarQux",
|
|
|
|
"aBaafbq" ) ).CandidatesForQuery( "fbq" ),
|
|
|
|
ElementsAre( "aGaaFooBarQux",
|
|
|
|
"aBaafbq" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"aFooBarQux",
|
|
|
|
"afbq" ) ).CandidatesForQuery( "fbq" ),
|
|
|
|
ElementsAre( "aFooBarQux",
|
|
|
|
"afbq" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"acaaCaaFooGxx",
|
|
|
|
"aCaafoog" ) ).CandidatesForQuery( "caafoo" ),
|
|
|
|
ElementsAre( "acaaCaaFooGxx",
|
|
|
|
"aCaafoog" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"acaaCaaFooGxx",
|
|
|
|
"aCaafoog" ) ).CandidatesForQuery( "caaFoo" ),
|
|
|
|
ElementsAre( "acaaCaaFooGxx",
|
|
|
|
"aCaafoog" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"FooBarQux",
|
|
|
|
"FooBarQuxZaa" ) ).CandidatesForQuery( "fbq" ),
|
|
|
|
ElementsAre( "FooBarQux",
|
|
|
|
"FooBarQuxZaa" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"FooBar",
|
|
|
|
"FooBarRux" ) ).CandidatesForQuery( "fba" ),
|
|
|
|
ElementsAre( "FooBar",
|
|
|
|
"FooBarRux" ) );
|
2012-04-15 23:10:39 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, QueryPrefixOfCandidateWins ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar",
|
|
|
|
"fbaroo" ) ).CandidatesForQuery( "foo" ),
|
|
|
|
ElementsAre( "foobar",
|
|
|
|
"fbaroo" ) );
|
2012-04-17 00:57:20 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, LowerMatchCharIndexSumWins ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"ratio_of_word_boundary_chars_in_query_",
|
|
|
|
"first_char_same_in_query_and_text_" ) )
|
|
|
|
.CandidatesForQuery( "charinq" ),
|
|
|
|
ElementsAre( "first_char_same_in_query_and_text_",
|
|
|
|
"ratio_of_word_boundary_chars_in_query_" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"barfooq",
|
|
|
|
"barquxfoo" ) ).CandidatesForQuery( "foo" ),
|
|
|
|
ElementsAre( "barfooq",
|
|
|
|
"barquxfoo" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"xxxxxxabc",
|
|
|
|
"xxabcxxxx" ) ).CandidatesForQuery( "abc" ),
|
|
|
|
ElementsAre( "xxabcxxxx",
|
|
|
|
"xxxxxxabc" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"FooBarQux",
|
|
|
|
"FaBarQux" ) ).CandidatesForQuery( "fbq" ),
|
|
|
|
ElementsAre( "FaBarQux",
|
|
|
|
"FooBarQux" ) );
|
2012-06-24 18:35:00 -04:00
|
|
|
}
|
2012-04-15 23:10:39 -04:00
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, ShorterCandidateWins ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"CompleterT",
|
|
|
|
"CompleterTest" ) ).CandidatesForQuery( "co" ),
|
|
|
|
ElementsAre( "CompleterT",
|
|
|
|
"CompleterTest" ) );
|
|
|
|
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"CompleterT",
|
|
|
|
"CompleterTest" ) ).CandidatesForQuery( "plet" ),
|
|
|
|
ElementsAre( "CompleterT",
|
|
|
|
"CompleterTest" ) );
|
2012-04-15 19:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-01-19 23:17:12 -05:00
|
|
|
TEST( IdentifierCompleterTest, SameLowercaseCandidateWins ) {
|
|
|
|
EXPECT_THAT( IdentifierCompleter(
|
|
|
|
StringVector(
|
|
|
|
"foobar",
|
|
|
|
"Foobar" ) ).CandidatesForQuery( "foo" ),
|
|
|
|
ElementsAre( "foobar",
|
|
|
|
"Foobar" ) );
|
2012-04-17 01:13:05 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|