summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-06-16 10:22:10 +0000
committerDaniel Jasper <djasper@google.com>2015-06-16 10:22:10 +0000
commit0f291276361f863ed2898e1eecbbf3da94e2dfe8 (patch)
tree681ac9ffc9a71f516e55a848d1dece8807fd71f6 /clang/unittests/Tooling
parentc535d93b47c79add08a84917e3dcad1daf0323dd (diff)
downloadbcm5719-llvm-0f291276361f863ed2898e1eecbbf3da94e2dfe8.tar.gz
bcm5719-llvm-0f291276361f863ed2898e1eecbbf3da94e2dfe8.zip
Tooling: When applying a set of replacements, do deletions before
insertions. It is unlikely to be the intention to delete parts of newly inserted code. To do so, changed sorting Replacements at the same offset to have decreasing length. llvm-svn: 239809
Diffstat (limited to 'clang/unittests/Tooling')
-rw-r--r--clang/unittests/Tooling/RewriterTest.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/RewriterTest.cpp b/clang/unittests/Tooling/RewriterTest.cpp
index c53e50a87d7..4928b17cfa2 100644
--- a/clang/unittests/Tooling/RewriterTest.cpp
+++ b/clang/unittests/Tooling/RewriterTest.cpp
@@ -8,9 +8,12 @@
//===----------------------------------------------------------------------===//
#include "RewriterTestContext.h"
+#include "clang/Tooling/Core/Replacement.h"
#include "gtest/gtest.h"
namespace clang {
+namespace tooling {
+namespace {
TEST(Rewriter, OverwritesChangedFiles) {
RewriterTestContext Context;
@@ -34,4 +37,14 @@ TEST(Rewriter, ContinuesOverwritingFilesOnError) {
Context.getFileContentFromDisk("working.cpp"));
}
+TEST(Rewriter, AdjacentInsertAndDelete) {
+ Replacements Replaces;
+ Replaces.emplace("<file>", 6, 6, "");
+ Replaces.emplace("<file>", 6, 0, "replaced\n");
+ EXPECT_EQ("line1\nreplaced\nline3\nline4",
+ applyAllReplacements("line1\nline2\nline3\nline4", Replaces));
+}
+
+} // end namespace
+} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud