@@ -28315,9 +28315,11 @@ TEST_F(FormatTest, KeepFormFeed) {
28315
28315
}
28316
28316
28317
28317
TEST_F(FormatTest, ShortNamespacesOption) {
28318
- FormatStyle Style = getLLVMStyle();
28319
- Style.AllowShortNamespacesOnASingleLine = true;
28320
- Style.FixNamespaceComments = false;
28318
+ auto BaseStyle = getLLVMStyle();
28319
+ BaseStyle.AllowShortNamespacesOnASingleLine = true;
28320
+ BaseStyle.FixNamespaceComments = false;
28321
+
28322
+ auto Style = BaseStyle;
28321
28323
28322
28324
// Basic functionality.
28323
28325
verifyFormat("namespace foo { class bar; }", Style);
@@ -28335,7 +28337,7 @@ TEST_F(FormatTest, ShortNamespacesOption) {
28335
28337
"}",
28336
28338
Style);
28337
28339
28338
- // Make sure code doesn't walk to far on unbalanced code.
28340
+ // Make sure code doesn't walk too far on unbalanced code.
28339
28341
verifyFormat("namespace foo {", Style);
28340
28342
verifyFormat("namespace foo {\n"
28341
28343
"class baz;",
@@ -28348,7 +28350,7 @@ TEST_F(FormatTest, ShortNamespacesOption) {
28348
28350
verifyFormat("namespace foo { namespace bar { class baz; } }", Style);
28349
28351
verifyFormat("namespace foo {\n"
28350
28352
"namespace bar { class baz; }\n"
28351
- "namespace quar { class quaz ; }\n"
28353
+ "namespace qux { class quux ; }\n"
28352
28354
"}",
28353
28355
Style);
28354
28356
@@ -28390,20 +28392,32 @@ TEST_F(FormatTest, ShortNamespacesOption) {
28390
28392
// No ColumnLimit, allows long nested one-liners, but also leaves multi-line
28391
28393
// instances alone.
28392
28394
Style.ColumnLimit = 0;
28393
- verifyFormat("namespace foo { namespace bar { namespace baz { namespace qux "
28394
- " { class quux; } } } }",
28395
- Style);
28395
+ verifyFormat(
28396
+ "namespace foo { namespace bar { namespace baz { class qux; } } }",
28397
+ Style);
28396
28398
28397
28399
verifyNoChange("namespace foo {\n"
28398
- "namespace bar {\n"
28399
- "namespace baz { namespace qux { class quux; } }\n"
28400
- "}\n"
28400
+ "namespace bar { namespace baz { class qux; } }\n"
28401
28401
"}",
28402
28402
Style);
28403
28403
28404
+ Style = BaseStyle;
28405
+ Style.CompactNamespaces = true;
28406
+ verifyFormat("namespace foo { namespace bar { class baz; } }", Style);
28407
+
28408
+ // If we can't merge an outer nested namespaces, but can merge an inner
28409
+ // nested namespace, then CompactNamespaces will merge the outer namespace
28410
+ // first, preventing the merging of the inner namespace
28411
+ verifyFormat("namespace foo { namespace baz {\n"
28412
+ "class qux;\n"
28413
+ "} // comment\n"
28414
+ "}",
28415
+ Style);
28416
+
28404
28417
// This option doesn't really work with FixNamespaceComments and nested
28405
28418
// namespaces. Code should use the concatenated namespace syntax. e.g.
28406
28419
// 'namespace foo::bar'.
28420
+ Style = BaseStyle;
28407
28421
Style.FixNamespaceComments = true;
28408
28422
28409
28423
verifyFormat(
0 commit comments