================ @@ -3191,20 +3198,150 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) { "}\n" "// Comment"; -#if 0 - // FIXME: The following comment is aligned with the namespace comment. verifyFormat("namespace A {\n" " int Foo;\n" " int Bar;\n" "} // namespace A\n" - " // Comment", + "// Comment", Input, Style); -#endif Style.FixNamespaceComments = false; verifyFormat(Input, Style); } +TEST_F(FormatTestComments, DontAlignOverScope) { + verifyFormat("if (foo) {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("if (foo) {\n" + " // something\n" + "} else {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("if (foo) {\n" + " // something\n" + "} else if (foo) {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("while (foo) {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("for (;;) {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("do {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} while (foo); // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("do\n" + " int aLongVariable; // with comment\n" + "while (foo); // not aigned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("do\n" + " int aLongVariable; // with comment\n" + "/**/ while (foo); // not aigned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("switch (foo) {\n" + "case 7: {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // case not aligned\n" + "} // switch also not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("switch (foo) {\n" + "default: {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "} // case not aligned\n" + "} // switch also not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("class C {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "}; // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("struct S {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "}; // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("union U {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "}; // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("enum E {\n" + " aLongVariable, // with comment\n" + " f // aligned\n" + "}; // not aligned\n" + "int bar; // new align\n" + "int foobar; // group"); + + verifyFormat("void foo() {\n" + " {\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + " } // not aligned\n" + " int bar; // new align\n" + " int foobar; // group\n" + "}"); + + verifyFormat("auto longLambda = [] { // comment\n" + " int aLongVariable; // with comment\n" + " int f; // aligned\n" + "}; // not aligned\n" + "int bar; // new align\n" + "int foobar; // group\n" + "auto shortLambda = [] { return 5; }; // aligned"); ---------------- owenca wrote:
FWIW, maybe another test case that ends with `}(); // not aligned`? https://github.com/llvm/llvm-project/pull/68743 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits