|
@@ -439,7 +439,8 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
|
|
|
|
|
|
FormatStyle AllowsMergedIf = getLLVMStyle();
|
|
FormatStyle AllowsMergedIf = getLLVMStyle();
|
|
AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
|
|
AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
|
|
- AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_WithoutElse;
|
|
verifyFormat("if (a)\n"
|
|
verifyFormat("if (a)\n"
|
|
" // comment\n"
|
|
" // comment\n"
|
|
" f();",
|
|
" f();",
|
|
@@ -487,6 +488,41 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
|
|
verifyFormat("if (a)\n return;", AllowsMergedIf);
|
|
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) {
|
|
TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
|
|
FormatStyle AllowsMergedLoops = getLLVMStyle();
|
|
FormatStyle AllowsMergedLoops = getLLVMStyle();
|
|
AllowsMergedLoops.AllowShortLoopsOnASingleLine = true;
|
|
AllowsMergedLoops.AllowShortLoopsOnASingleLine = true;
|
|
@@ -515,7 +551,8 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
|
|
AllowSimpleBracedStatements.ColumnLimit = 40;
|
|
AllowSimpleBracedStatements.ColumnLimit = 40;
|
|
AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true;
|
|
AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true;
|
|
|
|
|
|
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_WithoutElse;
|
|
AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
|
|
AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
|
|
|
|
|
|
AllowSimpleBracedStatements.BreakBeforeBraces = FormatStyle::BS_Custom;
|
|
AllowSimpleBracedStatements.BreakBeforeBraces = FormatStyle::BS_Custom;
|
|
@@ -563,7 +600,8 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
|
|
"};",
|
|
"};",
|
|
AllowSimpleBracedStatements);
|
|
AllowSimpleBracedStatements);
|
|
|
|
|
|
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
|
|
|
|
|
|
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_Never;
|
|
verifyFormat("if (true) {}", AllowSimpleBracedStatements);
|
|
verifyFormat("if (true) {}", AllowSimpleBracedStatements);
|
|
verifyFormat("if (true) {\n"
|
|
verifyFormat("if (true) {\n"
|
|
" f();\n"
|
|
" f();\n"
|
|
@@ -588,7 +626,8 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
|
|
"}",
|
|
"}",
|
|
AllowSimpleBracedStatements);
|
|
AllowSimpleBracedStatements);
|
|
|
|
|
|
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_WithoutElse;
|
|
AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
|
|
AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
|
|
AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
|
|
AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
|
|
|
|
|
|
@@ -625,7 +664,8 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
|
|
"}",
|
|
"}",
|
|
AllowSimpleBracedStatements);
|
|
AllowSimpleBracedStatements);
|
|
|
|
|
|
- AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
|
|
|
|
|
|
+ AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_Never;
|
|
verifyFormat("if (true) {}", AllowSimpleBracedStatements);
|
|
verifyFormat("if (true) {}", AllowSimpleBracedStatements);
|
|
verifyFormat("if (true)\n"
|
|
verifyFormat("if (true)\n"
|
|
"{\n"
|
|
"{\n"
|
|
@@ -659,7 +699,7 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
|
|
TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
|
|
TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
|
|
FormatStyle Style = getLLVMStyleWithColumns(60);
|
|
FormatStyle Style = getLLVMStyleWithColumns(60);
|
|
Style.AllowShortBlocksOnASingleLine = true;
|
|
Style.AllowShortBlocksOnASingleLine = true;
|
|
- Style.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_WithoutElse;
|
|
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
|
|
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
|
|
EXPECT_EQ("#define A \\\n"
|
|
EXPECT_EQ("#define A \\\n"
|
|
" if (HANDLEwernufrnuLwrmviferuvnierv) \\\n"
|
|
" if (HANDLEwernufrnuLwrmviferuvnierv) \\\n"
|
|
@@ -3157,7 +3197,7 @@ TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
|
|
|
|
|
|
TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
|
|
TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
|
|
FormatStyle SingleLine = getLLVMStyle();
|
|
FormatStyle SingleLine = getLLVMStyle();
|
|
- SingleLine.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ SingleLine.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_WithoutElse;
|
|
verifyFormat("#if 0\n"
|
|
verifyFormat("#if 0\n"
|
|
"#elif 1\n"
|
|
"#elif 1\n"
|
|
"#endif\n"
|
|
"#endif\n"
|
|
@@ -8000,7 +8040,8 @@ TEST_F(FormatTest, FormatHashIfExpressions) {
|
|
|
|
|
|
TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) {
|
|
TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) {
|
|
FormatStyle AllowsMergedIf = getGoogleStyle();
|
|
FormatStyle AllowsMergedIf = getGoogleStyle();
|
|
- AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_WithoutElse;
|
|
verifyFormat("void f() { f(); }\n#error E", AllowsMergedIf);
|
|
verifyFormat("void f() { f(); }\n#error E", AllowsMergedIf);
|
|
verifyFormat("if (true) return 42;\n#error E", AllowsMergedIf);
|
|
verifyFormat("if (true) return 42;\n#error E", AllowsMergedIf);
|
|
verifyFormat("if (true)\n#error E\n return 42;", AllowsMergedIf);
|
|
verifyFormat("if (true)\n#error E\n return 42;", AllowsMergedIf);
|
|
@@ -10425,7 +10466,8 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
|
|
AllmanBraceStyle.ColumnLimit = 80;
|
|
AllmanBraceStyle.ColumnLimit = 80;
|
|
|
|
|
|
FormatStyle BreakBeforeBraceShortIfs = AllmanBraceStyle;
|
|
FormatStyle BreakBeforeBraceShortIfs = AllmanBraceStyle;
|
|
- BreakBeforeBraceShortIfs.AllowShortIfStatementsOnASingleLine = true;
|
|
|
|
|
|
+ BreakBeforeBraceShortIfs.AllowShortIfStatementsOnASingleLine =
|
|
|
|
+ FormatStyle::SIS_WithoutElse;
|
|
BreakBeforeBraceShortIfs.AllowShortLoopsOnASingleLine = true;
|
|
BreakBeforeBraceShortIfs.AllowShortLoopsOnASingleLine = true;
|
|
verifyFormat("void f(bool b)\n"
|
|
verifyFormat("void f(bool b)\n"
|
|
"{\n"
|
|
"{\n"
|
|
@@ -10887,7 +10929,6 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
|
|
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
|
|
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
|
|
CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine);
|
|
CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine);
|
|
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
|
|
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
|
|
- CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
|
|
|
|
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
|
|
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
|
|
CHECK_PARSE_BOOL(BinPackArguments);
|
|
CHECK_PARSE_BOOL(BinPackArguments);
|
|
CHECK_PARSE_BOOL(BinPackParameters);
|
|
CHECK_PARSE_BOOL(BinPackParameters);
|
|
@@ -11150,6 +11191,20 @@ TEST_F(FormatTest, ParsesConfiguration) {
|
|
CHECK_PARSE("NamespaceIndentation: All", NamespaceIndentation,
|
|
CHECK_PARSE("NamespaceIndentation: All", NamespaceIndentation,
|
|
FormatStyle::NI_All);
|
|
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
|
|
// FIXME: This is required because parsing a configuration simply overwrites
|
|
// the first N elements of the list instead of resetting it.
|
|
// the first N elements of the list instead of resetting it.
|
|
Style.ForEachMacros.clear();
|
|
Style.ForEachMacros.clear();
|