From 93459d3142e78bec125075c6b455b734fb7dfc5a 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. llvm-svn: 290093 --- clang/lib/Format/Format.cpp | 2 +- clang/unittests/Format/CleanupTest.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index bd19b48..ffe41c2 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/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/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index dbf3f07..6ac5f69 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/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.7.4