TEST( ClangCompleterTest, CandidatesForLocationInFile ) {
  ClangCompleter completer;
  std::vector< CompletionData > completions =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "basic.cpp" ).string(),
      11,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  EXPECT_TRUE( !completions.empty() );
}
Пример #2
0
TEST( ClangCompleterTest, NoTranslationUnit ) {
  ClangCompleter completer;

  const std::string filename;
  const std::vector< UnsavedFile > unsaved_files;
  const std::vector< std::string > flags;

  EXPECT_EQ( std::vector< Diagnostic >(),
             completer.UpdateTranslationUnit( filename, unsaved_files, flags) );

  EXPECT_EQ( std::vector< CompletionData >(),
             completer.CandidatesForLocationInFile( filename,
                                                    1,
                                                    1,
                                                    unsaved_files,
                                                    flags ) );

  EXPECT_EQ( Location(), completer.GetDeclarationLocation( filename,
                                                           1,
                                                           1,
                                                           unsaved_files,
                                                           flags ) );
  EXPECT_EQ( Location(), completer.GetDefinitionLocation( filename,
                                                          1,
                                                          1,
                                                          unsaved_files,
                                                          flags ) );
  EXPECT_EQ( std::string( "no unit" ),
             completer.GetTypeAtLocation( filename,
                                          1,
                                          1,
                                          unsaved_files,
                                          flags ) );
  EXPECT_EQ( std::string( "no unit" ),
             completer.GetEnclosingFunctionAtLocation( filename,
                                                       1,
                                                       1,
                                                       unsaved_files,
                                                       flags ) );
  EXPECT_EQ( std::vector< FixIt >(),
             completer.GetFixItsForLocationInFile( filename,
                                                   1,
                                                   1,
                                                   unsaved_files,
                                                   flags ) );

  EXPECT_EQ( DocumentationData(),
             completer.GetDocsForLocationInFile( filename,
                                                 1,
                                                 1,
                                                 unsaved_files,
                                                 flags ) );
}
TEST( ClangCompleterTest, GetDefinitionLocation ) {
  ClangCompleter completer;
  std::string filename = PathToTestFile( "basic.cpp" ).string();

  // Clang operates on the reasonable assumption that line and column numbers
  // are 1-based.
  Location actual_location =
    completer.GetDefinitionLocation(
      filename,
      9,
      3,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  EXPECT_EQ( Location( filename, 1, 8 ), actual_location );
}
Пример #4
0
TEST( ClangCompleterTest, CandidatesObjCForLocationInFile ) {
  ClangCompleter completer;
  std::vector< std::string > flags;
  flags.push_back( "-x" );
  flags.push_back( "objective-c" );
  std::vector< CompletionData > completions =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "SWObject.m" ).string(),
      6,
      16,
      std::vector< UnsavedFile >(),
      flags );

  ASSERT_TRUE( !completions.empty() );
  EXPECT_THAT( completions[0].TextToInsertInBuffer(), StrEq( "withArg2:" ) );
}
Пример #5
0
TEST( ClangCompleterTest, BufferTextNoParens ) {
  ClangCompleter completer;
  std::vector< CompletionData > completions =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "basic.cpp" ).string(),
      29,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  ASSERT_TRUE( !completions.empty() );
  EXPECT_THAT( completions,
               Contains(
                 Property( &CompletionData::TextToInsertInBuffer,
                           StrEq( "barbar" ) ) ) );
}
TEST( ClangCompleterTest, GetDocString ) {
  ClangCompleter completer;

  std::vector< CompletionData > completions =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "basic.cpp" ).string(),
      11,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  for ( size_t i = 0; i < completions.size(); ++i ) {
    if ( completions[i].TextToInsertInBuffer() == "x" ) {
      EXPECT_STREQ( "A docstring.", completions[i].DocString().c_str() );
      break;
    }
  }
}
Пример #7
0
TEST( ClangCompleterTest, MemberFunctionWithDefaults ) {
  ClangCompleter completer;
  std::vector< CompletionData > completions =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "basic.cpp" ).string(),
      30,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  for ( size_t i = 0; i < completions.size(); ++i ) {
    if ( completions[i].TextToInsertInBuffer() == "foobar" ) {
      EXPECT_STREQ( "foobar( int a, float b = 3.0, char c = '\\n' )",
                    completions[i].MainCompletionText().c_str() );
      break;
    }
  }
}
Пример #8
0
TEST( ClangCompleterTest, CandidatesForLocationInFile ) {
  ClangCompleter completer;
  std::vector< CompletionData > completions_class =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "basic.cpp" ).string(),
      29,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );
  std::vector< CompletionData > completions_struct =
    completer.CandidatesForLocationInFile(
      PathToTestFile( "basic.cpp" ).string(),
      30,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  ASSERT_TRUE( !completions_struct.empty() );
  ASSERT_TRUE( !completions_class.empty() );
}
Пример #9
0
TEST( ClangCompleterTest, GetDefinitionLocation ) {
  ClangCompleter completer;
  std::string filename = PathToTestFile( "basic.cpp" ).string();

  // Clang operates on the reasonable assumption that line and column numbers
  // are 1-based.
  Location actual_location_struct =
    completer.GetDefinitionLocation(
      filename,
      26,
      3,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  Location actual_location_class_method =
    completer.GetDefinitionLocation(
      filename,
      29,
      7,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  Location actual_location_class =
    completer.GetDefinitionLocation(
      filename,
      27,
      3,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  Location actual_location_enum_value =
    completer.GetDefinitionLocation(
      filename,
      31,
      25,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  Location actual_location_enum =
    completer.GetDefinitionLocation(
      filename,
      31,
      3,
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );

  EXPECT_EQ( Location( filename, 12, 8 ), actual_location_struct );
  EXPECT_EQ( Location( filename, 1, 7 ), actual_location_class );
  EXPECT_EQ( Location( filename, 22, 35 ), actual_location_enum );
  EXPECT_EQ( Location( filename, 22, 16 ), actual_location_enum_value );
  EXPECT_EQ( Location( filename, 7, 8 ), actual_location_class_method );
}