summaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2019-08-11 17:48:36 +0000
committerOwen Pan <owenpiano@gmail.com>2019-08-11 17:48:36 +0000
commitd671e605e4d22270300406268d483eb95558f543 (patch)
tree5e778f13d567474dccae738895b2e48d21c0b471 /unittests/Format/FormatTest.cpp
parentc9a615ed810c08ac0190a589f2c658433d726728 (diff)
downloadclang-d671e605e4d22270300406268d483eb95558f543.tar.gz
[clang-format] Expand AllowShortBlocksOnASingleLine for WebKit
See PR40840 Differential Revision: https://reviews.llvm.org/D66059 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368539 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 197c08bfaf..3fe75ec233 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -561,7 +561,8 @@ TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
TEST_F(FormatTest, FormatShortBracedStatements) {
FormatStyle AllowSimpleBracedStatements = getLLVMStyle();
AllowSimpleBracedStatements.ColumnLimit = 40;
- AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true;
+ AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine =
+ FormatStyle::SBS_Always;
AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
FormatStyle::SIS_WithoutElse;
@@ -714,7 +715,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
FormatStyle Style = getLLVMStyleWithColumns(60);
- Style.AllowShortBlocksOnASingleLine = true;
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_WithoutElse;
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
EXPECT_EQ("#define A \\\n"
@@ -1163,7 +1164,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
FormatStyle Style = getLLVMStyle();
Style.IndentCaseLabels = true;
- Style.AllowShortBlocksOnASingleLine = false;
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.AfterCaseLabel = true;
Style.BraceWrapping.AfterControlStatement = true;
@@ -3692,10 +3693,10 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
EXPECT_EQ("{}", format("{}"));
verifyFormat("enum E {};");
verifyFormat("enum E {}");
- EXPECT_EQ("void f() { }", format("void f() {}", getWebKitStyle()));
FormatStyle Style = getLLVMStyle();
- Style.AllowShortBlocksOnASingleLine = true;
Style.SpaceInEmptyBlock = true;
+ EXPECT_EQ("void f() { }", format("void f() {}", Style));
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
EXPECT_EQ("while (true) { }", format("while (true) {}", Style));
}
@@ -11745,7 +11746,6 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
CHECK_PARSE_BOOL(AllowAllConstructorInitializersOnNextLine);
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
- CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine);
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(BinPackArguments);
@@ -11920,6 +11920,19 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE("UseTab: false", UseTab, FormatStyle::UT_Never);
CHECK_PARSE("UseTab: true", UseTab, FormatStyle::UT_Always);
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
+ CHECK_PARSE("AllowShortBlocksOnASingleLine: Never",
+ AllowShortBlocksOnASingleLine, FormatStyle::SBS_Never);
+ CHECK_PARSE("AllowShortBlocksOnASingleLine: Empty",
+ AllowShortBlocksOnASingleLine, FormatStyle::SBS_Empty);
+ CHECK_PARSE("AllowShortBlocksOnASingleLine: Always",
+ AllowShortBlocksOnASingleLine, FormatStyle::SBS_Always);
+ // For backward compatibility:
+ CHECK_PARSE("AllowShortBlocksOnASingleLine: false",
+ AllowShortBlocksOnASingleLine, FormatStyle::SBS_Never);
+ CHECK_PARSE("AllowShortBlocksOnASingleLine: true",
+ AllowShortBlocksOnASingleLine, FormatStyle::SBS_Always);
+
Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
CHECK_PARSE("AllowShortFunctionsOnASingleLine: None",
AllowShortFunctionsOnASingleLine, FormatStyle::SFS_None);
@@ -12527,6 +12540,14 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
// Allow functions on a single line.
verifyFormat("void f() { return; }", Style);
+ // Allow empty blocks on a single line and insert a space in empty blocks.
+ EXPECT_EQ("void f() { }", format("void f() {}", Style));
+ EXPECT_EQ("while (true) { }", format("while (true) {}", Style));
+ // However, don't merge non-empty short loops.
+ EXPECT_EQ("while (true) {\n"
+ " continue;\n"
+ "}", format("while (true) { continue; }", Style));
+
// Constructor initializers are formatted one per line with the "," on the
// new line.
verifyFormat("Constructor()\n"
@@ -13033,7 +13054,7 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
TEST_F(FormatTest, FormatsBlocks) {
FormatStyle ShortBlocks = getLLVMStyle();
- ShortBlocks.AllowShortBlocksOnASingleLine = true;
+ ShortBlocks.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
verifyFormat("int (^Block)(int, int);", ShortBlocks);
verifyFormat("int (^Block1)(int, int) = ^(int i, int j)", ShortBlocks);
verifyFormat("void (^block)(int) = ^(id test) { int i; };", ShortBlocks);
@@ -13191,10 +13212,10 @@ TEST_F(FormatTest, FormatsBlocksWithZeroColumnWidth) {
"};",
ZeroColumn);
- ZeroColumn.AllowShortBlocksOnASingleLine = true;
+ ZeroColumn.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
EXPECT_EQ("void (^largeBlock)(void) = ^{ int i; };",
format("void (^largeBlock)(void) = ^{ int i; };", ZeroColumn));
- ZeroColumn.AllowShortBlocksOnASingleLine = false;
+ ZeroColumn.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
EXPECT_EQ("void (^largeBlock)(void) = ^{\n"
" int i;\n"
"};",