r297289 - Add missing implementation for AtomicChange::replace(...)
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 8 07:53:10 PST 2017
Author: ioeric
Date: Wed Mar 8 09:53:10 2017
New Revision: 297289
URL: http://llvm.org/viewvc/llvm-project?rev=297289&view=rev
Log:
Add missing implementation for AtomicChange::replace(...)
Summary: Just realized the implementation is missing...
Reviewers: klimek
Reviewed By: klimek
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D30735
Modified:
cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp
cfe/trunk/unittests/Tooling/RefactoringTest.cpp
Modified: cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp?rev=297289&r1=297288&r2=297289&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/AtomicChange.cpp Wed Mar 8 09:53:10 2017
@@ -132,6 +132,11 @@ AtomicChange AtomicChange::convertFromYA
return E;
}
+llvm::Error AtomicChange::replace(const SourceManager &SM, SourceLocation Loc,
+ unsigned Length, llvm::StringRef Text) {
+ return Replaces.add(Replacement(SM, Loc, Length, Text));
+}
+
llvm::Error AtomicChange::insert(const SourceManager &SM, SourceLocation Loc,
llvm::StringRef Text, bool InsertAfter) {
if (Text.empty())
Modified: cfe/trunk/unittests/Tooling/RefactoringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringTest.cpp?rev=297289&r1=297288&r2=297289&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RefactoringTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringTest.cpp Wed Mar 8 09:53:10 2017
@@ -1173,8 +1173,10 @@ TEST_F(AtomicChangeTest, YAMLToAtomicCha
EXPECT_EQ(ExpectedChange.getKey(), ActualChange.getKey());
EXPECT_EQ(ExpectedChange.getFilePath(), ActualChange.getFilePath());
EXPECT_EQ(ExpectedChange.getError(), ActualChange.getError());
- EXPECT_EQ(ExpectedChange.getInsertedHeaders(), ActualChange.getInsertedHeaders());
- EXPECT_EQ(ExpectedChange.getRemovedHeaders(), ActualChange.getRemovedHeaders());
+ EXPECT_EQ(ExpectedChange.getInsertedHeaders(),
+ ActualChange.getInsertedHeaders());
+ EXPECT_EQ(ExpectedChange.getRemovedHeaders(),
+ ActualChange.getRemovedHeaders());
EXPECT_EQ(ExpectedChange.getReplacements().size(),
ActualChange.getReplacements().size());
EXPECT_EQ(2u, ActualChange.getReplacements().size());
@@ -1191,6 +1193,22 @@ TEST_F(AtomicChangeTest, CheckKeyAndKeyF
EXPECT_EQ("input.cpp", Change.getFilePath());
}
+TEST_F(AtomicChangeTest, Replace) {
+ setUp();
+ AtomicChange Change(Context.Sources, DefaultLoc);
+ llvm::Error Err = Change.replace(Context.Sources, DefaultLoc, 2, "aa");
+ ASSERT_TRUE(!Err);
+ EXPECT_EQ(Change.getReplacements().size(), 1u);
+ EXPECT_EQ(*Change.getReplacements().begin(),
+ Replacement(Context.Sources, DefaultLoc, 2, "aa"));
+
+ // Add a new replacement that conflicts with the existing one.
+ Err = Change.replace(Context.Sources, DefaultLoc, 3, "ab");
+ EXPECT_TRUE((bool)Err);
+ llvm::consumeError(std::move(Err));
+ EXPECT_EQ(Change.getReplacements().size(), 1u);
+}
+
TEST_F(AtomicChangeTest, InsertBefore) {
setUp();
AtomicChange Change(Context.Sources, DefaultLoc);
More information about the cfe-commits
mailing list