summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorPaul Hoad <mydeveloperday@gmail.com>2019-03-13 08:15:03 +0000
committerPaul Hoad <mydeveloperday@gmail.com>2019-03-13 08:15:03 +0000
commitd74c055fe640d85d5fb22e261770601567c769ee (patch)
tree1797a4d04748a8a1c372aa74c9039d828de60c4d /clang/unittests/Format/FormatTest.cpp
parent6d294f28e9a24ca941f88bce7c8ed98d5931a3fc (diff)
downloadbcm5719-llvm-d74c055fe640d85d5fb22e261770601567c769ee.tar.gz
bcm5719-llvm-d74c055fe640d85d5fb22e261770601567c769ee.zip
Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present"
This reverts commit b358cbb9b78389e20f7be36e1a98e26515c3ecce. llvm-svn: 356030
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp75
1 files changed, 10 insertions, 65 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 7fcff46f581..650636b7633 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -439,8 +439,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
FormatStyle AllowsMergedIf = getLLVMStyle();
AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
- AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_WithoutElse;
+ AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
verifyFormat("if (a)\n"
" // comment\n"
" f();",
@@ -488,41 +487,6 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
verifyFormat("if (a)\n return;", AllowsMergedIf);
}
-TEST_F(FormatTest, FormatIfWithoutCompoundStatementButElseWith) {
- FormatStyle AllowsMergedIf = getLLVMStyle();
- AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
- AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_WithoutElse;
- verifyFormat("if (a)\n"
- " f();\n"
- "else {\n"
- " g();\n"
- "}",
- AllowsMergedIf);
- verifyFormat("if (a)\n"
- " f();\n"
- "else\n"
- " g();\n",
- AllowsMergedIf);
-
- AllowsMergedIf.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Always;
-
- verifyFormat("if (a) f();\n"
- "else {\n"
- " g();\n"
- "}",
- AllowsMergedIf);
- verifyFormat("if (a) f();\n"
- "else {\n"
- " if (a) f();\n"
- " else {\n"
- " g();\n"
- " }\n"
- " g();\n"
- "}",
- AllowsMergedIf);
-}
-
TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
FormatStyle AllowsMergedLoops = getLLVMStyle();
AllowsMergedLoops.AllowShortLoopsOnASingleLine = true;
@@ -551,8 +515,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
AllowSimpleBracedStatements.ColumnLimit = 40;
AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true;
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_WithoutElse;
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
AllowSimpleBracedStatements.BreakBeforeBraces = FormatStyle::BS_Custom;
@@ -600,8 +563,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
"};",
AllowSimpleBracedStatements);
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_Never;
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
verifyFormat("if (true) {}", AllowSimpleBracedStatements);
verifyFormat("if (true) {\n"
" f();\n"
@@ -626,8 +588,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
"}",
AllowSimpleBracedStatements);
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_WithoutElse;
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
@@ -664,8 +625,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
"}",
AllowSimpleBracedStatements);
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_Never;
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
verifyFormat("if (true) {}", AllowSimpleBracedStatements);
verifyFormat("if (true)\n"
"{\n"
@@ -699,7 +659,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
FormatStyle Style = getLLVMStyleWithColumns(60);
Style.AllowShortBlocksOnASingleLine = true;
- Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_WithoutElse;
+ Style.AllowShortIfStatementsOnASingleLine = true;
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
EXPECT_EQ("#define A \\\n"
" if (HANDLEwernufrnuLwrmviferuvnierv) \\\n"
@@ -3197,7 +3157,7 @@ TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
FormatStyle SingleLine = getLLVMStyle();
- SingleLine.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_WithoutElse;
+ SingleLine.AllowShortIfStatementsOnASingleLine = true;
verifyFormat("#if 0\n"
"#elif 1\n"
"#endif\n"
@@ -8040,8 +8000,7 @@ TEST_F(FormatTest, FormatHashIfExpressions) {
TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) {
FormatStyle AllowsMergedIf = getGoogleStyle();
- AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_WithoutElse;
+ AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
verifyFormat("void f() { f(); }\n#error E", AllowsMergedIf);
verifyFormat("if (true) return 42;\n#error E", AllowsMergedIf);
verifyFormat("if (true)\n#error E\n return 42;", AllowsMergedIf);
@@ -10466,8 +10425,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
AllmanBraceStyle.ColumnLimit = 80;
FormatStyle BreakBeforeBraceShortIfs = AllmanBraceStyle;
- BreakBeforeBraceShortIfs.AllowShortIfStatementsOnASingleLine =
- FormatStyle::SIS_WithoutElse;
+ BreakBeforeBraceShortIfs.AllowShortIfStatementsOnASingleLine = true;
BreakBeforeBraceShortIfs.AllowShortLoopsOnASingleLine = true;
verifyFormat("void f(bool b)\n"
"{\n"
@@ -10929,6 +10887,7 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine);
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
+ CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(BinPackArguments);
CHECK_PARSE_BOOL(BinPackParameters);
@@ -11191,20 +11150,6 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE("NamespaceIndentation: All", NamespaceIndentation,
FormatStyle::NI_All);
- Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Always;
- CHECK_PARSE("AllowShortIfStatementsOnASingleLine: Never",
- AllowShortIfStatementsOnASingleLine, FormatStyle::SIS_Never);
- CHECK_PARSE("AllowShortIfStatementsOnASingleLine: WithoutElse",
- AllowShortIfStatementsOnASingleLine,
- FormatStyle::SIS_WithoutElse);
- CHECK_PARSE("AllowShortIfStatementsOnASingleLine: Always",
- AllowShortIfStatementsOnASingleLine, FormatStyle::SIS_Always);
- CHECK_PARSE("AllowShortIfStatementsOnASingleLine: false",
- AllowShortIfStatementsOnASingleLine, FormatStyle::SIS_Never);
- CHECK_PARSE("AllowShortIfStatementsOnASingleLine: true",
- AllowShortIfStatementsOnASingleLine,
- FormatStyle::SIS_WithoutElse);
-
// FIXME: This is required because parsing a configuration simply overwrites
// the first N elements of the list instead of resetting it.
Style.ForEachMacros.clear();
OpenPOWER on IntegriCloud