From 100ecde90ef26ee81763214d5fb335415ffc2b53 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Wed, 21 Jun 2017 13:56:02 +0000 Subject: clang-format: introduce InlineOnly short function style Summary: This is the same as Inline, except it does not imply all empty functions are merged: with this style, empty functions are merged only if they also match the 'inline' criteria (i.e. defined in a class). This is helpful to avoid inlining functions in implementations files. Reviewers: djasper, krasimir Reviewed By: djasper Subscribers: klimek, rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D34399 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305912 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Format/FormatTest.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'unittests') diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 51849d9650..b43f735d4c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6509,6 +6509,52 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { MergeInlineOnly); } +TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { + FormatStyle MergeInlineOnly = getLLVMStyle(); + MergeInlineOnly.AllowShortFunctionsOnASingleLine = + FormatStyle::SFS_InlineOnly; + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + MergeInlineOnly); + verifyFormat("int f() {\n" + " return 42;\n" + "}", + MergeInlineOnly); + + // SFS_InlineOnly does not imply SFS_Empty + verifyFormat("class C {\n" + " int f() {}\n" + "};", + MergeInlineOnly); + verifyFormat("int f() {\n" + "}", + MergeInlineOnly); + + // Also verify behavior when BraceWrapping.AfterFunction = true + MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom; + MergeInlineOnly.BraceWrapping.AfterFunction = true; + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + MergeInlineOnly); + verifyFormat("int f()\n" + "{\n" + " return 42;\n" + "}", + MergeInlineOnly); + + // SFS_InlineOnly does not imply SFS_Empty + verifyFormat("int f()\n" + "{\n" + "}", + MergeInlineOnly); + verifyFormat("class C {\n" + " int f() {}\n" + "};", + MergeInlineOnly); +} + TEST_F(FormatTest, SplitEmptyFunctionBody) { FormatStyle Style = getLLVMStyle(); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; -- cgit v1.2.3