@@ -8655,6 +8655,19 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
86558655 Style);
86568656}
86578657
8658+ TEST_F(FormatTest, BreakFunctionsReturningRecords) {
8659+ FormatStyle Style = getLLVMStyle();
8660+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
8661+ Style.BraceWrapping.AfterFunction = true;
8662+ Style.BraceWrapping.AfterClass = false;
8663+ Style.BraceWrapping.AfterStruct = false;
8664+ Style.BraceWrapping.AfterUnion = false;
8665+
8666+ verifyFormat("class Bar foo() {}", Style);
8667+ verifyFormat("struct Bar foo() {}", Style);
8668+ verifyFormat("union Bar foo() {}", Style);
8669+ }
8670+
86588671TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) {
86598672 // Regression test for https://bugs.llvm.org/show_bug.cgi?id=40516:
86608673 // Prefer keeping `::` followed by `operator` together.
@@ -15357,6 +15370,66 @@ TEST_F(FormatTest, NeverMergeShortRecords) {
1535715370 Style);
1535815371}
1535915372
15373+ TEST_F(FormatTest, AllowShortRecordsOnASingleLine) {
15374+ FormatStyle Style = getLLVMStyle();
15375+
15376+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
15377+ Style.BraceWrapping.AfterClass = true;
15378+ Style.BraceWrapping.AfterStruct = true;
15379+ Style.BraceWrapping.AfterUnion = true;
15380+ Style.BraceWrapping.SplitEmptyRecord = false;
15381+ Style.AllowShortRecordsOnASingleLine = FormatStyle::SRS_Never;
15382+
15383+ verifyFormat("class foo\n{\n"
15384+ " void bar();\n"
15385+ "};",
15386+ Style);
15387+ verifyFormat("class foo\n{};", Style);
15388+
15389+ verifyFormat("struct foo\n{\n"
15390+ " int bar;\n"
15391+ "};",
15392+ Style);
15393+ verifyFormat("struct foo\n{};", Style);
15394+
15395+ verifyFormat("union foo\n{\n"
15396+ " int bar;\n"
15397+ "};",
15398+ Style);
15399+ verifyFormat("union foo\n{};", Style);
15400+
15401+ Style.AllowShortRecordsOnASingleLine = FormatStyle::SRS_Empty;
15402+
15403+ verifyFormat("class foo\n{\n"
15404+ " void bar();\n"
15405+ "};",
15406+ Style);
15407+ verifyFormat("class foo {};", Style);
15408+
15409+ verifyFormat("struct foo\n{\n"
15410+ " int bar;\n"
15411+ "};",
15412+ Style);
15413+ verifyFormat("struct foo {};", Style);
15414+
15415+ verifyFormat("union foo\n{\n"
15416+ " int bar;\n"
15417+ "};",
15418+ Style);
15419+ verifyFormat("union foo {};", Style);
15420+
15421+ Style.AllowShortRecordsOnASingleLine = FormatStyle::SRS_All;
15422+
15423+ verifyFormat("class foo { void bar(); };", Style);
15424+ verifyFormat("class foo {};", Style);
15425+
15426+ verifyFormat("struct foo { int bar; };", Style);
15427+ verifyFormat("struct foo {};", Style);
15428+
15429+ verifyFormat("union foo { int bar; };", Style);
15430+ verifyFormat("union foo {};", Style);
15431+ }
15432+
1536015433TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
1536115434 // Elaborate type variable declarations.
1536215435 verifyFormat("struct foo a = {bar};\nint n;");
0 commit comments