From 3753f912bf2218ab02afae404ca7d39cebe94811 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Tue, 14 Jun 2016 14:09:21 +0000 Subject: [clang-format] do not add existing includes. Summary: do not add existing includes. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21323 llvm-svn: 272669 --- clang/unittests/Format/CleanupTest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'clang/unittests/Format/CleanupTest.cpp') diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index 9037304a723..f51e3acf9ac 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -688,6 +688,29 @@ TEST_F(CleanUpReplacementsTest, NoNewLineAtTheEndOfCode) { EXPECT_EQ(Expected, apply(Code, Replaces)); } +TEST_F(CleanUpReplacementsTest, SkipExistingHeaders) { + std::string Code = "#include \"a.h\"\n" + "#include \n"; + std::string Expected = "#include \"a.h\"\n" + "#include \n"; + tooling::Replacements Replaces = {createInsertion("#include "), + createInsertion("#include \"a.h\"")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + +TEST_F(CleanUpReplacementsTest, AddIncludesWithDifferentForms) { + std::string Code = "#include \"a.h\"\n" + "#include \n"; + // FIXME: this might not be the best behavior. + std::string Expected = "#include \"a.h\"\n" + "#include \"vector\"\n" + "#include \n" + "#include \n"; + tooling::Replacements Replaces = {createInsertion("#include \"vector\""), + createInsertion("#include ")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + } // end namespace } // end namespace format } // end namespace clang -- cgit v1.2.3