diff options
author | Daniel Jasper <djasper@google.com> | 2013-11-05 19:10:03 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-11-05 19:10:03 +0000 |
commit | 2a80ad6fe7aa506b1df2bb638bc367d9e760f707 (patch) | |
tree | e1898983a585cafd84d1a289b146996e3f1c0fc1 /unittests | |
parent | 9ce5135c15b3dfd5ee666b843f5df8ffb3a5038f (diff) | |
download | clang-2a80ad6fe7aa506b1df2bb638bc367d9e760f707.tar.gz |
clang-format: Allow line merging and partial formatting of nested blocks
Before, clang-format would always format entire nested blocks, which
can be unwanted e.g. for long DEBUG({...}) statements. Also
clang-format would not allow to merge lines in nested blocks (e.g. to
put "if (a) return;" on one line in Google style).
This is the first step of several refactorings mostly focussing on the
additional functionality (by reusing the "format many lines" code to
format the children of a nested block). The next steps are:
* Pull out the line merging into its own class.
* Seperate the formatting of many lines from the formatting of a single
line (and the analysis of the solution space).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194090 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 5852d1c0ed..fc6ef2bb5e 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2447,6 +2447,45 @@ TEST_F(FormatTest, LayoutNestedBlocks) { " // comment\n" " int j;\n" "});")); + + verifyFormat("DEBUG({\n" + " if (a)\n" + " return;\n" + "});"); + verifyGoogleFormat("DEBUG({\n" + " if (a) return;\n" + "});"); + FormatStyle Style = getGoogleStyle(); + Style.ColumnLimit = 45; + verifyFormat("Debug(aaaaa, {\n" + " if (aaaaaaaaaaaaaaaaaaaaaaaa)\n" + " return;\n" + " },\n" + " a);", Style); + + EXPECT_EQ("Debug({\n" + " if (aaaaaaaaaaaaaaaaaaaaaaaa)\n" + " return;\n" + " },\n" + " a);", + format("Debug({\n" + " if (aaaaaaaaaaaaaaaaaaaaaaaa)\n" + " return;\n" + " },\n" + " a);", + 50, 1, getLLVMStyle())); +} + +TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) { + EXPECT_EQ("DEBUG({\n" + " int i;\n" + " int j;\n" + "});", + format("DEBUG( {\n" + " int i;\n" + " int j;\n" + "} ) ;", + 40, 1, getLLVMStyle())); } TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) { |