diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-07 09:24:17 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-07 09:24:17 +0000 |
commit | d544c574ccbcbfcb5b3c3edd19956143826008cf (patch) | |
tree | f0ae6671f751d5efe12dd0a53324157fd8d105b4 /unittests/Format/FormatTest.cpp | |
parent | 6cf581436e9e59a18f6a362027a69eaaa9b67597 (diff) |
Do not ever allow using the full line in preprocessor directives.
We would format:
#define A \
int f(a); int i;
as
#define A \
int f(a);\
int i
The fix will break up macro definitions that could fit a line, but hit
the last column; fixing that is more involved, though, as it requires
looking at the following line.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171715 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 27ca53c1ea..54999e1f63 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -413,11 +413,13 @@ TEST_F(FormatTest, EndOfFileEndsPPDirective) { } TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) { - // If the macro fits in one line, we have the full width. - verifyFormat("#define A(B)", getLLVMStyleWithColumns(12)); + // If the macro fits in one line, we still do not get the full + // line, as only the next line decides whether we need an escaped newline and + // thus use the last column. + verifyFormat("#define A(B)", getLLVMStyleWithColumns(13)); - verifyFormat("#define A(\\\n B)", getLLVMStyleWithColumns(11)); - verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(11)); + verifyFormat("#define A( \\\n B)", getLLVMStyleWithColumns(12)); + verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(12)); verifyFormat("#define A( \\\n A, B)", getLLVMStyleWithColumns(12)); } @@ -490,6 +492,13 @@ TEST_F(FormatTest, EscapedNewlineAtStartOfTokenInMacroDefinition) { getLLVMStyleWithColumns(11))); } +TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) { + verifyFormat("#define A \\\n" + " int v( \\\n" + " a); \\\n" + " int i;", getLLVMStyleWithColumns(11)); +} + TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) { EXPECT_EQ( "#define ALooooooooooooooooooooooooooooooooooooooongMacro(" |