diff options
| author | Daniel Jasper <djasper@google.com> | 2014-04-08 12:46:38 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-04-08 12:46:38 +0000 |
| commit | d74cf40386ac321fca0aed6404647667d2ef00f7 (patch) | |
| tree | 34c11655e5f4982bc936312ef7122a1a81e80f8e /clang/unittests/Format/FormatTest.cpp | |
| parent | 9eb8c92b526b13491565585b0d33159d624bf811 (diff) | |
| download | bcm5719-llvm-d74cf40386ac321fca0aed6404647667d2ef00f7.tar.gz bcm5719-llvm-d74cf40386ac321fca0aed6404647667d2ef00f7.zip | |
clang-format: Extend AllowShortFunctions.. to only merge inline functions.
Before AllowShortFunctionsOnASingleLine could either be true, merging
all functions, or false, merging no functions. This patch adds a third
value "Inline", which can be used to only merge short functions defined
inline in a class, i.e.:
void f() {
return 42;
}
class C {
void f() { return 42; }
};
llvm-svn: 205760
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 90e6ff72037..d59ed6c0aff 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5162,7 +5162,7 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { FormatStyle DoNotMerge = getLLVMStyle(); - DoNotMerge.AllowShortFunctionsOnASingleLine = false; + DoNotMerge.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; verifyFormat("void f() { return 42; }"); verifyFormat("void f() {\n" @@ -5219,7 +5219,8 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { format("A()\n:b(0)\n{\n}", NoColumnLimit)); FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit; - DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = false; + DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = + FormatStyle::SFS_None; EXPECT_EQ("A()\n" " : b(0) {\n" "}", @@ -5249,6 +5250,19 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { getLLVMStyleWithColumns(23)); } +TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { + FormatStyle MergeInlineOnly = getLLVMStyle(); + MergeInlineOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + MergeInlineOnly); + verifyFormat("int f() {\n" + " return 42;\n" + "}", + MergeInlineOnly); +} + TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { // Elaborate type variable declarations. verifyFormat("struct foo a = {bar};\nint n;"); @@ -7537,7 +7551,6 @@ TEST_F(FormatTest, ParsesConfiguration) { CHECK_PARSE_BOOL(AlignEscapedNewlinesLeft); CHECK_PARSE_BOOL(AlignTrailingComments); CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine); - CHECK_PARSE_BOOL(AllowShortFunctionsOnASingleLine); CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine); CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine); CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations); @@ -7590,6 +7603,18 @@ TEST_F(FormatTest, ParsesConfiguration) { CHECK_PARSE("UseTab: ForIndentation", UseTab, FormatStyle::UT_ForIndentation); CHECK_PARSE("UseTab: Always", UseTab, FormatStyle::UT_Always); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + CHECK_PARSE("AllowShortFunctionsOnASingleLine: false", + AllowShortFunctionsOnASingleLine, FormatStyle::SFS_None); + CHECK_PARSE("AllowShortFunctionsOnASingleLine: true", + AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All); + CHECK_PARSE("AllowShortFunctionsOnASingleLine: None", + AllowShortFunctionsOnASingleLine, FormatStyle::SFS_None); + CHECK_PARSE("AllowShortFunctionsOnASingleLine: Inline", + AllowShortFunctionsOnASingleLine, FormatStyle::SFS_Inline); + CHECK_PARSE("AllowShortFunctionsOnASingleLine: All", + AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All); + Style.SpaceBeforeParens = FormatStyle::SBPO_Always; CHECK_PARSE("SpaceBeforeParens: Never", SpaceBeforeParens, FormatStyle::SBPO_Never); @@ -7943,7 +7968,7 @@ TEST_F(FormatTest, ConstructorInitializerIndentWidth) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = false; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; verifyFormat("SomeClass::Constructor()\n" " : a(a)\n" " , b(b)\n" @@ -7954,7 +7979,7 @@ TEST_F(FormatTest, ConstructorInitializerIndentWidth) { Style); Style.ColumnLimit = 80; - Style.AllowShortFunctionsOnASingleLine = true; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; Style.ConstructorInitializerIndentWidth = 2; verifyFormat("SomeClass::Constructor()\n" " : a(a)\n" |

