<div dir="ltr"><div dir="ltr" class="gmail_msg">Hi Mehdi,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This is an unintended change. I've reverted this line and added a test case for this in r290093.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thanks,</div><div class="gmail_msg">Eric</div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Fri, Dec 16, 2016 at 7:02 PM Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="gmail_msg" target="_blank">mehdi.amini@apple.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Eric,<br class="gmail_msg">
<br class="gmail_msg">
> On Dec 2, 2016, at 3:01 AM, Eric Liu via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="gmail_msg" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> Author: ioeric<br class="gmail_msg">
> Date: Fri Dec 2 05:01:43 2016<br class="gmail_msg">
> New Revision: 288493<br class="gmail_msg">
><br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=288493&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=288493&view=rev</a><br class="gmail_msg">
> Log:<br class="gmail_msg">
> [ClangFormat] Only insert #include into the #include block in the beginning of the file.<br class="gmail_msg">
><br class="gmail_msg">
> Summary:<br class="gmail_msg">
> This avoid inserting #include into:<br class="gmail_msg">
> - raw string literals containing #include.<br class="gmail_msg">
> - #if block.<br class="gmail_msg">
> - Special #include among declarations (e.g. functions).<br class="gmail_msg">
><br class="gmail_msg">
> Reviewers: djasper<br class="gmail_msg">
><br class="gmail_msg">
> Subscribers: cfe-commits, klimek<br class="gmail_msg">
><br class="gmail_msg">
> Differential Revision: <a href="https://reviews.llvm.org/D26909" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D26909</a><br class="gmail_msg">
><br class="gmail_msg">
> Modified:<br class="gmail_msg">
> cfe/trunk/include/clang/Format/Format.h<br class="gmail_msg">
> cfe/trunk/lib/Format/Format.cpp<br class="gmail_msg">
> cfe/trunk/unittests/Format/CleanupTest.cpp<br class="gmail_msg">
><br class="gmail_msg">
> Modified: cfe/trunk/include/clang/Format/Format.h<br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=288493&r1=288492&r2=288493&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=288493&r1=288492&r2=288493&view=diff</a><br class="gmail_msg">
> ==============================================================================<br class="gmail_msg">
> --- cfe/trunk/include/clang/Format/Format.h (original)<br class="gmail_msg">
> +++ cfe/trunk/include/clang/Format/Format.h Fri Dec 2 05:01:43 2016<br class="gmail_msg">
> @@ -786,7 +786,14 @@ formatReplacements(StringRef Code, const<br class="gmail_msg">
> /// This also supports inserting/deleting C++ #include directives:<br class="gmail_msg">
> /// - If a replacement has offset UINT_MAX, length 0, and a replacement text<br class="gmail_msg">
> /// that is an #include directive, this will insert the #include into the<br class="gmail_msg">
> -/// correct block in the \p Code.<br class="gmail_msg">
> +/// correct block in the \p Code. When searching for points to insert new<br class="gmail_msg">
> +/// header, this ignores #include's after the #include block(s) in the<br class="gmail_msg">
> +/// beginning of a file to avoid inserting headers into code sections where<br class="gmail_msg">
> +/// new #include's should not be added by default. These code sections<br class="gmail_msg">
> +/// include:<br class="gmail_msg">
> +/// - raw string literals (containing #include).<br class="gmail_msg">
> +/// - #if blocks.<br class="gmail_msg">
> +/// - Special #include's among declarations (e.g. functions).<br class="gmail_msg">
> /// - If a replacement has offset UINT_MAX, length 1, and a replacement text<br class="gmail_msg">
> /// that is the name of the header to be removed, the header will be removed<br class="gmail_msg">
> /// from \p Code if it exists.<br class="gmail_msg">
><br class="gmail_msg">
> Modified: cfe/trunk/lib/Format/Format.cpp<br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=288493&r1=288492&r2=288493&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=288493&r1=288492&r2=288493&view=diff</a><br class="gmail_msg">
> ==============================================================================<br class="gmail_msg">
> --- cfe/trunk/lib/Format/Format.cpp (original)<br class="gmail_msg">
> +++ cfe/trunk/lib/Format/Format.cpp Fri Dec 2 05:01:43 2016<br class="gmail_msg">
> @@ -1514,10 +1514,23 @@ inline bool isHeaderDeletion(const tooli<br class="gmail_msg">
> return Replace.getOffset() == UINT_MAX && Replace.getLength() == 1;<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> -void skipComments(Lexer &Lex, Token &Tok) {<br class="gmail_msg">
> - while (Tok.is(tok::comment))<br class="gmail_msg">
> - if (Lex.LexFromRawLexer(Tok))<br class="gmail_msg">
> - return;<br class="gmail_msg">
> +// Returns the offset after skipping a sequence of tokens, matched by \p<br class="gmail_msg">
> +// GetOffsetAfterSequence, from the start of the code.<br class="gmail_msg">
> +// \p GetOffsetAfterSequence should be a function that matches a sequence of<br class="gmail_msg">
> +// tokens and returns an offset after the sequence.<br class="gmail_msg">
> +unsigned getOffsetAfterTokenSequence(<br class="gmail_msg">
> + StringRef FileName, StringRef Code, const FormatStyle &Style,<br class="gmail_msg">
> + std::function<unsigned(const SourceManager &, Lexer &, Token &)><br class="gmail_msg">
> + GetOffsetAfterSequense) {<br class="gmail_msg">
> + std::unique_ptr<Environment> Env =<br class="gmail_msg">
> + Environment::CreateVirtualEnvironment(Code, FileName, /*Ranges=*/{});<br class="gmail_msg">
> + const SourceManager &SourceMgr = Env->getSourceManager();<br class="gmail_msg">
> + Lexer Lex(Env->getFileID(), SourceMgr.getBuffer(Env->getFileID()), SourceMgr,<br class="gmail_msg">
> + getFormattingLangOpts(Style));<br class="gmail_msg">
> + Token Tok;<br class="gmail_msg">
> + // Get the first token.<br class="gmail_msg">
> + Lex.LexFromRawLexer(Tok);<br class="gmail_msg">
> + return GetOffsetAfterSequense(SourceMgr, Lex, Tok);<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> // Check if a sequence of tokens is like "#<Name> <raw_identifier>". If it is,<br class="gmail_msg">
> @@ -1527,31 +1540,88 @@ bool checkAndConsumeDirectiveWithName(Le<br class="gmail_msg">
> bool Matched = Tok.is(tok::hash) && !Lex.LexFromRawLexer(Tok) &&<br class="gmail_msg">
> Tok.is(tok::raw_identifier) &&<br class="gmail_msg">
> Tok.getRawIdentifier() == Name && !Lex.LexFromRawLexer(Tok) &&<br class="gmail_msg">
> - Tok.is(tok::raw_identifier);<br class="gmail_msg">
> + tok::raw_identifier;<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Can you elaborate on this line change? I don’t get it. (It was flagged by coverity).<br class="gmail_msg">
<br class="gmail_msg">
Thanks,<br class="gmail_msg">
<br class="gmail_msg">
—<br class="gmail_msg">
Mehdi<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
> if (Matched)<br class="gmail_msg">
> Lex.LexFromRawLexer(Tok);<br class="gmail_msg">
> return Matched;<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> +void skipComments(Lexer &Lex, Token &Tok) {<br class="gmail_msg">
> + while (Tok.is(tok::comment))<br class="gmail_msg">
> + if (Lex.LexFromRawLexer(Tok))<br class="gmail_msg">
> + return;<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +// Returns the offset after header guard directives and any comments<br class="gmail_msg">
> +// before/after header guards. If no header guard presents in the code, this<br class="gmail_msg">
> +// will returns the offset after skipping all comments from the start of the<br class="gmail_msg">
> +// code.<br class="gmail_msg">
> unsigned getOffsetAfterHeaderGuardsAndComments(StringRef FileName,<br class="gmail_msg">
> StringRef Code,<br class="gmail_msg">
> const FormatStyle &Style) {<br class="gmail_msg">
> - std::unique_ptr<Environment> Env =<br class="gmail_msg">
> - Environment::CreateVirtualEnvironment(Code, FileName, /*Ranges=*/{});<br class="gmail_msg">
> - const SourceManager &SourceMgr = Env->getSourceManager();<br class="gmail_msg">
> - Lexer Lex(Env->getFileID(), SourceMgr.getBuffer(Env->getFileID()), SourceMgr,<br class="gmail_msg">
> - getFormattingLangOpts(Style));<br class="gmail_msg">
> - Token Tok;<br class="gmail_msg">
> - // Get the first token.<br class="gmail_msg">
> - Lex.LexFromRawLexer(Tok);<br class="gmail_msg">
> - skipComments(Lex, Tok);<br class="gmail_msg">
> - unsigned AfterComments = SourceMgr.getFileOffset(Tok.getLocation());<br class="gmail_msg">
> - if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) {<br class="gmail_msg">
> - skipComments(Lex, Tok);<br class="gmail_msg">
> - if (checkAndConsumeDirectiveWithName(Lex, "define", Tok))<br class="gmail_msg">
> - return SourceMgr.getFileOffset(Tok.getLocation());<br class="gmail_msg">
> + return getOffsetAfterTokenSequence(<br class="gmail_msg">
> + FileName, Code, Style,<br class="gmail_msg">
> + [](const SourceManager &SM, Lexer &Lex, Token Tok) {<br class="gmail_msg">
> + skipComments(Lex, Tok);<br class="gmail_msg">
> + unsigned InitialOffset = SM.getFileOffset(Tok.getLocation());<br class="gmail_msg">
> + if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) {<br class="gmail_msg">
> + skipComments(Lex, Tok);<br class="gmail_msg">
> + if (checkAndConsumeDirectiveWithName(Lex, "define", Tok))<br class="gmail_msg">
> + return SM.getFileOffset(Tok.getLocation());<br class="gmail_msg">
> + }<br class="gmail_msg">
> + return InitialOffset;<br class="gmail_msg">
> + });<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +// Check if a sequence of tokens is like<br class="gmail_msg">
> +// "#include ("header.h" | <header.h>)".<br class="gmail_msg">
> +// If it is, \p Tok will be the token after this directive; otherwise, it can be<br class="gmail_msg">
> +// any token after the given \p Tok (including \p Tok).<br class="gmail_msg">
> +bool checkAndConsumeInclusiveDirective(Lexer &Lex, Token &Tok) {<br class="gmail_msg">
> + auto Matched = [&]() {<br class="gmail_msg">
> + Lex.LexFromRawLexer(Tok);<br class="gmail_msg">
> + return true;<br class="gmail_msg">
> + };<br class="gmail_msg">
> + if (Tok.is(tok::hash) && !Lex.LexFromRawLexer(Tok) &&<br class="gmail_msg">
> + Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "include") {<br class="gmail_msg">
> + if (Lex.LexFromRawLexer(Tok))<br class="gmail_msg">
> + return false;<br class="gmail_msg">
> + if (Tok.is(tok::string_literal))<br class="gmail_msg">
> + return Matched();<br class="gmail_msg">
> + if (Tok.is(tok::less)) {<br class="gmail_msg">
> + while (!Lex.LexFromRawLexer(Tok) && Tok.isNot(tok::greater)) {<br class="gmail_msg">
> + }<br class="gmail_msg">
> + if (Tok.is(tok::greater))<br class="gmail_msg">
> + return Matched();<br class="gmail_msg">
> + }<br class="gmail_msg">
> }<br class="gmail_msg">
> - return AfterComments;<br class="gmail_msg">
> + return false;<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +// Returns the offset of the last #include directive after which a new<br class="gmail_msg">
> +// #include can be inserted. This ignores #include's after the #include block(s)<br class="gmail_msg">
> +// in the beginning of a file to avoid inserting headers into code sections<br class="gmail_msg">
> +// where new #include's should not be added by default.<br class="gmail_msg">
> +// These code sections include:<br class="gmail_msg">
> +// - raw string literals (containing #include).<br class="gmail_msg">
> +// - #if blocks.<br class="gmail_msg">
> +// - Special #include's among declarations (e.g. functions).<br class="gmail_msg">
> +//<br class="gmail_msg">
> +// If no #include after which a new #include can be inserted, this returns the<br class="gmail_msg">
> +// offset after skipping all comments from the start of the code.<br class="gmail_msg">
> +// Inserting after an #include is not allowed if it comes after code that is not<br class="gmail_msg">
> +// #include (e.g. pre-processing directive that is not #include, declarations).<br class="gmail_msg">
> +unsigned getMaxHeaderInsertionOffset(StringRef FileName, StringRef Code,<br class="gmail_msg">
> + const FormatStyle &Style) {<br class="gmail_msg">
> + return getOffsetAfterTokenSequence(<br class="gmail_msg">
> + FileName, Code, Style,<br class="gmail_msg">
> + [](const SourceManager &SM, Lexer &Lex, Token Tok) {<br class="gmail_msg">
> + skipComments(Lex, Tok);<br class="gmail_msg">
> + unsigned MaxOffset = SM.getFileOffset(Tok.getLocation());<br class="gmail_msg">
> + while (checkAndConsumeInclusiveDirective(Lex, Tok))<br class="gmail_msg">
> + MaxOffset = SM.getFileOffset(Tok.getLocation());<br class="gmail_msg">
> + return MaxOffset;<br class="gmail_msg">
> + });<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> bool isDeletedHeader(llvm::StringRef HeaderName,<br class="gmail_msg">
> @@ -1560,11 +1630,6 @@ bool isDeletedHeader(llvm::StringRef Hea<br class="gmail_msg">
> HeadersToDelete.count(HeaderName.trim("\"<>"));<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> -// FIXME: we also need to insert a '\n' at the end of the code if we have an<br class="gmail_msg">
> -// insertion with offset Code.size(), and there is no '\n' at the end of the<br class="gmail_msg">
> -// code.<br class="gmail_msg">
> -// FIXME: do not insert headers into conditional #include blocks, e.g. #includes<br class="gmail_msg">
> -// surrounded by compile condition "#if...".<br class="gmail_msg">
> // FIXME: insert empty lines between newly created blocks.<br class="gmail_msg">
> tooling::Replacements<br class="gmail_msg">
> fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,<br class="gmail_msg">
> @@ -1612,6 +1677,8 @@ fixCppIncludeInsertions(StringRef Code,<br class="gmail_msg">
> unsigned MinInsertOffset =<br class="gmail_msg">
> getOffsetAfterHeaderGuardsAndComments(FileName, Code, Style);<br class="gmail_msg">
> StringRef TrimmedCode = Code.drop_front(MinInsertOffset);<br class="gmail_msg">
> + unsigned MaxInsertOffset =<br class="gmail_msg">
> + getMaxHeaderInsertionOffset(FileName, TrimmedCode, Style);<br class="gmail_msg">
> SmallVector<StringRef, 32> Lines;<br class="gmail_msg">
> TrimmedCode.split(Lines, '\n');<br class="gmail_msg">
> unsigned Offset = MinInsertOffset;<br class="gmail_msg">
> @@ -1623,11 +1690,14 @@ fixCppIncludeInsertions(StringRef Code,<br class="gmail_msg">
> // The header name with quotes or angle brackets.<br class="gmail_msg">
> StringRef IncludeName = Matches[2];<br class="gmail_msg">
> ExistingIncludes.insert(IncludeName);<br class="gmail_msg">
> - int Category = Categories.getIncludePriority(<br class="gmail_msg">
> - IncludeName, /*CheckMainHeader=*/FirstIncludeOffset < 0);<br class="gmail_msg">
> - CategoryEndOffsets[Category] = NextLineOffset;<br class="gmail_msg">
> - if (FirstIncludeOffset < 0)<br class="gmail_msg">
> - FirstIncludeOffset = Offset;<br class="gmail_msg">
> + // Only record the offset of current #include if we can insert after it.<br class="gmail_msg">
> + if (Offset <= MaxInsertOffset) {<br class="gmail_msg">
> + int Category = Categories.getIncludePriority(<br class="gmail_msg">
> + IncludeName, /*CheckMainHeader=*/FirstIncludeOffset < 0);<br class="gmail_msg">
> + CategoryEndOffsets[Category] = NextLineOffset;<br class="gmail_msg">
> + if (FirstIncludeOffset < 0)<br class="gmail_msg">
> + FirstIncludeOffset = Offset;<br class="gmail_msg">
> + }<br class="gmail_msg">
> if (isDeletedHeader(IncludeName, HeadersToDelete)) {<br class="gmail_msg">
> // If this is the last line without trailing newline, we need to make<br class="gmail_msg">
> // sure we don't delete across the file boundary.<br class="gmail_msg">
><br class="gmail_msg">
> Modified: cfe/trunk/unittests/Format/CleanupTest.cpp<br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CleanupTest.cpp?rev=288493&r1=288492&r2=288493&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CleanupTest.cpp?rev=288493&r1=288492&r2=288493&view=diff</a><br class="gmail_msg">
> ==============================================================================<br class="gmail_msg">
> --- cfe/trunk/unittests/Format/CleanupTest.cpp (original)<br class="gmail_msg">
> +++ cfe/trunk/unittests/Format/CleanupTest.cpp Fri Dec 2 05:01:43 2016<br class="gmail_msg">
> @@ -839,6 +839,93 @@ TEST_F(CleanUpReplacementsTest, Insertio<br class="gmail_msg">
> EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> +TEST_F(CleanUpReplacementsTest, NoInsertionAfterCode) {<br class="gmail_msg">
> + std::string Code = "#include \"a.h\"\n"<br class="gmail_msg">
> + "void f() {}\n"<br class="gmail_msg">
> + "#include \"b.h\"\n";<br class="gmail_msg">
> + std::string Expected = "#include \"a.h\"\n"<br class="gmail_msg">
> + "#include \"c.h\"\n"<br class="gmail_msg">
> + "void f() {}\n"<br class="gmail_msg">
> + "#include \"b.h\"\n";<br class="gmail_msg">
> + tooling::Replacements Replaces = toReplacements(<br class="gmail_msg">
> + {createInsertion("#include \"c.h\"")});<br class="gmail_msg">
> + EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +TEST_F(CleanUpReplacementsTest, NoInsertionInStringLiteral) {<br class="gmail_msg">
> + std::string Code = "#include \"a.h\"\n"<br class="gmail_msg">
> + "const char[] = R\"(\n"<br class="gmail_msg">
> + "#include \"b.h\"\n"<br class="gmail_msg">
> + ")\";\n";<br class="gmail_msg">
> + std::string Expected = "#include \"a.h\"\n"<br class="gmail_msg">
> + "#include \"c.h\"\n"<br class="gmail_msg">
> + "const char[] = R\"(\n"<br class="gmail_msg">
> + "#include \"b.h\"\n"<br class="gmail_msg">
> + ")\";\n";<br class="gmail_msg">
> + tooling::Replacements Replaces =<br class="gmail_msg">
> + toReplacements({createInsertion("#include \"c.h\"")});<br class="gmail_msg">
> + EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +TEST_F(CleanUpReplacementsTest, NoInsertionAfterOtherDirective) {<br class="gmail_msg">
> + std::string Code = "#include \"a.h\"\n"<br class="gmail_msg">
> + "#ifdef X\n"<br class="gmail_msg">
> + "#include \"b.h\"\n"<br class="gmail_msg">
> + "#endif\n";<br class="gmail_msg">
> + std::string Expected = "#include \"a.h\"\n"<br class="gmail_msg">
> + "#include \"c.h\"\n"<br class="gmail_msg">
> + "#ifdef X\n"<br class="gmail_msg">
> + "#include \"b.h\"\n"<br class="gmail_msg">
> + "#endif\n";<br class="gmail_msg">
> + tooling::Replacements Replaces = toReplacements(<br class="gmail_msg">
> + {createInsertion("#include \"c.h\"")});<br class="gmail_msg">
> + EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +TEST_F(CleanUpReplacementsTest, CanInsertAfterLongSystemInclude) {<br class="gmail_msg">
> + std::string Code = "#include \"a.h\"\n"<br class="gmail_msg">
> + "// comment\n\n"<br class="gmail_msg">
> + "#include <a/b/c/d/e.h>\n";<br class="gmail_msg">
> + std::string Expected = "#include \"a.h\"\n"<br class="gmail_msg">
> + "// comment\n\n"<br class="gmail_msg">
> + "#include <a/b/c/d/e.h>\n"<br class="gmail_msg">
> + "#include <x.h>\n";<br class="gmail_msg">
> + tooling::Replacements Replaces =<br class="gmail_msg">
> + toReplacements({createInsertion("#include <x.h>")});<br class="gmail_msg">
> + EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +TEST_F(CleanUpReplacementsTest, CanInsertAfterComment) {<br class="gmail_msg">
> + std::string Code = "#include \"a.h\"\n"<br class="gmail_msg">
> + "// Comment\n"<br class="gmail_msg">
> + "\n"<br class="gmail_msg">
> + "/* Comment */\n"<br class="gmail_msg">
> + "// Comment\n"<br class="gmail_msg">
> + "\n"<br class="gmail_msg">
> + "#include \"b.h\"\n";<br class="gmail_msg">
> + std::string Expected = "#include \"a.h\"\n"<br class="gmail_msg">
> + "// Comment\n"<br class="gmail_msg">
> + "\n"<br class="gmail_msg">
> + "/* Comment */\n"<br class="gmail_msg">
> + "// Comment\n"<br class="gmail_msg">
> + "\n"<br class="gmail_msg">
> + "#include \"b.h\"\n"<br class="gmail_msg">
> + "#include \"c.h\"\n";<br class="gmail_msg">
> + tooling::Replacements Replaces =<br class="gmail_msg">
> + toReplacements({createInsertion("#include \"c.h\"")});<br class="gmail_msg">
> + EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +TEST_F(CleanUpReplacementsTest, CanDeleteAfterCode) {<br class="gmail_msg">
> + std::string Code = "#include \"a.h\"\n"<br class="gmail_msg">
> + "void f() {}\n"<br class="gmail_msg">
> + "#include \"b.h\"\n";<br class="gmail_msg">
> + std::string Expected = "#include \"a.h\"\n"<br class="gmail_msg">
> + "void f() {}\n";<br class="gmail_msg">
> + tooling::Replacements Replaces = toReplacements({createDeletion("\"b.h\"")});<br class="gmail_msg">
> + EXPECT_EQ(Expected, apply(Code, Replaces));<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> } // end namespace<br class="gmail_msg">
> } // end namespace format<br class="gmail_msg">
> } // end namespace clang<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> cfe-commits mailing list<br class="gmail_msg">
> <a href="mailto:cfe-commits@lists.llvm.org" class="gmail_msg" target="_blank">cfe-commits@lists.llvm.org</a><br class="gmail_msg">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>