[llvm-branch-commits] [cfe-branch] r159761 - in /cfe/branches/tooling: include/clang/Tooling/Refactoring.h unittests/Tooling/RefactoringTest.cpp

Manuel Klimek klimek at google.com
Thu Jul 5 11:16:03 PDT 2012


Author: klimek
Date: Thu Jul  5 13:16:03 2012
New Revision: 159761

URL: http://llvm.org/viewvc/llvm-project?rev=159761&view=rev
Log:
Updates from mainline that were lost in merge hell.


Modified:
    cfe/branches/tooling/include/clang/Tooling/Refactoring.h
    cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp

Modified: cfe/branches/tooling/include/clang/Tooling/Refactoring.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/Refactoring.h?rev=159761&r1=159760&r2=159761&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Tooling/Refactoring.h (original)
+++ cfe/branches/tooling/include/clang/Tooling/Refactoring.h Thu Jul  5 13:16:03 2012
@@ -71,7 +71,7 @@
 
   /// \brief Accessors.
   /// @{
-  std::string getFilePath() const { return FilePath; }
+  StringRef getFilePath() const { return FilePath; }
   unsigned getOffset() const { return Offset; }
   unsigned getLength() const { return Length; }
   /// @}

Modified: cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp?rev=159761&r1=159760&r2=159761&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp (original)
+++ cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp Thu Jul  5 13:16:03 2012
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "RewriterTestContext.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
@@ -30,64 +31,20 @@
 namespace clang {
 namespace tooling {
 
-class RewriterTestContext {
- public:
-  RewriterTestContext()
-      : Diagnostics(llvm::IntrusiveRefCntPtr<DiagnosticIDs>()),
-        DiagnosticPrinter(llvm::outs(), DiagnosticOptions()),
-        Files((FileSystemOptions())),
-        Sources(Diagnostics, Files),
-        Rewrite(Sources, Options) {
-    Diagnostics.setClient(&DiagnosticPrinter, false);
-  }
-
-  FileID createInMemoryFile(llvm::StringRef Name, llvm::StringRef Content) {
-    const llvm::MemoryBuffer *Source =
-      llvm::MemoryBuffer::getMemBuffer(Content);
-    const FileEntry *Entry =
-      Files.getVirtualFile(Name, Source->getBufferSize(), 0);
-    Sources.overrideFileContents(Entry, Source, true);
-    assert(Entry != NULL);
-    return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
-  }
-
-  SourceLocation getLocation(FileID ID, unsigned Line, unsigned Column) {
-    SourceLocation Result = Sources.translateFileLineCol(
-        Sources.getFileEntryForID(ID), Line, Column);
-    assert(Result.isValid());
-    return Result;
-  }
-
-  std::string getRewrittenText(FileID ID) {
-    std::string Result;
-    llvm::raw_string_ostream OS(Result);
-    Rewrite.getEditBuffer(ID).write(OS);
-    OS.flush();
-    return Result;
-  }
-
+class ReplacementTest : public ::testing::Test {
+ protected:
   Replacement createReplacement(SourceLocation Start, unsigned Length,
                                 llvm::StringRef ReplacementText) {
-    return Replacement(Sources, Start, Length, ReplacementText);
+    return Replacement(Context.Sources, Start, Length, ReplacementText);
   }
 
-  DiagnosticsEngine Diagnostics;
-  TextDiagnosticPrinter DiagnosticPrinter;
-  FileManager Files;
-  SourceManager Sources;
-  LangOptions Options;
-  Rewriter Rewrite;
-};
-
-class ReplacementTest : public ::testing::Test {
- protected:
   RewriterTestContext Context;
 };
 
 TEST_F(ReplacementTest, CanDeleteAllText) {
   FileID ID = Context.createInMemoryFile("input.cpp", "text");
   SourceLocation Location = Context.getLocation(ID, 1, 1);
-  Replacement Replace(Context.createReplacement(Location, 4, ""));
+  Replacement Replace(createReplacement(Location, 4, ""));
   EXPECT_TRUE(Replace.apply(Context.Rewrite));
   EXPECT_EQ("", Context.getRewrittenText(ID));
 }
@@ -95,7 +52,7 @@
 TEST_F(ReplacementTest, CanDeleteAllTextInTextWithNewlines) {
   FileID ID = Context.createInMemoryFile("input.cpp", "line1\nline2\nline3");
   SourceLocation Location = Context.getLocation(ID, 1, 1);
-  Replacement Replace(Context.createReplacement(Location, 17, ""));
+  Replacement Replace(createReplacement(Location, 17, ""));
   EXPECT_TRUE(Replace.apply(Context.Rewrite));
   EXPECT_EQ("", Context.getRewrittenText(ID));
 }
@@ -103,7 +60,7 @@
 TEST_F(ReplacementTest, CanAddText) {
   FileID ID = Context.createInMemoryFile("input.cpp", "");
   SourceLocation Location = Context.getLocation(ID, 1, 1);
-  Replacement Replace(Context.createReplacement(Location, 0, "result"));
+  Replacement Replace(createReplacement(Location, 0, "result"));
   EXPECT_TRUE(Replace.apply(Context.Rewrite));
   EXPECT_EQ("result", Context.getRewrittenText(ID));
 }
@@ -112,7 +69,7 @@
   FileID ID = Context.createInMemoryFile("input.cpp",
                                          "line1\nline2\nline3\nline4");
   SourceLocation Location = Context.getLocation(ID, 2, 3);
-  Replacement Replace(Context.createReplacement(Location, 12, "x"));
+  Replacement Replace(createReplacement(Location, 12, "x"));
   EXPECT_TRUE(Replace.apply(Context.Rewrite));
   EXPECT_EQ("line1\nlixne4", Context.getRewrittenText(ID));
 }
@@ -121,14 +78,14 @@
   FileID ID = Context.createInMemoryFile("input.cpp",
                                          "line1\nline2\nline3\nline4");
   SourceLocation Location1 = Context.getLocation(ID, 2, 3);
-  Replacement Replace1(Context.createReplacement(Location1, 12, "x\ny\n"));
+  Replacement Replace1(createReplacement(Location1, 12, "x\ny\n"));
   EXPECT_TRUE(Replace1.apply(Context.Rewrite));
   EXPECT_EQ("line1\nlix\ny\nne4", Context.getRewrittenText(ID));
 
   // Since the original source has not been modified, the (4, 4) points to the
   // 'e' in the original content.
   SourceLocation Location2 = Context.getLocation(ID, 4, 4);
-  Replacement Replace2(Context.createReplacement(Location2, 1, "f"));
+  Replacement Replace2(createReplacement(Location2, 1, "f"));
   EXPECT_TRUE(Replace2.apply(Context.Rewrite));
   EXPECT_EQ("line1\nlix\ny\nnf4", Context.getRewrittenText(ID));
 }





More information about the llvm-branch-commits mailing list