From 50dd7b04c578e43ddc951a329b647d30b9ccd115 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 19 Dec 2016 10:41:05 +0000 Subject: [PATCH] [clang-format] revert an unintended change in r288493 and add a test case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290093 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 2 +- unittests/Format/CleanupTest.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index bd19b48db3..ffe41c224a 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1545,7 +1545,7 @@ bool checkAndConsumeDirectiveWithName(Lexer &Lex, StringRef Name, Token &Tok) { bool Matched = Tok.is(tok::hash) && !Lex.LexFromRawLexer(Tok) && Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == Name && !Lex.LexFromRawLexer(Tok) && - tok::raw_identifier; + Tok.is(tok::raw_identifier); if (Matched) Lex.LexFromRawLexer(Tok); return Matched; diff --git a/unittests/Format/CleanupTest.cpp b/unittests/Format/CleanupTest.cpp index dbf3f07047..6ac5f695d4 100644 --- a/unittests/Format/CleanupTest.cpp +++ b/unittests/Format/CleanupTest.cpp @@ -714,6 +714,19 @@ TEST_F(CleanUpReplacementsTest, IfNDefWithNoDefine) { EXPECT_EQ(Expected, apply(Code, Replaces)); } +TEST_F(CleanUpReplacementsTest, FakeHeaderGuard) { + std::string Code = "// comment \n" + "#ifndef X\n" + "#define 1\n"; + std::string Expected = "// comment \n" + "#include \n" + "#ifndef X\n" + "#define 1\n"; + tooling::Replacements Replaces = + toReplacements({createInsertion("#include ")}); + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + TEST_F(CleanUpReplacementsTest, HeaderGuardWithComment) { std::string Code = "// comment \n" "#ifndef X // comment\n" -- 2.40.0