TEST( IdentifierCompleterTest, TagsEndToEndWorks ) {
  IdentifierCompleter completer;
  std::vector< std::string > tag_files;
  tag_files.push_back( PathToTestFile( "basic.tags" ).string() );

  completer.AddIdentifiersToDatabaseFromTagFiles( tag_files );

  EXPECT_THAT( completer.CandidatesForQueryAndType( "fo", "cpp" ),
               ElementsAre( "foosy",
                            "fooaaa" ) );

}
Example #2
0
TEST_F( TranslationUnitTest, GoToDefinitionFails ) {
  TranslationUnit unit( PathToTestFile( "goto.cpp" ).string(),
                        std::vector< UnsavedFile >(),
                        std::vector< std::string >(),
                        clang_index_ );

  Location location = unit.GetDefinitionLocation(
                        19,
                        3,
                        std::vector< UnsavedFile >() );

  EXPECT_FALSE( location.IsValid() );
}
Example #3
0
TEST_F( TranslationUnitTest, GoToDeclarationWorks ) {
  TranslationUnit unit( PathToTestFile( "goto.cpp" ).string(),
                        std::vector< UnsavedFile >(),
                        std::vector< std::string >(),
                        clang_index_ );

  Location location = unit.GetDeclarationLocation(
                        19,
                        3,
                        std::vector< UnsavedFile >() );

  EXPECT_EQ( 12, location.line_number_ );
  EXPECT_EQ( 8, location.column_number_ );
  EXPECT_TRUE( !location.filename_.empty() );
}
Example #4
0
TEST_F( TranslationUnitTest, InvalidTranslationUnitStore ) {
  // libclang fails to parse a file with no extension and no language flag -x
  // given.
  TranslationUnitStore translation_unit_store{ clang_index_ };
  try {
    translation_unit_store.GetOrCreate(
      PathToTestFile( "file_without_extension" ).string(),
      std::vector< UnsavedFile >(),
      std::vector< std::string >() );
    FAIL() << "Expected ClangParseError exception.";
  } catch ( const ClangParseError &error ) {
    EXPECT_STREQ( error.what(),
                  "An AST deserialization error occurred while parsing "
                  "the translation unit." );
  } catch ( ... ) {
    FAIL() << "Expected ClangParseError exception.";
  }
}
Example #5
0
TEST_F( TranslationUnitTest, ExceptionThrownOnParseFailure ) {
  // Create a translation unit for a C++ file that is not saved on disk.
  std::string filename = PathToTestFile( "unsaved_file.cpp" ).string();
  UnsavedFile unsaved_file;
  unsaved_file.filename_ = filename;

  try {
    // libclang requires a valid index to parse a file.
    TranslationUnit( filename,
                     std::vector< UnsavedFile >{ unsaved_file },
                     std::vector< std::string >(),
                     nullptr );
    FAIL() << "Expected ClangParseError exception.";
  } catch ( const ClangParseError &error ) {
    EXPECT_STREQ( error.what(), "Invalid arguments supplied "
                                "when parsing the translation unit." );
  } catch ( ... ) {
    FAIL() << "Expected ClangParseError exception.";
  }
}