From b10cbc45ad4ea8c75caef27b203c2f7044414b56 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 10 Jul 2013 14:02:49 +0000 Subject: Add experimental flag for adaptive parameter bin-packing. This is not activated for any style, might change or go away completely. For those that want to play around with it, set ExperimentalAutoDetectBinPacking to true. clang-format will then: Look at whether function calls/declarations/definitions are currently formatted with one parameter per line (on a case-by-case basis). If so, clang-format will avoid bin-packing the parameters. If all parameters are on one line (thus that line is "inconclusive"), clang-format will make the choice dependent on whether there are other bin-packed calls/declarations in the same file. The reason for this change is that bin-packing in some situations can be really bad and an author might opt to put one parameter on each line. If the author does that, he might want clang-format not to mess with that. If the author is unhappy with the one-per-line formatting, clang-format can easily be convinced to bin-pack by putting any two parameters on the same line. llvm-svn: 186003 --- clang/unittests/Format/FormatTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'clang/unittests/Format/FormatTest.cpp') diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 0192a0718b3..b87393a9da2 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2644,6 +2644,30 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, AdaptiveOnePerLineFormatting) { + FormatStyle Style = getLLVMStyleWithColumns(15); + Style.ExperimentalAutoDetectBinPacking = true; + EXPECT_EQ("aaa(aaaa,\n" + " aaaa,\n" + " aaaa);\n" + "aaa(aaaa,\n" + " aaaa,\n" + " aaaa);", + format("aaa(aaaa,\n" // one-per-line + " aaaa,\n" + " aaaa );\n" + "aaa(aaaa, aaaa, aaaa);", // inconclusive + Style)); + EXPECT_EQ("aaa(aaaa, aaaa,\n" + " aaaa);\n" + "aaa(aaaa, aaaa,\n" + " aaaa);", + format("aaa(aaaa, aaaa,\n" // bin-packed + " aaaa );\n" + "aaa(aaaa, aaaa, aaaa);", // inconclusive + Style)); +} + TEST_F(FormatTest, FormatsBuilderPattern) { verifyFormat( "return llvm::StringSwitch(name)\n" -- cgit v1.2.3