summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 0a9969a9b70..0f785705d9e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11526,6 +11526,35 @@ TEST_F(ReplacementTest, FormatCodeAfterReplacements) {
Code, formatReplacements(Code, Replaces, Style)));
}
+TEST_F(ReplacementTest, FixOnlyAffectedCodeAfterReplacements) {
+ std::string Code = "namespace A {\n"
+ "namespace B {\n"
+ " int x;\n"
+ "} // namespace B\n"
+ "} // namespace A\n"
+ "\n"
+ "namespace C {\n"
+ "namespace D { int i; }\n"
+ "inline namespace E { namespace { int y; } }\n"
+ "int x= 0;"
+ "}";
+ std::string Expected = "\n\nnamespace C {\n"
+ "namespace D { int i; }\n\n"
+ "int x= 0;"
+ "}";
+ FileID ID = Context.createInMemoryFile("fix.cpp", Code);
+ tooling::Replacements Replaces;
+ Replaces.insert(tooling::Replacement(
+ Context.Sources, Context.getLocation(ID, 3, 3), 6, ""));
+ Replaces.insert(tooling::Replacement(
+ Context.Sources, Context.getLocation(ID, 9, 34), 6, ""));
+
+ format::FormatStyle Style = format::getLLVMStyle();
+ auto FinalReplaces = formatReplacements(
+ Code, cleanupAroundReplacements(Code, Replaces, Style), Style);
+ EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
OpenPOWER on IntegriCloud