@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
182
182
" int a; // This is unrelated" ));
183
183
EXPECT_EQ (" class C {\n "
184
184
" void f() { // This does something ..\n "
185
- " } // awesome..\n "
185
+ " } // awesome..\n "
186
186
" \n "
187
187
" int a; // This is unrelated\n "
188
188
" };" ,
@@ -3102,7 +3102,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3102
3102
StringRef Input = " namespace A {\n "
3103
3103
" TESTSUITE(B) {\n "
3104
3104
" namespace C {\n "
3105
- " namespace D {} // namespace D\n "
3105
+ " namespace D { //\n "
3106
+ " } // namespace D\n "
3106
3107
" std::string Foo = Bar; // Comment\n "
3107
3108
" std::string BazString = Baz; // C2\n "
3108
3109
" } // namespace C\n "
@@ -3114,7 +3115,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3114
3115
verifyFormat (" namespace A {\n "
3115
3116
" TESTSUITE(B) {\n "
3116
3117
" namespace C {\n "
3117
- " namespace D {} // namespace D\n "
3118
+ " namespace D { //\n "
3119
+ " } // namespace D\n "
3118
3120
" std::string Foo = Bar; // Comment\n "
3119
3121
" std::string BazString = Baz; // C2\n "
3120
3122
" } // namespace C\n "
@@ -3126,7 +3128,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3126
3128
verifyFormat (" namespace A {\n "
3127
3129
" TESTSUITE(B) {\n "
3128
3130
" namespace C {\n "
3129
- " namespace D {} // namespace D\n "
3131
+ " namespace D { //\n "
3132
+ " } // namespace D\n "
3130
3133
" std::string Foo = Bar; // Comment\n "
3131
3134
" std::string BazString = Baz; // C2\n "
3132
3135
" } // namespace C\n "
@@ -3138,7 +3141,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3138
3141
verifyFormat (" namespace A {\n "
3139
3142
" TESTSUITE(B) {\n "
3140
3143
" namespace C {\n "
3141
- " namespace D {} // namespace D\n "
3144
+ " namespace D { //\n "
3145
+ " } // namespace D\n "
3142
3146
" std::string Foo = Bar; // Comment\n "
3143
3147
" std::string BazString = Baz; // C2\n "
3144
3148
" } // namespace C\n "
@@ -3151,7 +3155,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3151
3155
verifyFormat (" namespace A {\n "
3152
3156
" TESTSUITE(B) {\n "
3153
3157
" namespace C {\n "
3154
- " namespace D {} // namespace D\n "
3158
+ " namespace D { //\n "
3159
+ " } // namespace D\n "
3155
3160
" std::string Foo = Bar; // Comment\n "
3156
3161
" std::string BazString = Baz; // C2\n "
3157
3162
" } // namespace C\n "
@@ -3163,7 +3168,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3163
3168
verifyFormat (" namespace A {\n "
3164
3169
" TESTSUITE(B) {\n "
3165
3170
" namespace C {\n "
3166
- " namespace D {} // namespace D\n "
3171
+ " namespace D { //\n "
3172
+ " } // namespace D\n "
3167
3173
" std::string Foo = Bar; // Comment\n "
3168
3174
" std::string BazString = Baz; // C2\n "
3169
3175
" } // namespace C\n "
@@ -3175,7 +3181,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3175
3181
verifyFormat (" namespace A {\n "
3176
3182
" TESTSUITE(B) {\n "
3177
3183
" namespace C {\n "
3178
- " namespace D {} // namespace D\n "
3184
+ " namespace D { //\n "
3185
+ " } // namespace D\n "
3179
3186
" std::string Foo = Bar; // Comment\n "
3180
3187
" std::string BazString = Baz; // C2\n "
3181
3188
" } // namespace C\n "
@@ -3191,20 +3198,167 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
3191
3198
" }\n "
3192
3199
" // Comment" ;
3193
3200
3194
- #if 0
3195
- // FIXME: The following comment is aligned with the namespace comment.
3196
3201
verifyFormat (" namespace A {\n "
3197
3202
" int Foo;\n "
3198
3203
" int Bar;\n "
3199
3204
" } // namespace A\n "
3200
- " // Comment",
3205
+ " // Comment" ,
3201
3206
Input, Style );
3202
- #endif
3203
3207
3204
3208
Style .FixNamespaceComments = false ;
3205
3209
verifyFormat (Input, Style );
3206
3210
}
3207
3211
3212
+ TEST_F (FormatTestComments, DontAlignOverScope) {
3213
+ verifyFormat (" if (foo) {\n "
3214
+ " int aLongVariable; // with comment\n "
3215
+ " int f; // aligned\n "
3216
+ " } // not aligned\n "
3217
+ " int bar; // new align\n "
3218
+ " int foobar; // group" );
3219
+
3220
+ verifyFormat (" if (foo) {\n "
3221
+ " // something\n "
3222
+ " } else {\n "
3223
+ " int aLongVariable; // with comment\n "
3224
+ " int f; // aligned\n "
3225
+ " } // not aligned\n "
3226
+ " int bar; // new align\n "
3227
+ " int foobar; // group" );
3228
+
3229
+ verifyFormat (" if (foo) {\n "
3230
+ " // something\n "
3231
+ " } else if (foo) {\n "
3232
+ " int aLongVariable; // with comment\n "
3233
+ " int f; // aligned\n "
3234
+ " } // not aligned\n "
3235
+ " int bar; // new align\n "
3236
+ " int foobar; // group" );
3237
+
3238
+ verifyFormat (" while (foo) {\n "
3239
+ " int aLongVariable; // with comment\n "
3240
+ " int f; // aligned\n "
3241
+ " } // not aligned\n "
3242
+ " int bar; // new align\n "
3243
+ " int foobar; // group" );
3244
+
3245
+ verifyFormat (" for (;;) {\n "
3246
+ " int aLongVariable; // with comment\n "
3247
+ " int f; // aligned\n "
3248
+ " } // not aligned\n "
3249
+ " int bar; // new align\n "
3250
+ " int foobar; // group" );
3251
+
3252
+ verifyFormat (" do {\n "
3253
+ " int aLongVariable; // with comment\n "
3254
+ " int f; // aligned\n "
3255
+ " } while (foo); // not aligned\n "
3256
+ " int bar; // new align\n "
3257
+ " int foobar; // group" );
3258
+
3259
+ verifyFormat (" do\n "
3260
+ " int aLongVariable; // with comment\n "
3261
+ " while (foo); // not aigned\n "
3262
+ " int bar; // new align\n "
3263
+ " int foobar; // group" );
3264
+
3265
+ verifyFormat (" do\n "
3266
+ " int aLongVariable; // with comment\n "
3267
+ " /**/ while (foo); // not aigned\n "
3268
+ " int bar; // new align\n "
3269
+ " int foobar; // group" );
3270
+
3271
+ verifyFormat (" switch (foo) {\n "
3272
+ " case 7: {\n "
3273
+ " int aLongVariable; // with comment\n "
3274
+ " int f; // aligned\n "
3275
+ " } // case not aligned\n "
3276
+ " } // switch also not aligned\n "
3277
+ " int bar; // new align\n "
3278
+ " int foobar; // group" );
3279
+
3280
+ verifyFormat (" switch (foo) {\n "
3281
+ " default: {\n "
3282
+ " int aLongVariable; // with comment\n "
3283
+ " int f; // aligned\n "
3284
+ " } // case not aligned\n "
3285
+ " } // switch also not aligned\n "
3286
+ " int bar; // new align\n "
3287
+ " int foobar; // group" );
3288
+
3289
+ verifyFormat (" class C {\n "
3290
+ " int aLongVariable; // with comment\n "
3291
+ " int f; // aligned\n "
3292
+ " }; // not aligned\n "
3293
+ " int bar; // new align\n "
3294
+ " int foobar; // group" );
3295
+
3296
+ verifyFormat (" struct S {\n "
3297
+ " int aLongVariable; // with comment\n "
3298
+ " int f; // aligned\n "
3299
+ " }; // not aligned\n "
3300
+ " int bar; // new align\n "
3301
+ " int foobar; // group" );
3302
+
3303
+ verifyFormat (" union U {\n "
3304
+ " int aLongVariable; // with comment\n "
3305
+ " int f; // aligned\n "
3306
+ " }; // not aligned\n "
3307
+ " int bar; // new align\n "
3308
+ " int foobar; // group" );
3309
+
3310
+ verifyFormat (" enum E {\n "
3311
+ " aLongVariable, // with comment\n "
3312
+ " f // aligned\n "
3313
+ " }; // not aligned\n "
3314
+ " int bar; // new align\n "
3315
+ " int foobar; // group" );
3316
+
3317
+ verifyFormat (" void foo() {\n "
3318
+ " {\n "
3319
+ " int aLongVariable; // with comment\n "
3320
+ " int f; // aligned\n "
3321
+ " } // not aligned\n "
3322
+ " int bar; // new align\n "
3323
+ " int foobar; // group\n "
3324
+ " }" );
3325
+
3326
+ verifyFormat (" auto longLambda = [] { // comment\n "
3327
+ " int aLongVariable; // with comment\n "
3328
+ " int f; // aligned\n "
3329
+ " }; // not aligned\n "
3330
+ " int bar; // new align\n "
3331
+ " int foobar; // group\n "
3332
+ " auto shortLambda = [] { return 5; }; // aligned" );
3333
+
3334
+ verifyFormat (" auto longLambdaResult = [] { // comment\n "
3335
+ " int aLongVariable; // with comment\n "
3336
+ " int f; // aligned\n "
3337
+ " }(); // not aligned\n "
3338
+ " int bar; // new align\n "
3339
+ " int foobar; // group\n "
3340
+ " auto shortLambda = [] { return 5; }(); // aligned" );
3341
+
3342
+ verifyFormat (
3343
+ " auto longLambdaResult = [](auto I, auto J) { // comment\n "
3344
+ " int aLongVariable; // with comment\n "
3345
+ " int f; // aligned\n "
3346
+ " }(\" Input\" , 5); // not aligned\n "
3347
+ " int bar; // new align\n "
3348
+ " int foobar; // group\n "
3349
+ " auto shortL = [](auto I, auto J) { return 5; }(\" In\" , 5); // aligned" );
3350
+
3351
+ verifyFormat (" enum E1 { V1, V2 }; // Aligned\n "
3352
+ " enum E2 { LongerNames, InThis, Enum }; // Comments" );
3353
+
3354
+ verifyFormat (" class C {\n "
3355
+ " int aLongVariable; // with comment\n "
3356
+ " int f; // aligned\n "
3357
+ " } /* middle comment */; // not aligned\n "
3358
+ " int bar; // new align\n "
3359
+ " int foobar; // group" );
3360
+ }
3361
+
3208
3362
TEST_F (FormatTestComments, AlignsBlockCommentDecorations) {
3209
3363
EXPECT_EQ (" /*\n "
3210
3364
" */" ,
0 commit comments