forked from qt-creator/qt-creator
Clang: Test for file path RequestSourceLocationsForRenamingMessage
Change-Id: Ia384deb60e644d8894d7c56f81b3deb8b7706c11 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -105,6 +105,12 @@ public:
|
|||||||
return SourceLocationsContainer(Utils::clone(filePathHash), Utils::clone(sourceLocationContainers_));
|
return SourceLocationsContainer(Utils::clone(filePathHash), Utils::clone(sourceLocationContainers_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const std::unordered_map<uint, FilePath> &filePathsForTestOnly() const
|
||||||
|
{
|
||||||
|
return filePathHash;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<uint, FilePath> filePathHash;
|
std::unordered_map<uint, FilePath> filePathHash;
|
||||||
std::vector<V2::SourceLocationContainer> sourceLocationContainers_;
|
std::vector<V2::SourceLocationContainer> sourceLocationContainers_;
|
||||||
|
|||||||
@@ -43,14 +43,26 @@
|
|||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
inline
|
inline
|
||||||
Utils::SmallString absolutePath(const char *path)
|
llvm::SmallString<256> absolutePath(const char *path)
|
||||||
{
|
{
|
||||||
llvm::SmallString<256> absolutePath(path);
|
llvm::SmallString<256> absolutePath(path);
|
||||||
|
|
||||||
if (!llvm::sys::path::is_absolute(absolutePath))
|
if (!llvm::sys::path::is_absolute(absolutePath))
|
||||||
llvm::sys::fs::make_absolute(absolutePath);
|
llvm::sys::fs::make_absolute(absolutePath);
|
||||||
|
|
||||||
return Utils::SmallString(absolutePath.begin(), absolutePath.end());
|
return absolutePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Container>
|
||||||
|
Utils::SmallString fromNativePath(Container container)
|
||||||
|
{
|
||||||
|
Utils::SmallString path(container.data(), container.size());
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
std::replace(path.begin(), path.end(), '\\', '/');
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -65,12 +77,13 @@ void appendSourceLocationsToSourceLocationsContainer(
|
|||||||
clang::FullSourceLoc fullSourceLocation(sourceLocation, sourceManager);
|
clang::FullSourceLoc fullSourceLocation(sourceLocation, sourceManager);
|
||||||
auto fileId = fullSourceLocation.getFileID();
|
auto fileId = fullSourceLocation.getFileID();
|
||||||
auto fileEntry = sourceManager.getFileEntryForID(fileId);
|
auto fileEntry = sourceManager.getFileEntryForID(fileId);
|
||||||
auto fileName = fileEntry->getName();
|
auto filePath = absolutePath(fileEntry->getName());
|
||||||
auto fileDirectoryPath = absolutePath(fileEntry->getDir()->getName());
|
auto fileName = llvm::sys::path::filename(filePath);
|
||||||
|
llvm::sys::path::remove_filename(filePath);
|
||||||
|
|
||||||
sourceLocationsContainer.insertFilePath(fileId.getHashValue(),
|
sourceLocationsContainer.insertFilePath(fileId.getHashValue(),
|
||||||
std::move(fileDirectoryPath),
|
fromNativePath(filePath),
|
||||||
fileName);
|
fromNativePath(fileName));
|
||||||
sourceLocationsContainer.insertSourceLocation(fileId.getHashValue(),
|
sourceLocationsContainer.insertSourceLocation(fileId.getHashValue(),
|
||||||
fullSourceLocation.getSpellingLineNumber(),
|
fullSourceLocation.getSpellingLineNumber(),
|
||||||
fullSourceLocation.getSpellingColumnNumber());
|
fullSourceLocation.getSpellingColumnNumber());
|
||||||
|
|||||||
@@ -39,12 +39,15 @@ namespace {
|
|||||||
|
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::Contains;
|
using testing::Contains;
|
||||||
|
using testing::Pair;
|
||||||
using testing::PrintToString;
|
using testing::PrintToString;
|
||||||
using testing::Property;
|
using testing::Property;
|
||||||
|
using testing::_;
|
||||||
|
|
||||||
using ClangBackEnd::RequestSourceLocationsForRenamingMessage;
|
using ClangBackEnd::RequestSourceLocationsForRenamingMessage;
|
||||||
using ClangBackEnd::SourceLocationsContainer;
|
using ClangBackEnd::SourceLocationsContainer;
|
||||||
using ClangBackEnd::SourceLocationsForRenamingMessage;
|
using ClangBackEnd::SourceLocationsForRenamingMessage;
|
||||||
|
using ClangBackEnd::FilePath;
|
||||||
|
|
||||||
MATCHER_P2(IsSourceLocation, line, column,
|
MATCHER_P2(IsSourceLocation, line, column,
|
||||||
std::string(negation ? "isn't" : "is")
|
std::string(negation ? "isn't" : "is")
|
||||||
@@ -83,9 +86,11 @@ TEST_F(RefactoringServer, RequestSourceLocationsForRenamingMessage)
|
|||||||
sourceLocationsForRenamingMessage(
|
sourceLocationsForRenamingMessage(
|
||||||
AllOf(Property(&SourceLocationsForRenamingMessage::symbolName, "v"),
|
AllOf(Property(&SourceLocationsForRenamingMessage::symbolName, "v"),
|
||||||
Property(&SourceLocationsForRenamingMessage::sourceLocations,
|
Property(&SourceLocationsForRenamingMessage::sourceLocations,
|
||||||
Property(&SourceLocationsContainer::sourceLocationContainers,
|
AllOf(Property(&SourceLocationsContainer::sourceLocationContainers,
|
||||||
AllOf(Contains(IsSourceLocation(1, 5)),
|
AllOf(Contains(IsSourceLocation(1, 5)),
|
||||||
Contains(IsSourceLocation(3, 9))))))))
|
Contains(IsSourceLocation(3, 9)))),
|
||||||
|
Property(&SourceLocationsContainer::filePathsForTestOnly,
|
||||||
|
Contains(Pair(_, FilePath(TESTDATA_DIR, "renamevariable.cpp")))))))))
|
||||||
.Times(1);
|
.Times(1);
|
||||||
|
|
||||||
refactoringServer.requestSourceLocationsForRenamingMessage(std::move(requestSourceLocationsForRenamingMessage));
|
refactoringServer.requestSourceLocationsForRenamingMessage(std::move(requestSourceLocationsForRenamingMessage));
|
||||||
|
|||||||
Reference in New Issue
Block a user