diff options
author | Manuel Klimek <klimek@google.com> | 2015-06-03 13:10:41 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2015-06-03 13:10:41 +0000 |
commit | 94a89231f6ca2c56228f5258d46c4d5d5c5581f5 (patch) | |
tree | f8e63eba32ba4408629381eebfbadbe76ed6016f /clang/unittests/Tooling/RefactoringTest.cpp | |
parent | 1f58ef71ea400d52cb8be5cfdc0bfd20e1389ce5 (diff) | |
download | bcm5719-llvm-94a89231f6ca2c56228f5258d46c4d5d5c5581f5.tar.gz bcm5719-llvm-94a89231f6ca2c56228f5258d46c4d5d5c5581f5.zip |
Allow replacements created from token ranges to specify language options.
The default language options will lead to incorrect replacements in C++
code, for example when trying to replace nested name specifiers ending
in "::".
llvm-svn: 238922
Diffstat (limited to 'clang/unittests/Tooling/RefactoringTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/RefactoringTest.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index 7e643fa66d9..6c2c16b484d 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -281,6 +281,7 @@ public: protected: clang::SourceManager *SM; + clang::ASTContext *Context; private: class FindConsumer : public clang::ASTConsumer { @@ -303,6 +304,7 @@ private: CreateASTConsumer(clang::CompilerInstance &compiler, llvm::StringRef dummy) override { Visitor->SM = &compiler.getSourceManager(); + Visitor->Context = &compiler.getASTContext(); /// TestConsumer will be deleted by the framework calling us. return llvm::make_unique<FindConsumer>(Visitor); } @@ -368,6 +370,29 @@ TEST(Replacement, TemplatedFunctionCall) { expectReplacementAt(CallToF.Replace, "input.cc", 43, 8); } +class NestedNameSpecifierAVisitor + : public TestVisitor<NestedNameSpecifierAVisitor> { +public: + bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLoc) { + if (NNSLoc.getNestedNameSpecifier()) { + if (const NamespaceDecl* NS = NNSLoc.getNestedNameSpecifier()->getAsNamespace()) { + if (NS->getName() == "a") { + Replace = Replacement(*SM, &NNSLoc, "", Context->getLangOpts()); + } + } + } + return TestVisitor<NestedNameSpecifierAVisitor>::TraverseNestedNameSpecifierLoc( + NNSLoc); + } + Replacement Replace; +}; + +TEST(Replacement, ColonColon) { + NestedNameSpecifierAVisitor VisitNNSA; + EXPECT_TRUE(VisitNNSA.runOver("namespace a { void f() { ::a::f(); } }")); + expectReplacementAt(VisitNNSA.Replace, "input.cc", 25, 5); +} + TEST(Range, overlaps) { EXPECT_TRUE(Range(10, 10).overlapsWith(Range(0, 11))); EXPECT_TRUE(Range(0, 11).overlapsWith(Range(10, 10))); |