YouCompleteMe/cpp/ycm/tests/IdentifierCompleter_test.cpp

223 lines
7.6 KiB
C++
Raw Normal View History

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 "IdentifierCompleter.h"
2012-04-15 19:57:10 -04:00
#include "Utils.h"
#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
// 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() );
}
2013-01-19 23:17:12 -05:00
TEST( IdentifierCompleterTest, NoDuplicatesReturned ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar",
"foobar",
"foobar" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar" ) );
}
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
}
TEST( IdentifierCompleterTest, SmartCaseFiltering ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"fooBar",
"fooBaR" ) ).CandidatesForQuery( "fBr" ),
ElementsAre( "fooBar" ) );
}
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(
"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" ) );
}
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-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" ) );
}
TEST( IdentifierCompleterTest, ShorterAndLowercaseWins ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"STDIN_FILENO",
"stdin" ) ).CandidatesForQuery( "std" ),
ElementsAre( "stdin",
"STDIN_FILENO" ) );
}
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