]> granicus.if.org Git - clang/commitdiff
[clang-format] revert an unintended change in r288493 and add a test case.
authorEric Liu <ioeric@google.com>
Mon, 19 Dec 2016 10:41:05 +0000 (10:41 +0000)
committerEric Liu <ioeric@google.com>
Mon, 19 Dec 2016 10:41:05 +0000 (10:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/CleanupTest.cpp

index bd19b48db3f2b525871230234dc21c1efe6c2f03..ffe41c224ae266755195b9ef4ca4f0ced7d58920 100644 (file)
@@ -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;
index dbf3f0704768d77bca33e1337ecb2b7237359c0a..6ac5f695d437fa8d6d69c2833d97ae0488fc21c2 100644 (file)
@@ -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 <vector>\n"
+                         "#ifndef X\n"
+                         "#define 1\n";
+  tooling::Replacements Replaces =
+      toReplacements({createInsertion("#include <vector>")});
+  EXPECT_EQ(Expected, apply(Code, Replaces));
+}
+
 TEST_F(CleanUpReplacementsTest, HeaderGuardWithComment) {
   std::string Code = "// comment \n"
                      "#ifndef X // comment\n"