summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-05-18 13:43:48 +0000
committerEric Liu <ioeric@google.com>2016-05-18 13:43:48 +0000
commitbaf58c2309010f8796daff461ff7045f9a0b1c21 (patch)
tree08e3d99ec19ab9f4a82e88ba7c47fd9cf1f21d53 /clang/unittests/Format/FormatTest.cpp
parent6b5160a369a10f5fa521391c633b0736408936cd (diff)
downloadbcm5719-llvm-baf58c2309010f8796daff461ff7045f9a0b1c21.tar.gz
bcm5719-llvm-baf58c2309010f8796daff461ff7045f9a0b1c21.zip
[clang-format] Make formatReplacements() also sort #includes.
Summary: [clang-format] Make formatReplacements() also sort #includes. Reviewers: bkramer, djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20362 llvm-svn: 269924
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 3c72a13bf10..1b434eb8c94 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11559,6 +11559,31 @@ TEST_F(ReplacementTest, FixOnlyAffectedCodeAfterReplacements) {
EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
}
+TEST_F(ReplacementTest, SortIncludesAfterReplacement) {
+ std::string Code = "#include \"a.h\"\n"
+ "#include \"c.h\"\n"
+ "\n"
+ "int main() {\n"
+ " return 0;\n"
+ "}";
+ std::string Expected = "#include \"a.h\"\n"
+ "#include \"b.h\"\n"
+ "#include \"c.h\"\n"
+ "\n"
+ "int main() {\n"
+ " return 0;\n"
+ "}";
+ FileID ID = Context.createInMemoryFile("fix.cpp", Code);
+ tooling::Replacements Replaces;
+ Replaces.insert(tooling::Replacement(
+ Context.Sources, Context.getLocation(ID, 1, 1), 0, "#include \"b.h\"\n"));
+
+ format::FormatStyle Style = format::getLLVMStyle();
+ Style.SortIncludes = true;
+ auto FinalReplaces = formatReplacements(Code, Replaces, Style);
+ EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
OpenPOWER on IntegriCloud