Formatting more code with astyle

This commit is contained in:
Strahinja Val Markovic 2013-01-19 20:17:12 -08:00
parent 4308130ab3
commit 1641bc9683
10 changed files with 257 additions and 262 deletions

View File

@ -19,41 +19,37 @@
#include "Candidate.h"
#include "Result.h"
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( CandidateTest, TextValid )
{
TEST( CandidateTest, TextValid ) {
std::string text = "foo";
Candidate candidate( text );
EXPECT_EQ( text, candidate.Text() );
}
TEST( CandidateTest, MatchesQueryBitsetWhenMatch )
{
TEST( CandidateTest, MatchesQueryBitsetWhenMatch ) {
Candidate candidate( "foobaaar" );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "foobaaar" ) ) );
LetterBitsetFromString( "foobaaar" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "fobar" ) ) );
LetterBitsetFromString( "fobar" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "rabof" ) ) );
LetterBitsetFromString( "rabof" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "bfroa" ) ) );
LetterBitsetFromString( "bfroa" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "fbr" ) ) );
LetterBitsetFromString( "fbr" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "r" ) ) );
LetterBitsetFromString( "r" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "bbb" ) ) );
LetterBitsetFromString( "bbb" ) ) );
EXPECT_TRUE( candidate.MatchesQueryBitset(
LetterBitsetFromString( "" ) ) );
LetterBitsetFromString( "" ) ) );
}
TEST( CandidateTest, DoesntMatchQueryBitset )
{
TEST( CandidateTest, DoesntMatchQueryBitset ) {
Candidate candidate( "foobar" );
EXPECT_FALSE( candidate.MatchesQueryBitset(
@ -68,8 +64,7 @@ TEST( CandidateTest, DoesntMatchQueryBitset )
LetterBitsetFromString( "fbrmmm" ) ) );
}
TEST( CandidateTest, QueryMatchResultIsSubsequence )
{
TEST( CandidateTest, QueryMatchResultIsSubsequence ) {
Candidate candidate( "foobaaar" );
EXPECT_TRUE( candidate.QueryMatchResult( "foobaaar" ).IsSubsequence() );
@ -88,8 +83,7 @@ TEST( CandidateTest, QueryMatchResultIsSubsequence )
EXPECT_TRUE( candidate.QueryMatchResult( "" ).IsSubsequence() );
}
TEST( CandidateTest, QueryMatchResultIsntSubsequence )
{
TEST( CandidateTest, QueryMatchResultIsntSubsequence ) {
Candidate candidate( "foobaaar" );
EXPECT_FALSE( candidate.QueryMatchResult( "foobra" ).IsSubsequence() );

View File

@ -26,29 +26,26 @@ namespace fs = boost::filesystem;
using ::testing::ElementsAre;
using ::testing::WhenSorted;
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( ClangCompleterTest, CandidatesForLocationInFile )
{
TEST( ClangCompleterTest, CandidatesForLocationInFile ) {
fs::path path_to_testdata = fs::current_path() / fs::path( "testdata" );
fs::path test_file = path_to_testdata / fs::path( "basic.cpp" );
ClangCompleter completer;
std::vector< CompletionData > completions =
completer.CandidatesForLocationInFile(
test_file.string(),
11,
7,
std::vector< UnsavedFile >(),
std::vector< std::string >() );
test_file.string(),
11,
7,
std::vector< UnsavedFile >(),
std::vector< std::string >() );
EXPECT_TRUE( !completions.empty() );
}
TEST( ClangCompleterTest, CandidatesForQueryAndLocationInFileAsync )
{
TEST( ClangCompleterTest, CandidatesForQueryAndLocationInFileAsync ) {
fs::path path_to_testdata = fs::current_path() / fs::path( "testdata" );
fs::path test_file = path_to_testdata / fs::path( "basic.cpp" );
@ -57,12 +54,12 @@ TEST( ClangCompleterTest, CandidatesForQueryAndLocationInFileAsync )
Future< AsyncCompletions > completions_future =
completer.CandidatesForQueryAndLocationInFileAsync(
"",
test_file.string(),
11,
7,
std::vector< UnsavedFile >(),
std::vector< std::string >() );
"",
test_file.string(),
11,
7,
std::vector< UnsavedFile >(),
std::vector< std::string >() );
completions_future.Wait();

View File

@ -27,11 +27,9 @@ namespace fs = boost::filesystem;
using ::testing::ElementsAre;
using ::testing::WhenSorted;
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( TranslationUnitTest, ExceptionThrownOnParseFailure )
{
TEST( TranslationUnitTest, ExceptionThrownOnParseFailure ) {
fs::path test_file = fs::temp_directory_path() / fs::unique_path();
std::string junk = "#&9112(^(^#>@(^@!@(&#@a}}}}{nthoeu\n&&^^&^&!#%%@@!aeu";
WriteUtf8File( test_file, junk );

View File

@ -24,176 +24,186 @@
using ::testing::ElementsAre;
using ::testing::WhenSorted;
namespace YouCompleteMe
{
namespace YouCompleteMe {
// This differs from what we expect from the ClangCompleter. That one should
// return results for an empty query.
TEST( IdentifierCompleterTest, EmptyQueryNoResults )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar" ) ).CandidatesForQuery( "" ),
ElementsAre() );
TEST( IdentifierCompleterTest, EmptyQueryNoResults ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar" ) ).CandidatesForQuery( "" ),
ElementsAre() );
}
TEST( IdentifierCompleterTest, NoDuplicatesReturned )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar",
"foobar",
"foobar" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar" ) );
TEST( IdentifierCompleterTest, NoDuplicatesReturned ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar",
"foobar",
"foobar" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar" ) );
}
TEST( IdentifierCompleterTest, OneCandidate )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar" ) ).CandidatesForQuery( "fbr" ),
ElementsAre( "foobar" ) );
TEST( IdentifierCompleterTest, OneCandidate ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar" ) ).CandidatesForQuery( "fbr" ),
ElementsAre( "foobar" ) );
}
TEST( IdentifierCompleterTest, ManyCandidateSimple )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar",
"foobartest",
"Foobartest" ) ).CandidatesForQuery( "fbr" ),
WhenSorted( ElementsAre( "Foobartest",
"foobar",
"foobartest" ) ) );
TEST( IdentifierCompleterTest, ManyCandidateSimple ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar",
"foobartest",
"Foobartest" ) ).CandidatesForQuery( "fbr" ),
WhenSorted( ElementsAre( "Foobartest",
"foobar",
"foobartest" ) ) );
}
TEST( IdentifierCompleterTest, FirstCharSameAsQueryWins )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar",
"afoobar" ) ).CandidatesForQuery( "fbr" ),
ElementsAre( "foobar",
"afoobar" ) );
TEST( IdentifierCompleterTest, FirstCharSameAsQueryWins ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar",
"afoobar" ) ).CandidatesForQuery( "fbr" ),
ElementsAre( "foobar",
"afoobar" ) );
}
TEST( IdentifierCompleterTest, CompleteMatchForWordBoundaryCharsWins )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"FooBarQux",
"FBaqux" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "FooBarQux",
"FBaqux" ) );
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(
"CompleterTest",
"CompleteMatchForWordBoundaryCharsWins" ) )
.CandidatesForQuery( "ct" ),
ElementsAre( "CompleterTest",
"CompleteMatchForWordBoundaryCharsWins" ) );
EXPECT_THAT( IdentifierCompleter( StringVector(
"FooBar",
"FooBarRux" ) ).CandidatesForQuery( "fbr" ),
ElementsAre( "FooBarRux",
"FooBar" ) );
EXPECT_THAT( IdentifierCompleter(
StringVector(
"FooBar",
"FooBarRux" ) ).CandidatesForQuery( "fbr" ),
ElementsAre( "FooBarRux",
"FooBar" ) );
}
TEST( IdentifierCompleterTest, RatioUtilizationTieBreak )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"aGaaFooBarQux",
"aBaafbq" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "aGaaFooBarQux",
"aBaafbq" ) );
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(
"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(
"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(
"FooBarQux",
"FooBarQuxZaa" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "FooBarQux",
"FooBarQuxZaa" ) );
EXPECT_THAT( IdentifierCompleter( StringVector(
"FooBar",
"FooBarRux" ) ).CandidatesForQuery( "fba" ),
ElementsAre( "FooBar",
"FooBarRux" ) );
EXPECT_THAT( IdentifierCompleter(
StringVector(
"FooBar",
"FooBarRux" ) ).CandidatesForQuery( "fba" ),
ElementsAre( "FooBar",
"FooBarRux" ) );
}
TEST( IdentifierCompleterTest, QueryPrefixOfCandidateWins )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar",
"fbaroo" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar",
"fbaroo" ) );
TEST( IdentifierCompleterTest, QueryPrefixOfCandidateWins ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar",
"fbaroo" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar",
"fbaroo" ) );
}
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_") );
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(
"barfooq",
"barquxfoo" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "barfooq",
"barquxfoo" ) );
EXPECT_THAT( IdentifierCompleter( StringVector(
"xxxxxxabc",
"xxabcxxxx" ) ).CandidatesForQuery( "abc" ),
ElementsAre( "xxabcxxxx",
"xxxxxxabc") );
EXPECT_THAT( IdentifierCompleter(
StringVector(
"xxxxxxabc",
"xxabcxxxx" ) ).CandidatesForQuery( "abc" ),
ElementsAre( "xxabcxxxx",
"xxxxxxabc" ) );
EXPECT_THAT( IdentifierCompleter( StringVector(
"FooBarQux",
"FaBarQux" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "FaBarQux",
"FooBarQux" ) );
EXPECT_THAT( IdentifierCompleter(
StringVector(
"FooBarQux",
"FaBarQux" ) ).CandidatesForQuery( "fbq" ),
ElementsAre( "FaBarQux",
"FooBarQux" ) );
}
TEST( IdentifierCompleterTest, ShorterCandidateWins )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"CompleterT",
"CompleterTest" ) ).CandidatesForQuery( "co" ),
ElementsAre( "CompleterT",
"CompleterTest" ) );
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" ) );
EXPECT_THAT( IdentifierCompleter(
StringVector(
"CompleterT",
"CompleterTest" ) ).CandidatesForQuery( "plet" ),
ElementsAre( "CompleterT",
"CompleterTest" ) );
}
TEST( IdentifierCompleterTest, SameLowercaseCandidateWins )
{
EXPECT_THAT( IdentifierCompleter( StringVector(
"foobar",
"Foobar" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar",
"Foobar" ) );
TEST( IdentifierCompleterTest, SameLowercaseCandidateWins ) {
EXPECT_THAT( IdentifierCompleter(
StringVector(
"foobar",
"Foobar" ) ).CandidatesForQuery( "foo" ),
ElementsAre( "foobar",
"Foobar" ) );
}
// TODO: tests for filepath and filetype candidate storing

View File

@ -22,75 +22,72 @@
using ::testing::ElementsAre;
using ::testing::WhenSorted;
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( IdentifierUtilsTest, RemoveIdentifierFreeTextWorks )
{
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar //foo \n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
TEST( IdentifierUtilsTest, RemoveIdentifierFreeTextWorks ) {
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar //foo \n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar #foo \n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar #foo \n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar /* foo \n"
" foo2 */\n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar /* foo \n"
" foo2 */\n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar 'foo'\n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar 'foo'\n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar \"foo\"\n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"foo \n"
"bar \"foo\"\n"
"qux"
).c_str(),
"foo \n"
"bar \n"
"qux" );
}
TEST( IdentifierUtilsTest, ExtractIdentifiersFromTextWorks )
{
EXPECT_THAT( ExtractIdentifiersFromText(
"foo $_bar \n&BazGoo\n FOO= !!! '-' - _ (x) one-two !moo [qqq]"
),
ElementsAre( "foo",
"_bar",
"BazGoo",
"FOO",
"_",
"x",
"one",
"two",
"moo",
"qqq" ) );
TEST( IdentifierUtilsTest, ExtractIdentifiersFromTextWorks ) {
EXPECT_THAT( ExtractIdentifiersFromText(
"foo $_bar \n&BazGoo\n FOO= !!! '-' - _ (x) one-two !moo [qqq]"
),
ElementsAre( "foo",
"_bar",
"BazGoo",
"FOO",
"_",
"x",
"one",
"two",
"moo",
"qqq" ) );
}

View File

@ -18,11 +18,9 @@
#include <gtest/gtest.h>
#include "LetterNodeListMap.h"
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( IndexForCharTest, Basic )
{
TEST( IndexForCharTest, Basic ) {
EXPECT_EQ( static_cast<int>( 'a' ), IndexForChar( 'a' ) );
EXPECT_EQ( static_cast<int>( 'a' ), IndexForChar( 'A' ) );
EXPECT_EQ( static_cast<int>( 'z' ), IndexForChar( 'z' ) );

View File

@ -18,11 +18,9 @@
#include <gtest/gtest.h>
#include "LetterNodeListMap.h"
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( IsUppercaseTest, Basic )
{
TEST( IsUppercaseTest, Basic ) {
EXPECT_TRUE( IsUppercase( 'A' ) );
EXPECT_TRUE( IsUppercase( 'B' ) );
EXPECT_TRUE( IsUppercase( 'Z' ) );

View File

@ -18,11 +18,9 @@
#include <gtest/gtest.h>
#include "Candidate.h"
namespace YouCompleteMe
{
namespace YouCompleteMe {
TEST( LetterBitsetFromStringTest, Basic )
{
TEST( LetterBitsetFromStringTest, Basic ) {
Bitset expected;
expected.set( IndexForChar( 'a' ) );
expected.set( IndexForChar( 'o' ) );

View File

@ -17,8 +17,7 @@
#include "TestUtils.h"
namespace YouCompleteMe
{
namespace YouCompleteMe {
std::vector< std::string > StringVector( const std::string &a,
const std::string &b,
@ -28,25 +27,32 @@ std::vector< std::string > StringVector( const std::string &a,
const std::string &f,
const std::string &g,
const std::string &h,
const std::string &i )
{
const std::string &i ) {
std::vector< std::string > string_vector;
string_vector.push_back( a );
if ( !b.empty() )
string_vector.push_back( a );
if ( !b.empty() )
string_vector.push_back( b );
if ( !c.empty() )
if ( !c.empty() )
string_vector.push_back( c );
if ( !d.empty() )
if ( !d.empty() )
string_vector.push_back( d );
if ( !e.empty() )
if ( !e.empty() )
string_vector.push_back( e );
if ( !f.empty() )
if ( !f.empty() )
string_vector.push_back( f );
if ( !g.empty() )
if ( !g.empty() )
string_vector.push_back( g );
if ( !h.empty() )
if ( !h.empty() )
string_vector.push_back( h );
if ( !i.empty() )
if ( !i.empty() )
string_vector.push_back( i );
return string_vector;

View File

@ -21,8 +21,7 @@
#include <vector>
#include <string>
namespace YouCompleteMe
{
namespace YouCompleteMe {
std::vector< std::string > StringVector( const std::string &a,
const std::string &b = std::string(),