PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Workspaces/CSharpTest/Formatting/FormattingTriviaTests.cs

https://github.com/EkardNT/Roslyn
C# | 1704 lines | 1511 code | 187 blank | 6 comment | 0 complexity | c38b649b5cfc1549e291447a0a080756 MD5 | raw file
   1using Microsoft.CodeAnalysis.Test.Utilities;
   2using Roslyn.Test.Utilities;
   3using Xunit;
   4
   5namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Formatting
   6{
   7    public class FormattingEngineTriviaTests : CSharpFormattingTestBase
   8    {
   9        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
  10        public void PreprocessorInEmptyFile()
  11        {
  12            var content = @"
  13                    
  14            #line 1000
  15        #error
  16                        ";
  17
  18            var expected = @"
  19
  20#line 1000
  21#error
  22";
  23
  24            AssertFormat(expected, content);
  25        }
  26
  27        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
  28        public void Comment1()
  29        {
  30            var content = @"             // single line comment
  31            class C {           }";
  32
  33            var expected = @"// single line comment
  34class C { }";
  35
  36            AssertFormat(expected, content);
  37        }
  38
  39        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
  40        public void Comment2()
  41        {
  42            var content = @"class C 
  43{
  44                // single line comment
  45    int i;
  46}";
  47
  48            var expected = @"class C
  49{
  50    // single line comment
  51    int i;
  52}";
  53
  54            AssertFormat(expected, content);
  55        }
  56
  57        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
  58        public void Comment3()
  59        {
  60            var content = @"class C 
  61{
  62                // single line comment
  63}";
  64
  65            var expected = @"class C
  66{
  67    // single line comment
  68}";
  69
  70            AssertFormat(expected, content);
  71        }
  72
  73        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
  74        public void Comment4()
  75        {
  76            var content = @"class C 
  77{
  78                // single line comment
  79//  single line comment 2
  80    void Method() { }
  81}";
  82
  83            var expected = @"class C
  84{
  85    // single line comment
  86    //  single line comment 2
  87    void Method() { }
  88}";
  89
  90            AssertFormat(expected, content);
  91        }
  92
  93        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
  94        public void Comment5()
  95        {
  96            var content = @"class C 
  97{
  98    void Method() { 
  99    // single line comment
 100    //  single line comment 2
 101}
 102}";
 103
 104            var expected = @"class C
 105{
 106    void Method()
 107    {
 108        // single line comment
 109        //  single line comment 2
 110    }
 111}";
 112
 113            AssertFormat(expected, content);
 114        }
 115
 116        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 117        public void Comment6()
 118        {
 119            var content = @"class C 
 120{
 121    void Method() { 
 122    // single line comment
 123    //  single line comment 2
 124        int i = 10;
 125}
 126}";
 127
 128            var expected = @"class C
 129{
 130    void Method()
 131    {
 132        // single line comment
 133        //  single line comment 2
 134        int i = 10;
 135    }
 136}";
 137
 138            AssertFormat(expected, content);
 139        }
 140
 141        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 142        public void Comment7()
 143        {
 144            var content = @"class C 
 145{
 146    void Method() { 
 147    // single line comment
 148
 149        int i = 10;
 150
 151    //  single line comment 2
 152}
 153}";
 154
 155            var expected = @"class C
 156{
 157    void Method()
 158    {
 159        // single line comment
 160
 161        int i = 10;
 162
 163        //  single line comment 2
 164    }
 165}";
 166
 167            AssertFormat(expected, content);
 168        }
 169
 170        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 171        public void Comment8()
 172        {
 173            var content = @"class C 
 174{
 175    void Method() { 
 176        /* multiline comment */
 177
 178        int i = 10;
 179}
 180}";
 181
 182            var expected = @"class C
 183{
 184    void Method()
 185    {
 186        /* multiline comment */
 187
 188        int i = 10;
 189    }
 190}";
 191
 192            AssertFormat(expected, content);
 193        }
 194
 195        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 196        public void Comment9()
 197        {
 198            var content = @"class C 
 199{
 200    void Method() { 
 201        /* multiline comment */
 202
 203        int i = 10;
 204}
 205}";
 206
 207            var expected = @"class C
 208{
 209    void Method()
 210    {
 211        /* multiline comment */
 212
 213        int i = 10;
 214    }
 215}";
 216
 217            AssertFormat(expected, content);
 218        }
 219
 220        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 221        public void Comment10()
 222        {
 223            var content = @"class C 
 224{
 225    void Method() { 
 226        /* multiline comment */
 227
 228        int i = 10;
 229/* multiline comment */
 230}
 231}";
 232
 233            var expected = @"class C
 234{
 235    void Method()
 236    {
 237        /* multiline comment */
 238
 239        int i = 10;
 240        /* multiline comment */
 241    }
 242}";
 243
 244            AssertFormat(expected, content);
 245        }
 246
 247        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 248        public void Comment11()
 249        {
 250            var content = @"class C 
 251{
 252    void Method() { 
 253                    /* 
 254                     * multiline comment 
 255                     */
 256
 257        int i = 10;
 258
 259/* 
 260 * multiline comment 
 261 */
 262}
 263}";
 264
 265            var expected = @"class C
 266{
 267    void Method()
 268    {
 269        /* 
 270         * multiline comment 
 271         */
 272
 273        int i = 10;
 274
 275        /* 
 276         * multiline comment 
 277         */
 278    }
 279}";
 280
 281            AssertFormat(expected, content);
 282        }
 283
 284        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 285        public void Comment12()
 286        {
 287            var content = @"class C 
 288{
 289    void Method() { 
 290                                                        /* 
 291                     * multiline comment 
 292                     */
 293
 294        int i = 10;
 295
 296                            /* 
 297             * multiline comment 
 298             */
 299}
 300}";
 301
 302            var expected = @"class C
 303{
 304    void Method()
 305    {
 306        /* 
 307* multiline comment 
 308*/
 309
 310        int i = 10;
 311
 312        /* 
 313* multiline comment 
 314*/
 315    }
 316}";
 317
 318            AssertFormat(expected, content);
 319        }
 320
 321        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 322        public void Comment13()
 323        {
 324            var content = @"class C 
 325{
 326    void Method() { // test
 327        int i = 10;
 328}
 329}";
 330
 331            var expected = @"class C
 332{
 333    void Method()
 334    { // test
 335        int i = 10;
 336    }
 337}";
 338
 339            AssertFormat(expected, content);
 340        }
 341
 342        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 343        public void Comment14()
 344        {
 345            var content = @"class C 
 346{
 347    void Method() { // test
 348                    // test 2
 349                    // test 3
 350        int i = 10;
 351}
 352}";
 353
 354            var expected = @"class C
 355{
 356    void Method()
 357    { // test
 358      // test 2
 359      // test 3
 360        int i = 10;
 361    }
 362}";
 363
 364            AssertFormat(expected, content);
 365        }
 366
 367        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 368        public void Comment15()
 369        {
 370            var content = @"class C 
 371{
 372    void Method() { /* test */
 373        int i = 10;
 374}
 375}";
 376
 377            var expected = @"class C
 378{
 379    void Method()
 380    { /* test */
 381        int i = 10;
 382    }
 383}";
 384
 385            AssertFormat(expected, content);
 386        }
 387
 388        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 389        public void Comment16()
 390        {
 391            var content = @"class C 
 392{
 393    void Method() { /* test 
 394                     *      
 395                     */         
 396        int i = 10;
 397}
 398}";
 399
 400            var expected = @"class C
 401{
 402    void Method()
 403    { /* test 
 404                     *      
 405                     */
 406        int i = 10;
 407    }
 408}";
 409
 410            AssertFormat(expected, content);
 411        }
 412
 413        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 414        public void Comment17()
 415        {
 416            var content = @"class C 
 417{
 418    void Method() { 
 419                    /* test 
 420                     *      
 421                     */         // test
 422        int i = 10;
 423}
 424}";
 425
 426            var expected = @"class C
 427{
 428    void Method()
 429    {
 430        /* test 
 431         *      
 432         */         // test
 433        int i = 10;
 434    }
 435}";
 436
 437            AssertFormat(expected, content, true);
 438        }
 439
 440        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 441        public void Comment18()
 442        {
 443            var content = @"class C 
 444{
 445    void Method() { 
 446                    /* test 
 447                     *      
 448                     */         // test     
 449                                // test 2       
 450        int i = 10;
 451}
 452}";
 453
 454            var expected = @"class C
 455{
 456    void Method()
 457    {
 458        /* test 
 459         *      
 460         */         // test     
 461                    // test 2       
 462        int i = 10;
 463    }
 464}";
 465
 466            AssertFormat(expected, content);
 467        }
 468
 469        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 470        public void Comment19()
 471        {
 472            var content = @"class C 
 473{
 474    void Method() { 
 475                    /* test 
 476                     *      
 477                     */         /* test 2
 478                                 *
 479                                 */
 480        int i = 10;
 481}
 482}";
 483
 484            var expected = @"class C
 485{
 486    void Method()
 487    {
 488        /* test 
 489         *      
 490         */         /* test 2
 491                     *
 492                     */
 493        int i = 10;
 494    }
 495}";
 496
 497            AssertFormat(expected, content);
 498        }
 499
 500        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 501        public void Comment20()
 502        {
 503            var content = @"class C 
 504{
 505    void Method() { 
 506        int i = 10;
 507                    /* test 
 508                     *      
 509                     */         /* test 2
 510                                 *
 511                                 */
 512}
 513}";
 514
 515            var expected = @"class C
 516{
 517    void Method()
 518    {
 519        int i = 10;
 520        /* test 
 521         *      
 522         */         /* test 2
 523                     *
 524                     */
 525    }
 526}";
 527
 528            AssertFormat(expected, content);
 529        }
 530
 531        // for now, formatting engine doesn't re-indent token if the indentation line contains noisy
 532        // chars
 533        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 534        public void Comment21()
 535        {
 536            var content = @"class C 
 537{
 538    void Method() { 
 539                            /* */ int i = 10;
 540}
 541}";
 542
 543            var expected = @"class C
 544{
 545    void Method()
 546    {
 547        /* */
 548        int i = 10;
 549    }
 550}";
 551
 552            AssertFormat(expected, content);
 553        }
 554
 555        // for now, formatting engine doesn't re-indent token if the indentation line contains noisy
 556        // chars
 557        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 558        public void Comment22()
 559        {
 560            var content = @"class C 
 561{
 562    void Method() { 
 563                            int i = 
 564                                /* */ 10;
 565}
 566}";
 567
 568            var expected = @"class C
 569{
 570    void Method()
 571    {
 572        int i =
 573            /* */ 10;
 574    }
 575}";
 576
 577            AssertFormat(expected, content);
 578        }
 579
 580        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 581        public void Comment23()
 582        {
 583            var content = @"class C 
 584{
 585    void Method() { 
 586                            int /* */ i             = /* */         10;
 587}
 588}";
 589
 590            var expected = @"class C
 591{
 592    void Method()
 593    {
 594        int /* */ i = /* */         10;
 595    }
 596}";
 597
 598            AssertFormat(expected, content);
 599        }
 600
 601        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 602        public void Comment24()
 603        {
 604            var content = @"class C 
 605{
 606    void Method() {     
 607        /*
 608         */   int i             =          10;
 609}
 610}";
 611
 612            var expected = @"class C
 613{
 614    void Method()
 615    {
 616        /*
 617         */
 618        int i = 10;
 619    }
 620}";
 621
 622            AssertFormat(expected, content);
 623        }
 624
 625        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 626        public void DocComment1()
 627        {
 628            var content = @"class C 
 629{
 630    void Method() {     
 631                                /**
 632                                 */   
 633                int i             =          10;
 634}
 635}";
 636
 637            var expected = @"class C
 638{
 639    void Method()
 640    {
 641        /**
 642         */
 643        int i = 10;
 644    }
 645}";
 646
 647            AssertFormat(expected, content);
 648        }
 649
 650        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 651        public void DocComment2()
 652        {
 653            var content = @"class C 
 654{
 655    void Method() {     /**
 656                         */   
 657                int i             =          10;
 658}
 659}";
 660
 661            var expected = @"class C
 662{
 663    void Method()
 664    {     /**
 665                         */
 666        int i = 10;
 667    }
 668}";
 669
 670            AssertFormat(expected, content);
 671        }
 672
 673        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 674        public void DocComment3()
 675        {
 676            var content = @"class C 
 677{
 678    void Method() {     
 679                int i             =          10;
 680                        /**
 681                         */
 682}
 683}";
 684
 685            var expected = @"class C
 686{
 687    void Method()
 688    {
 689        int i = 10;
 690        /**
 691         */
 692    }
 693}";
 694
 695            AssertFormat(expected, content);
 696        }
 697
 698        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 699        public void DocComment4()
 700        {
 701            var content = @"class C 
 702{
 703    void Method() {     
 704                int i             =          10; /**                
 705                         */
 706}
 707}";
 708
 709            var expected = @"class C
 710{
 711    void Method()
 712    {
 713        int i = 10; /**                
 714                         */
 715    }
 716}";
 717
 718            AssertFormat(expected, content);
 719        }
 720
 721        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 722        public void DocComment5()
 723        {
 724            var content = @"class C 
 725{
 726    void Method() {     
 727                int i             =          10; /** */
 728}
 729}";
 730
 731            var expected = @"class C
 732{
 733    void Method()
 734    {
 735        int i = 10; /** */
 736    }
 737}";
 738
 739            AssertFormat(expected, content);
 740        }
 741
 742        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 743        public void DocComment6()
 744        {
 745            var content = @"class C 
 746{
 747    void Method() {     
 748                int i /** */            =     
 749                    /** */ 10; 
 750}
 751}";
 752
 753            var expected = @"class C
 754{
 755    void Method()
 756    {
 757        int i /** */            =
 758            /** */ 10;
 759    }
 760}";
 761
 762            AssertFormat(expected, content);
 763        }
 764
 765        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 766        public void DocComment7()
 767        {
 768            var content = @"class C 
 769{
 770    void Method() {     ///
 771                        ///
 772                int i = 10; 
 773}
 774}";
 775
 776            var expected = @"class C
 777{
 778    void Method()
 779    {     ///
 780          ///
 781        int i = 10;
 782    }
 783}";
 784
 785            AssertFormat(expected, content);
 786        }
 787
 788        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 789        public void DocComment8()
 790        {
 791            var content = @"class C 
 792{
 793    void Method() {     
 794                        ///
 795                        ///
 796                int i = 10; 
 797}
 798}";
 799
 800            var expected = @"class C
 801{
 802    void Method()
 803    {
 804        ///
 805        ///
 806        int i = 10;
 807    }
 808}";
 809
 810            AssertFormat(expected, content);
 811        }
 812
 813        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 814        public void DocComment9()
 815        {
 816            var content = @"class C 
 817{
 818    void Method() {     
 819                int i = 10; 
 820///
 821                        ///
 822}
 823}";
 824
 825            var expected = @"class C
 826{
 827    void Method()
 828    {
 829        int i = 10;
 830        ///
 831        ///
 832    }
 833}";
 834
 835            AssertFormat(expected, content);
 836        }
 837
 838        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 839        public void DocComment10()
 840        {
 841            var content = @"class C 
 842{
 843    void Method() {     
 844///
 845/**
 846 */ ///
 847    ///
 848                int i = 10; 
 849}
 850}";
 851
 852            var expected = @"class C
 853{
 854    void Method()
 855    {
 856        ///
 857        /**
 858         */ ///
 859            ///
 860        int i = 10;
 861    }
 862}";
 863
 864            AssertFormat(expected, content);
 865        }
 866
 867        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 868        public void DocComment11()
 869        {
 870            var content = @"class C 
 871{
 872    void Method() {     
 873///
 874/**
 875 */ /**
 876      *
 877      */
 878                int i = 10; 
 879}
 880}";
 881
 882            var expected = @"class C
 883{
 884    void Method()
 885    {
 886        ///
 887        /**
 888         */ /**
 889              *
 890              */
 891        int i = 10;
 892    }
 893}";
 894
 895            AssertFormat(expected, content);
 896        }
 897
 898        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 899        public void DocComment12()
 900        {
 901            var content = @"class C 
 902{
 903    void Method() {     
 904///
 905/**
 906 */ /** */
 907                int i = 10; 
 908}
 909}";
 910
 911            var expected = @"class C
 912{
 913    void Method()
 914    {
 915        ///
 916        /**
 917         */ /** */
 918        int i = 10;
 919    }
 920}";
 921
 922            AssertFormat(expected, content);
 923        }
 924
 925        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 926        public void MixCommentAndDocComment1()
 927        {
 928            var content = @"class C 
 929{
 930    void Method() {     
 931//
 932/**
 933 */ /*          
 934     */ //
 935                int i = 10; 
 936}
 937}";
 938
 939            var expected = @"class C
 940{
 941    void Method()
 942    {
 943        //
 944        /**
 945         */ /*          
 946             */ //
 947        int i = 10;
 948    }
 949}";
 950
 951            AssertFormat(expected, content);
 952        }
 953
 954        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 955        public void MixCommentAndDocComment2()
 956        {
 957            var content = @"class C 
 958{
 959    void Method() {     
 960/*
 961 *
 962 */ /**          
 963     *
 964     */ /*
 965 *
 966 */ ///
 967    ///
 968                int i = 10; 
 969}
 970}";
 971
 972            var expected = @"class C
 973{
 974    void Method()
 975    {
 976        /*
 977         *
 978         */ /**          
 979             *
 980             */ /*
 981         *
 982         */ ///
 983            ///
 984        int i = 10;
 985    }
 986}";
 987
 988            AssertFormat(expected, content);
 989        }
 990
 991        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
 992        public void MixCommentAndDocComment3()
 993        {
 994            var content = @"class C 
 995{
 996    void Method() {     
 997            // test
 998            // test 2
 999
1000            /// <text></text>
1001            /// test 3
1002            ///
1003
1004int i = 10; 
1005}
1006}";
1007
1008            var expected = @"class C
1009{
1010    void Method()
1011    {
1012        // test
1013        // test 2
1014
1015        /// <text></text>
1016        /// test 3
1017        ///
1018
1019        int i = 10;
1020    }
1021}";
1022
1023            AssertFormat(expected, content);
1024        }
1025
1026        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1027        public void MixCommentAndDocComment4()
1028        {
1029            var content = @"class C 
1030{
1031            /// <text></text>
1032            /// test 3
1033            ///
1034void Method() {     
1035            // test
1036            // test 2
1037
1038int i = 10; 
1039}
1040}";
1041
1042            var expected = @"class C
1043{
1044    /// <text></text>
1045    /// test 3
1046    ///
1047    void Method()
1048    {
1049        // test
1050        // test 2
1051
1052        int i = 10;
1053    }
1054}";
1055
1056            AssertFormat(expected, content);
1057        }
1058
1059        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1060        public void Preprocessor1()
1061        {
1062            var content = @"class C 
1063{
1064                    #if true
1065                    #endif
1066void Method() {     
1067int i = 10; 
1068}
1069}";
1070
1071            var expected = @"class C
1072{
1073#if true
1074#endif
1075    void Method()
1076    {
1077        int i = 10;
1078    }
1079}";
1080
1081            AssertFormat(expected, content);
1082        }
1083
1084        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1085        public void Preprocessor2()
1086        {
1087            var content = @"class C 
1088{
1089                    #if true
1090void Method() {     
1091int i = 10; 
1092}
1093}
1094    #endif
1095";
1096
1097            var expected = @"class C
1098{
1099#if true
1100    void Method()
1101    {
1102        int i = 10;
1103    }
1104}
1105#endif
1106";
1107
1108            AssertFormat(expected, content);
1109        }
1110
1111        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1112        public void Preprocessor3()
1113        {
1114            var content = @"class C 
1115{
1116                    #if true
1117void Method() {     
1118                #elif false
1119int i = 10; 
1120}
1121}
1122    #endif
1123}
1124}";
1125
1126            var expected = @"class C
1127{
1128#if true
1129    void Method()
1130    {
1131#elif false
1132int i = 10; 
1133}
1134}
1135#endif
1136    }
1137}";
1138
1139            AssertFormat(expected, content);
1140        }
1141
1142        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1143        public void Preprocessor4()
1144        {
1145            var content = @"class C 
1146{
1147                    #if true
1148void Method() {     
1149}
1150                #elif false
1151int i = 10; 
1152}
1153    #endif
1154}
1155";
1156
1157            var expected = @"class C
1158{
1159#if true
1160    void Method()
1161    {
1162    }
1163#elif false
1164int i = 10; 
1165}
1166#endif
1167}
1168";
1169
1170            // turn off transformation check - conditional directive preprocessor
1171            AssertFormat(expected, content);
1172        }
1173
1174        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1175        public void Preprocessor5()
1176        {
1177            var content = @"class C 
1178{
1179                    #region Test
1180        int i = 10;
1181                    #endregion
1182
1183void Method() {     
1184}
1185}
1186";
1187
1188            var expected = @"class C
1189{
1190    #region Test
1191    int i = 10;
1192    #endregion
1193
1194    void Method()
1195    {
1196    }
1197}
1198";
1199
1200            AssertFormat(expected, content);
1201        }
1202
1203        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1204        public void Preprocessor6()
1205        {
1206            var content = @"class C 
1207{
1208                    #region Test
1209        int i = 10;
1210                    #endregion
1211
1212void Method() {     
1213}
1214}
1215";
1216
1217            var expected = @"class C
1218{
1219    #region Test
1220    int i = 10;
1221    #endregion
1222
1223    void Method()
1224    {
1225    }
1226}
1227";
1228
1229            AssertFormat(expected, content);
1230        }
1231
1232        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1233        public void Preprocessor7()
1234        {
1235            var content = @"class C 
1236{
1237                    #region Test
1238        int i = 10;
1239                    
1240void Method() {     
1241}
1242#endregion
1243}
1244";
1245
1246            var expected = @"class C
1247{
1248    #region Test
1249    int i = 10;
1250
1251    void Method()
1252    {
1253    }
1254    #endregion
1255}
1256";
1257
1258            AssertFormat(expected, content);
1259        }
1260
1261        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1262        public void Preprocessor8()
1263        {
1264            var content = @"class C 
1265{
1266                    #region Test
1267        int i = 10;
1268                    
1269void Method() {     
1270#endregion
1271int i = 10;
1272}
1273}
1274";
1275
1276            var expected = @"class C
1277{
1278    #region Test
1279    int i = 10;
1280
1281    void Method()
1282    {
1283        #endregion
1284        int i = 10;
1285    }
1286}
1287";
1288
1289            AssertFormat(expected, content);
1290        }
1291
1292        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1293        public void MixAll()
1294        {
1295            var content = @"class C 
1296{
1297                    #region Test
1298
1299            #if true
1300
1301                        // test
1302                ///
1303                ///
1304        int i = 10;
1305
1306            #else                    
1307void Method() {     
1308}
1309    #endif
1310#endregion
1311}
1312";
1313
1314            var expected = @"class C
1315{
1316    #region Test
1317
1318#if true
1319
1320    // test
1321    ///
1322    ///
1323    int i = 10;
1324
1325#else
1326void Method() {     
1327}
1328#endif
1329    #endregion
1330}
1331";
1332
1333            // turn off transformation check since it doesn't work for conditional directive yet.
1334            AssertFormat(expected, content);
1335        }
1336
1337        [WorkItem(537895, "DevDiv")]
1338        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1339        public void Preprocessor9()
1340        {
1341            var content = @"class C 
1342{
1343void Method() {     
1344#region Myregion
1345            int a;
1346            if (true)
1347                a++;
1348            #endregion 
1349}
1350}
1351";
1352
1353            var expected = @"class C
1354{
1355    void Method()
1356    {
1357        #region Myregion
1358        int a;
1359        if (true)
1360            a++;
1361        #endregion
1362    }
1363}
1364";
1365
1366            AssertFormat(expected, content);
1367        }
1368
1369        [WorkItem(537895, "DevDiv")]
1370        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1371        public void Preprocessor10()
1372        {
1373            var content = @"class C 
1374{
1375void Method() {     
1376            int a;
1377            if (true)
1378                a++;
1379#region Myregion
1380}
1381}
1382";
1383
1384            var expected = @"class C
1385{
1386    void Method()
1387    {
1388        int a;
1389        if (true)
1390            a++;
1391        #region Myregion
1392    }
1393}
1394";
1395
1396            AssertFormat(expected, content);
1397        }
1398
1399        [WorkItem(537765, "DevDiv")]
1400        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1401        public void Comment25()
1402        {
1403            var content = @"class C 
1404{
1405            void Foo()//method
1406{
1407    int x;//variable
1408double y;
1409                    }
1410}
1411";
1412
1413            var expected = @"class C
1414{
1415    void Foo()//method
1416    {
1417        int x;//variable
1418        double y;
1419    }
1420}
1421";
1422
1423            AssertFormat(expected, content);
1424        }
1425
1426        [WorkItem(537765, "DevDiv")]
1427        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1428        public void Comment26()
1429        {
1430            var content = @"public class Class1
1431{
1432    void Foo()
1433    {
1434/**/int x;
1435    }
1436}";
1437
1438            var expected = @"public class Class1
1439{
1440    void Foo()
1441    {
1442        /**/
1443        int x;
1444    }
1445}";
1446
1447            AssertFormat(expected, content);
1448        }
1449
1450        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1451        public void Comment27()
1452        {
1453            var content = @"public class Class1
1454{
1455    void Foo()
1456    {
1457        //      
1458        // 
1459    }
1460}";
1461
1462            AssertFormat(content, content);
1463        }
1464
1465        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1466        public void Comment28()
1467        {
1468            var content = @"public class Class1
1469{
1470    void Foo()
1471    {
1472        //      
1473            
1474        // 
1475            
1476    }
1477}";
1478
1479            var expected = @"public class Class1
1480{
1481    void Foo()
1482    {
1483        //      
1484
1485        // 
1486
1487    }
1488}";
1489            AssertFormat(expected, content);
1490        }
1491
1492        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1493        public void Comment29()
1494        {
1495            var content = @"public class Class1
1496{
1497    void Foo()
1498    {
1499        int			/**/ i = 10;
1500    }
1501}";
1502
1503            var code = @"public class Class1
1504{
1505    void Foo()
1506    {
1507        int         /**/ i = 10;
1508    }
1509}";
1510
1511            AssertFormat(code, content);
1512        }
1513
1514        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1515        public void Comment30()
1516        {
1517            var content = @"
1518// Test";
1519
1520            var code = @"
1521// Test";
1522
1523            AssertFormat(code, content);
1524        }
1525
1526        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1527        public void Comment31()
1528        {
1529            var content = @"/// <summary>
1530///
1531        /// </summary>
1532class Program
1533{
1534    static void Main(string[] args)
1535    {
1536    }
1537}
1538";
1539
1540            var code = @"/// <summary>
1541///
1542/// </summary>
1543class Program
1544{
1545    static void Main(string[] args)
1546    {
1547    }
1548}
1549";
1550
1551            AssertFormat(code, content);
1552        }
1553
1554        [WorkItem(538703, "DevDiv")]
1555        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1556        public void Comment32()
1557        {
1558            var content = @"class Program
1559{
1560    ///<summary>
1561        ///     TestMethod
1562///</summary>
1563    void Method() { }
1564}
1565";
1566
1567            var code = @"class Program
1568{
1569    ///<summary>
1570    ///     TestMethod
1571    ///</summary>
1572    void Method() { }
1573}
1574";
1575
1576            AssertFormat(code, content);
1577        }
1578
1579        [WorkItem(542316, "DevDiv")]
1580        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1581        public void CommentInExpression()
1582        {
1583            var content = @"using System;
1584using System.Collections.Generic;
1585using System.Linq;
1586
1587class Program
1588{
1589    static void Main(string[] args)
1590    {
1591        CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1592                            // (10,30): error CS0455: Type parameter 'X' inherits conflicting constraints 'B' and 'A'
1593            Diagnostic(ErrorCode.ERR_BaseConstraintConflict, ""X"").WithArguments(""X"", ""B"", ""A"").WithLocation(10, 30));
1594    }
1595}
1596";
1597
1598            var code = @"using System;
1599using System.Collections.Generic;
1600using System.Linq;
1601
1602class Program
1603{
1604    static void Main(string[] args)
1605    {
1606        CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1607            // (10,30): error CS0455: Type parameter 'X' inherits conflicting constraints 'B' and 'A'
1608            Diagnostic(ErrorCode.ERR_BaseConstraintConflict, ""X"").WithArguments(""X"", ""B"", ""A"").WithLocation(10, 30));
1609    }
1610}
1611";
1612
1613            AssertFormat(code, content);
1614        }
1615
1616        [WorkItem(542546, "DevDiv")]
1617        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1618        public void FormatInvalidCode_1()
1619        {
1620            var content = @">	Roslyn.Utilities.dll! 	Basic";
1621            AssertFormat(content, content);
1622        }
1623
1624        [WorkItem(542546, "DevDiv")]
1625        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1626        public void FormatInvalidCode_2()
1627        {
1628            var content = @">	Roslyn.Utilities.dll! Line 43 + 0x5 bytes	Basic";
1629            var expectedContent = @">	Roslyn.Utilities.dll! Line 43 + 0x5 bytes Basic";
1630            AssertFormat(expectedContent, content);
1631        }
1632
1633        [WorkItem(537895, "DevDiv")]
1634        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1635        public void EmbededStatement1()
1636        {
1637            var content = @"using System;
1638using System.Collections.Generic;
1639using System.Linq;
1640
1641class Program
1642{
1643    static void Main(string[] args)
1644    {
1645        #region Myregion
1646        int a;
1647        if (true)
1648            a++;
1649            #endregion
1650    }
1651}";
1652            var expectedContent = @"using System;
1653using System.Collections.Generic;
1654using System.Linq;
1655
1656class Program
1657{
1658    static void Main(string[] args)
1659    {
1660        #region Myregion
1661        int a;
1662        if (true)
1663            a++;
1664        #endregion
1665    }
1666}";
1667            AssertFormat(expectedContent, content);
1668        }
1669
1670        [Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
1671        public void RefKeywords()
1672        {
1673            var content = @"class C 
1674{
1675    static void Main(string[] args)
1676    {
1677        int i = 1;
1678        TypedReference tr = __makeref(   i );
1679        Type t = __reftype( tr 
1680            );
1681        int j = __refvalue(            tr  ,
1682            int
1683            );
1684    }
1685}";
1686
1687            var expected = @"class C
1688{
1689    static void Main(string[] args)
1690    {
1691        int i = 1;
1692        TypedReference tr = __makeref(i);
1693        Type t = __reftype(tr
1694            );
1695        int j = __refvalue(tr,
1696            int
1697            );
1698    }
1699}";
1700
1701            AssertFormat(expected, content);
1702        }
1703    }
1704}