YouCompleteMe/cpp/ycm/tests/Candidate_test.cpp
Strahinja Val Markovic a6e83bfe76 Smart-case sensitive filtering
Fixes #120
2013-03-01 22:18:43 -08:00

151 lines
8.0 KiB
C++

// Copyright (C) 2011, 2012 Strahinja Val Markovic <val@markovic.io>
//
// 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 "Candidate.h"
#include "Result.h"
namespace YouCompleteMe {
TEST( CandidateTest, TextValid ) {
std::string text = "foo";
Candidate candidate( text );
EXPECT_EQ( text, candidate.Text() );
}
TEST( CandidateTest, MatchesQueryBitsetWhenMatch ) {
Candidate candidate( "foobaaar" );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "foobaaar" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "fobar" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "rabof" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "bfroa" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "fbr" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "r" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "bbb" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "" ) ) );
}
TEST( CandidateTest, DoesntMatchQueryBitset ) {
Candidate candidate( "foobar" );
EXPECT_FALSE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "foobare" ) ) );
EXPECT_FALSE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "gggg" ) ) );
EXPECT_FALSE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "x" ) ) );
EXPECT_FALSE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "nfoobar" ) ) );
EXPECT_FALSE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "fbrmmm" ) ) );
}
TEST( CandidateTest, QueryMatchResultCaseInsensitiveIsSubsequence ) {
Candidate candidate( "foobaaar" );
EXPECT_TRUE( candidate.QueryMatchResult( "foobaaar", false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "foOBAaar", false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "FOOBAAAR", false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "fobar" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "fbr" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "f" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "F" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "o" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "O" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "a" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "r" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "b" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "bar" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "oa" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "obr" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "oar" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "oo" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "aaa" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "AAA" , false ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "" , false ).IsSubsequence() );
}
TEST( CandidateTest, QueryMatchResultCaseInsensitiveIsntSubsequence ) {
Candidate candidate( "foobaaar" );
EXPECT_FALSE( candidate.QueryMatchResult( "foobra" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "frb" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "brf" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "x" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "9" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "-" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "~" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( " " , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "rabof" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "oabfr" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "ooo" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "baaara" , false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "ffoobaaar", false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "xfoobaaar", false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( " foobaaar", false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "foobaaar ", false ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "ff" , false ).IsSubsequence() );
}
TEST( CandidateTest, QueryMatchResultCaseSensitiveIsSubsequence ) {
Candidate candidate( "FooBaAAr" );
EXPECT_TRUE( candidate.QueryMatchResult( "FooBaAAr", true ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "FBAA" , true ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "F" , true ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "AA" , true ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "A" , true ).IsSubsequence() );
EXPECT_TRUE( candidate.QueryMatchResult( "B" , true ).IsSubsequence() );
}
TEST( CandidateTest, QueryMatchResultCaseSensitiveIsntSubsequence ) {
Candidate candidate( "FooBaAAr" );
EXPECT_FALSE( candidate.QueryMatchResult( "foobaaar", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "foobaAAr", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "fbAA" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "fbaa" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "R" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "b" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "f" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "O" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "OO" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "OBA" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "FBAR" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "fbar" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "FBAAR" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "Oar" , true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "FooBaAAR", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "FooBAAAr", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "FOoBaAAr", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "FOobaaar", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "fOobaaar", true ).IsSubsequence() );
EXPECT_FALSE( candidate.QueryMatchResult( "foobaaaR", true ).IsSubsequence() );
}
} // namespace YouCompleteMe