@@ -465,13 +465,13 @@ TEST_F(CleanUpReplacementsTest, InsertMultipleIncludesGoogleStyle) {
465
465
466
466
TEST_F (CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortLLVM) {
467
467
std::string Code = " \n int x;" ;
468
- std::string Expected = " #include \" fix.h\"\n "
468
+ std::string Expected = " \n #include \" fix.h\"\n "
469
469
" #include \" a.h\"\n "
470
470
" #include \" b.h\"\n "
471
471
" #include \" c.h\"\n "
472
472
" #include <list>\n "
473
473
" #include <vector>\n "
474
- " \n int x;" ;
474
+ " int x;" ;
475
475
tooling::Replacements Replaces = {createInsertion (" #include \" a.h\" " ),
476
476
createInsertion (" #include \" c.h\" " ),
477
477
createInsertion (" #include \" b.h\" " ),
@@ -483,13 +483,13 @@ TEST_F(CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortLLVM) {
483
483
484
484
TEST_F (CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortGoogle) {
485
485
std::string Code = " \n int x;" ;
486
- std::string Expected = " #include \" fix.h\"\n "
486
+ std::string Expected = " \n #include \" fix.h\"\n "
487
487
" #include <list>\n "
488
488
" #include <vector>\n "
489
489
" #include \" a.h\"\n "
490
490
" #include \" b.h\"\n "
491
491
" #include \" c.h\"\n "
492
- " \n int x;" ;
492
+ " int x;" ;
493
493
tooling::Replacements Replaces = {createInsertion (" #include \" a.h\" " ),
494
494
createInsertion (" #include \" c.h\" " ),
495
495
createInsertion (" #include \" b.h\" " ),
@@ -502,21 +502,22 @@ TEST_F(CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortGoogle) {
502
502
503
503
TEST_F (CleanUpReplacementsTest, FormatCorrectLineWhenHeadersAreInserted) {
504
504
std::string Code = " \n "
505
+ " int x;\n "
505
506
" int a;\n "
506
507
" int a;\n "
507
508
" int a;" ;
508
509
509
- std::string Expected = " #include \" x.h\"\n "
510
+ std::string Expected = " \n #include \" x.h\"\n "
510
511
" #include \" y.h\"\n "
511
512
" #include \" clang/x/x.h\"\n "
512
513
" #include <list>\n "
513
514
" #include <vector>\n "
514
- " \n "
515
+ " int x; \n "
515
516
" int a;\n "
516
517
" int b;\n "
517
518
" int a;" ;
518
519
tooling::Replacements Replaces = {
519
- createReplacement (getOffset (Code, 3 , 8 ), 1 , " b" ),
520
+ createReplacement (getOffset (Code, 4 , 8 ), 1 , " b" ),
520
521
createInsertion (" #include <vector>" ),
521
522
createInsertion (" #include <list>" ),
522
523
createInsertion (" #include \" clang/x/x.h\" " ),
@@ -537,6 +538,76 @@ TEST_F(CleanUpReplacementsTest, NotConfusedByDefine) {
537
538
EXPECT_EQ (Expected, formatAndApply (Code, Replaces));
538
539
}
539
540
541
+ TEST_F (CleanUpReplacementsTest, SkippedTopComment) {
542
+ std::string Code = " // comment\n "
543
+ " \n "
544
+ " // comment\n " ;
545
+ std::string Expected = " // comment\n "
546
+ " \n "
547
+ " // comment\n "
548
+ " #include <vector>\n " ;
549
+ tooling::Replacements Replaces = {createInsertion (" #include <vector>" )};
550
+ EXPECT_EQ (Expected, apply (Code, Replaces));
551
+ }
552
+
553
+ TEST_F (CleanUpReplacementsTest, SkippedMixedComments) {
554
+ std::string Code = " // comment\n "
555
+ " // comment \\\n "
556
+ " comment continued\n "
557
+ " /*\n "
558
+ " * comment\n "
559
+ " */\n " ;
560
+ std::string Expected = " // comment\n "
561
+ " // comment \\\n "
562
+ " comment continued\n "
563
+ " /*\n "
564
+ " * comment\n "
565
+ " */\n "
566
+ " #include <vector>\n " ;
567
+ tooling::Replacements Replaces = {createInsertion (" #include <vector>" )};
568
+ EXPECT_EQ (Expected, apply (Code, Replaces));
569
+ }
570
+
571
+ TEST_F (CleanUpReplacementsTest, MultipleBlockCommentsInOneLine) {
572
+ std::string Code = " /*\n "
573
+ " * comment\n "
574
+ " */ /* comment\n "
575
+ " */\n "
576
+ " \n\n "
577
+ " /* c1 */ /*c2 */\n " ;
578
+ std::string Expected = " /*\n "
579
+ " * comment\n "
580
+ " */ /* comment\n "
581
+ " */\n "
582
+ " \n\n "
583
+ " /* c1 */ /*c2 */\n "
584
+ " #include <vector>\n " ;
585
+ tooling::Replacements Replaces = {createInsertion (" #include <vector>" )};
586
+ EXPECT_EQ (Expected, apply (Code, Replaces));
587
+ }
588
+
589
+ TEST_F (CleanUpReplacementsTest, CodeAfterComments) {
590
+ std::string Code = " /*\n "
591
+ " * comment\n "
592
+ " */ /* comment\n "
593
+ " */\n "
594
+ " \n\n "
595
+ " /* c1 */ /*c2 */\n "
596
+ " \n "
597
+ " int x;\n " ;
598
+ std::string Expected = " /*\n "
599
+ " * comment\n "
600
+ " */ /* comment\n "
601
+ " */\n "
602
+ " \n\n "
603
+ " /* c1 */ /*c2 */\n "
604
+ " \n "
605
+ " #include <vector>\n "
606
+ " int x;\n " ;
607
+ tooling::Replacements Replaces = {createInsertion (" #include <vector>" )};
608
+ EXPECT_EQ (Expected, apply (Code, Replaces));
609
+ }
610
+
540
611
} // end namespace
541
612
} // end namespace format
542
613
} // end namespace clang
0 commit comments