aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-01-09 15:25:02 +0000
committerManuel Klimek <klimek@google.com>2013-01-09 15:25:02 +0000
commit526ed11ad9743c773df76bd1649d33fb92c2b8cb (patch)
treea2043c193caafb553102c6c1f413db8cdc404a87 /unittests/Format/FormatTest.cpp
parent35eb8c3e12cac22f91d1cd4c74ae092ebc94fc40 (diff)
Enables layouting unwrapped lines around preprocessor directives.
Previously, we'd always start at indent level 0 after a preprocessor directive, now we layout the following snippet (column limit 69) as follows: functionCallTo(someOtherFunction( withSomeParameters, whichInSequence, areLongerThanALine(andAnotherCall, B withMoreParamters, whichStronglyInfluenceTheLayout), andMoreParameters), trailing); Note that the different jumping indent is a different issue that will be addressed separately. This is the first step towards handling #ifdef->#else->#endif chains correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171974 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index d4e5a51bc3..c21ff24834 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -46,17 +46,24 @@ protected:
std::string messUp(llvm::StringRef Code) {
std::string MessedUp(Code.str());
bool InComment = false;
+ bool InPreprocessorDirective = false;
bool JustReplacedNewline = false;
for (unsigned i = 0, e = MessedUp.size() - 1; i != e; ++i) {
if (MessedUp[i] == '/' && MessedUp[i + 1] == '/') {
if (JustReplacedNewline)
MessedUp[i - 1] = '\n';
InComment = true;
+ } else if (MessedUp[i] == '#' && JustReplacedNewline) {
+ MessedUp[i - 1] = '\n';
+ InPreprocessorDirective = true;
} else if (MessedUp[i] == '\\' && MessedUp[i + 1] == '\n') {
MessedUp[i] = ' ';
+ MessedUp[i + 1] = ' ';
} else if (MessedUp[i] == '\n') {
if (InComment) {
InComment = false;
+ } else if (InPreprocessorDirective) {
+ InPreprocessorDirective = false;
} else {
JustReplacedNewline = true;
MessedUp[i] = ' ';
@@ -84,6 +91,14 @@ protected:
}
};
+TEST_F(FormatTest, MessUp) {
+ EXPECT_EQ("1 2 3", messUp("1 2 3"));
+ EXPECT_EQ("1 2 3\n", messUp("1\n2\n3\n"));
+ EXPECT_EQ("a\n//b\nc", messUp("a\n//b\nc"));
+ EXPECT_EQ("a\n#b\nc", messUp("a\n#b\nc"));
+ EXPECT_EQ("a\n#b c d\ne", messUp("a\n#b\\\nc\\\nd\ne"));
+}
+
//===----------------------------------------------------------------------===//
// Basic function tests.
//===----------------------------------------------------------------------===//
@@ -545,7 +560,9 @@ TEST_F(FormatTest, LayoutSingleUnwrappedLineInMacro) {
}
TEST_F(FormatTest, MacroDefinitionInsideStatement) {
- EXPECT_EQ("int x,\n#define A\ny;", format("int x,\n#define A\ny;"));
+ EXPECT_EQ("int x,\n"
+ "#define A\n"
+ " y;", format("int x,\n#define A\ny;"));
}
TEST_F(FormatTest, HashInMacroDefinition) {
@@ -609,6 +626,23 @@ TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
" aLooooooooooooooooooooooonPaaaaaaaaaaaaaaaaaaaaarmmmm);\n"));
}
+TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {
+ EXPECT_EQ("int\n"
+ "#define A\n"
+ " a;",
+ format("int\n#define A\na;"));
+ verifyFormat(
+ "functionCallTo(someOtherFunction(\n"
+ " withSomeParameters, whichInSequence,\n"
+ " areLongerThanALine(andAnotherCall,\n"
+ "#define A \\\n"
+ " B\n"
+ " withMoreParamters,\n"
+ " whichStronglyInfluenceTheLayout),\n"
+ " andMoreParameters),\n"
+ " trailing);", getLLVMStyleWithColumns(69));
+}
+
//===----------------------------------------------------------------------===//
// Line break tests.
//===----------------------------------------------------------------------===//