@@ -8632,6 +8632,19 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
8632
8632
Style);
8633
8633
}
8634
8634
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
+
8635
8648
TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) {
8636
8649
// Regression test for https://bugs.llvm.org/show_bug.cgi?id=40516:
8637
8650
// Prefer keeping `::` followed by `operator` together.
@@ -15334,6 +15347,66 @@ TEST_F(FormatTest, NeverMergeShortRecords) {
15334
15347
Style);
15335
15348
}
15336
15349
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
+
15337
15410
TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
15338
15411
// Elaborate type variable declarations.
15339
15412
verifyFormat("struct foo a = {bar};\nint n;");
0 commit comments