@@ -8632,6 +8632,19 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
86328632 Style);
86338633}
86348634
8635+ TEST_F(FormatTest, BreakFunctionsReturningRecords) {
8636+ FormatStyle Style = getLLVMStyle();
8637+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
8638+ Style.BraceWrapping.AfterFunction = true;
8639+ Style.BraceWrapping.AfterClass = false;
8640+ Style.BraceWrapping.AfterStruct = false;
8641+ Style.BraceWrapping.AfterUnion = false;
8642+
8643+ verifyFormat("class Bar foo() {}", Style);
8644+ verifyFormat("struct Bar foo() {}", Style);
8645+ verifyFormat("union Bar foo() {}", Style);
8646+ }
8647+
86358648TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) {
86368649 // Regression test for https://bugs.llvm.org/show_bug.cgi?id=40516:
86378650 // Prefer keeping `::` followed by `operator` together.
@@ -15334,6 +15347,66 @@ TEST_F(FormatTest, NeverMergeShortRecords) {
1533415347 Style);
1533515348}
1533615349
15350+ TEST_F(FormatTest, AllowShortRecordsOnASingleLine) {
15351+ FormatStyle Style = getLLVMStyle();
15352+
15353+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
15354+ Style.BraceWrapping.AfterClass = true;
15355+ Style.BraceWrapping.AfterStruct = true;
15356+ Style.BraceWrapping.AfterUnion = true;
15357+ Style.BraceWrapping.SplitEmptyRecord = false;
15358+ Style.AllowShortRecordsOnASingleLine = FormatStyle::SRS_Never;
15359+
15360+ verifyFormat("class foo\n{\n"
15361+ " void bar();\n"
15362+ "};",
15363+ Style);
15364+ verifyFormat("class foo\n{};", Style);
15365+
15366+ verifyFormat("struct foo\n{\n"
15367+ " int bar;\n"
15368+ "};",
15369+ Style);
15370+ verifyFormat("struct foo\n{};", Style);
15371+
15372+ verifyFormat("union foo\n{\n"
15373+ " int bar;\n"
15374+ "};",
15375+ Style);
15376+ verifyFormat("union foo\n{};", Style);
15377+
15378+ Style.AllowShortRecordsOnASingleLine = FormatStyle::SRS_Empty;
15379+
15380+ verifyFormat("class foo\n{\n"
15381+ " void bar();\n"
15382+ "};",
15383+ Style);
15384+ verifyFormat("class foo {};", Style);
15385+
15386+ verifyFormat("struct foo\n{\n"
15387+ " int bar;\n"
15388+ "};",
15389+ Style);
15390+ verifyFormat("struct foo {};", Style);
15391+
15392+ verifyFormat("union foo\n{\n"
15393+ " int bar;\n"
15394+ "};",
15395+ Style);
15396+ verifyFormat("union foo {};", Style);
15397+
15398+ Style.AllowShortRecordsOnASingleLine = FormatStyle::SRS_All;
15399+
15400+ verifyFormat("class foo { void bar(); };", Style);
15401+ verifyFormat("class foo {};", Style);
15402+
15403+ verifyFormat("struct foo { int bar; };", Style);
15404+ verifyFormat("struct foo {};", Style);
15405+
15406+ verifyFormat("union foo { int bar; };", Style);
15407+ verifyFormat("union foo {};", Style);
15408+ }
15409+
1533715410TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
1533815411 // Elaborate type variable declarations.
1533915412 verifyFormat("struct foo a = {bar};\nint n;");
0 commit comments