================
@@ -3007,6 +3007,130 @@ TEST_F(FormatTestComments,
AlignTrailingCommentsAcrossEmptyLines) {
Style);
}
+TEST_F(FormatTestComments, NonTrailingCommentBreaksAlignment) {
+ // Regression test for https://llvm.org/PR208266
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto);
+ Style.AlignConsecutiveAssignments.Enabled = true;
+ Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
+ Style.AlignTrailingComments.OverEmptyLines = 4;
+ Style.ColumnLimit = 0;
+
+ verifyNoChange("enum E {\n"
+ " A = 0; /* e */\n"
+ "}\n"
+ "/* c */\n"
+ "message M {\n"
+ " int32 a = 1; /* f */\n"
+ " int32 abcd = 2; /* g */\n"
+ "}",
+ Style);
+
+ Style = getLLVMStyle();
+ Style.AlignConsecutiveAssignments.Enabled = true;
+ Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
+ Style.AlignTrailingComments.OverEmptyLines = 4;
+ Style.ColumnLimit = 0;
+
+ verifyNoChange("void f() {\n"
+ " int a = 0; /* e */\n"
+ "}\n"
+ "/* c */\n"
+ "void g() {\n"
+ " int b = 1; /* f */\n"
+ " int abcd = 2; /* g */\n"
+ "}",
+ Style);
+
+ // OverEmptyLines should not align trailing comments across block boundaries
+ // even without an intervening comment separator.
+ verifyNoChange("void f() {\n"
+ " int a = 0; /* e */\n"
+ "}\n"
+ "void g() {\n"
+ " int b = 1; /* f */\n"
+ " int abcd = 2; /* g */\n"
+ "}",
+ Style);
+
+ // A trailing comment on a declaration between two blocks is its own group.
+ verifyNoChange("struct A {\n"
+ " int a = 0; /* e */\n"
+ "};\n"
+ "int i; /* comment */\n"
+ "struct M {\n"
+ " int b = 1; /* f */\n"
+ " int abcd = 2; /* g */\n"
+ "};",
+ Style);
+
+ // Scope-based alignment with trailing comments on }; lines and gaps.
+ verifyNoChange("struct A {\n"
+ " int a = 0; /* a */\n"
+ " int b = 0;\n"
+ " int c = 0; /* c */\n"
+ "}; /* end\n"
+ " A */\n"
+ "int i; /* comment */\n"
+ "int j;\n"
+ "int k; /* k */\n"
+ "struct M {\n"
+ " int d = 1; /* d */\n"
+ " int abcd = 2; /* abcd */\n"
+ " int e = 1;\n"
+ "}; /* end M */",
+ Style);
+
+ // OverEmptyLines should not align trailing comments across ); boundaries.
+ verifyNoChange("x = (5, // comm 5\n"
+ " 10, // comm 4\n"
+ " 15 // comm 3\n"
+ ");\n"
+ "y = (longvalue, // comm a\n"
+ " othervalue, // comm b\n"
+ " third // comm c\n"
+ ");",
+ Style);
+
+ // A trailing comment on a ); line aligns with its block, then breaks.
+ verifyNoChange("auto a = Foo(\n"
+ " x, // param 1\n"
+ " y, // param 2\n"
+ " z // param 3\n"
+ "); // end Foo\n"
+ "auto b = Bar(\n"
+ " longname, // param 1\n"
+ " othername, // param 2\n"
+ " third // param 3\n"
+ ");",
+ Style);
+
+ // Within a single expression, ), on its own line also breaks alignment.
+ verifyNoChange("result = (Foo(\n"
+ " x, // param 1\n"
+ " y, // param 2\n"
+ " z // param 3\n"
+ " ),\n"
+ " Bar(\n"
+ " longname, // param 1\n"
+ " othername, // param 2\n"
+ " third // param 3\n"
+ " ));",
+ Style);
+
+ // Trailing comments on ), and )); lines align with their respective blocks.
+ verifyNoChange("result = (Foo(\n"
+ " x, // param 1\n"
+ " y, // param 2\n"
+ " z // param 3\n"
+ " ), // end Foo\n"
+ " Bar(\n"
+ " longname, // param 1\n"
+ " othername, // param 2\n"
+ " third // param 3\n"
+ " )); // end Bar",
+ Style);
----------------
owenca wrote:
Delete
https://github.com/llvm/llvm-project/pull/208324
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits