diff options
author | Eric Liu <ioeric@google.com> | 2016-06-06 11:00:13 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2016-06-06 11:00:13 +0000 |
commit | 3528832930542732d9defefb97e242f03fb5bd5c (patch) | |
tree | 167d83930b39d46f5646b8e84fabdc7fcb57b8d0 /clang/unittests/Format/CleanupTest.cpp | |
parent | 6e7d5467c01e4b8ecda963dee260b2a56f589da1 (diff) | |
download | bcm5719-llvm-3528832930542732d9defefb97e242f03fb5bd5c.tar.gz bcm5719-llvm-3528832930542732d9defefb97e242f03fb5bd5c.zip |
[clang-format] make header guard identification stricter (with Lexer).
Summary: make header guard identification stricter with Lexer.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D20959
llvm-svn: 271883
Diffstat (limited to 'clang/unittests/Format/CleanupTest.cpp')
-rw-r--r-- | clang/unittests/Format/CleanupTest.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index 83b5dc0f58c..9037304a723 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -608,6 +608,86 @@ TEST_F(CleanUpReplacementsTest, CodeAfterComments) { EXPECT_EQ(Expected, apply(Code, Replaces)); } +TEST_F(CleanUpReplacementsTest, FakeHeaderGuardIfDef) { + std::string Code = "// comment \n" + "#ifdef X\n" + "#define X\n"; + std::string Expected = "// comment \n" + "#include <vector>\n" + "#ifdef X\n" + "#define X\n"; + tooling::Replacements Replaces = {createInsertion("#include <vector>")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + +TEST_F(CleanUpReplacementsTest, RealHeaderGuardAfterComments) { + std::string Code = "// comment \n" + "#ifndef X\n" + "#define X\n" + "int x;\n" + "#define Y 1\n"; + std::string Expected = "// comment \n" + "#ifndef X\n" + "#define X\n" + "#include <vector>\n" + "int x;\n" + "#define Y 1\n"; + tooling::Replacements Replaces = {createInsertion("#include <vector>")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + +TEST_F(CleanUpReplacementsTest, IfNDefWithNoDefine) { + std::string Code = "// comment \n" + "#ifndef X\n" + "int x;\n" + "#define Y 1\n"; + std::string Expected = "// comment \n" + "#include <vector>\n" + "#ifndef X\n" + "int x;\n" + "#define Y 1\n"; + tooling::Replacements Replaces = {createInsertion("#include <vector>")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + +TEST_F(CleanUpReplacementsTest, HeaderGuardWithComment) { + std::string Code = "// comment \n" + "#ifndef X // comment\n" + "// comment\n" + "/* comment\n" + "*/\n" + "/* comment */ #define X\n" + "int x;\n" + "#define Y 1\n"; + std::string Expected = "// comment \n" + "#ifndef X // comment\n" + "// comment\n" + "/* comment\n" + "*/\n" + "/* comment */ #define X\n" + "#include <vector>\n" + "int x;\n" + "#define Y 1\n"; + tooling::Replacements Replaces = {createInsertion("#include <vector>")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + +TEST_F(CleanUpReplacementsTest, EmptyCode) { + std::string Code = ""; + std::string Expected = "#include <vector>\n"; + tooling::Replacements Replaces = {createInsertion("#include <vector>")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + +// FIXME: although this case does not crash, the insertion is wrong. A '\n' +// should be inserted between the two #includes. +TEST_F(CleanUpReplacementsTest, NoNewLineAtTheEndOfCode) { + std::string Code = "#include <map>"; + std::string Expected = "#include <map>#include <vector>\n"; + tooling::Replacements Replaces = {createInsertion("#include <vector>")}; + EXPECT_EQ(Expected, apply(Code, Replaces)); +} + } // end namespace } // end namespace format } // end namespace clang |