diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-18 14:04:34 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-18 14:04:34 +0000 |
commit | 525fe168c25a8273899281c5d2326c722fc3f2a5 (patch) | |
tree | 3118da57eae0699db38c0bcc26d974dd0d4fc1eb /unittests/Format/FormatTest.cpp | |
parent | b8238b6f20bf7b5a79f18dc84ab3e51db479faa7 (diff) |
Fixes problems with line merging in the face of preprocessor directives.
This patch prepares being able to test for and fix more problems (see
FIXME in the test for example).
Previously we would output unwrapped lines for preprocessor directives
at the point where we also parsed the hash token. Since often
projections only terminate (and thus output their own unwrapped line)
after peeking at the next token, this would lead to the formatter seeing
the preprocessor directives out-of-order (slightly earlier). To be able
to correctly identify lines to merge, the formatter needs a well-defined
order of unwrapped lines, which this patch introduces.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172819 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 806707cb4c..6b77868776 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1537,6 +1537,16 @@ TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) { EXPECT_EQ("#warning 1", format(" # warning 1")); } +TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) { + FormatStyle AllowsMergedIf = getGoogleStyle(); + AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true; + verifyFormat("void f() { f(); }\n#error E", AllowsMergedIf); + verifyFormat("if (true) return 42;\n#error E", AllowsMergedIf); + + // FIXME: + // verifyFormat("if (true)\n#error E\n return 42;", AllowsMergedIf); +} + // FIXME: This breaks the order of the unwrapped lines: // TEST_F(FormatTest, OrderUnwrappedLines) { // verifyFormat("{\n" |