@@ -478,6 +478,67 @@ public void ABodyThatWritesNothingRendersAsAnEmptyBlock()
478478 Assert . AreEqual ( "public virtual void Run() { }\n " , Render ( method ) ) ;
479479 }
480480
481+ [ TestMethod ]
482+ [ DataRow ( 1 ) ]
483+ [ DataRow ( 2 ) ]
484+ public void ABodyThatWritesOnlyBlankLinesRendersAsAnEmptyBlock ( int newLines )
485+ {
486+ // A NewLine after a loop over an empty collection used to leave "public void M() " with no
487+ // body, which does not compile (CS0501).
488+ MethodTemplate method = new ( )
489+ {
490+ Type = "void" ,
491+ Name = "M" ,
492+ Keywords = { "public" } ,
493+ BodyFactory = codeBlocker =>
494+ {
495+ for ( int i = 0 ; i < newLines ; i ++ )
496+ {
497+ codeBlocker . NewLine ( ) ;
498+ }
499+ } ,
500+ } ;
501+
502+ Assert . AreEqual ( "public void M() { }\n " , Render ( method ) ) ;
503+ }
504+
505+ [ TestMethod ]
506+ public void AnExpressionBodyBetweenBlankLinesStaysOnTheDeclarationLine ( ) =>
507+ Assert . AreEqual (
508+ "public void Reset() => count = 0;\n " ,
509+ Render ( new MethodTemplate
510+ {
511+ Type = "void" ,
512+ Name = "Reset" ,
513+ Keywords = { "public" } ,
514+ BodyFactory = codeBlocker =>
515+ {
516+ codeBlocker . NewLine ( ) ;
517+ codeBlocker . WriteLine ( "=> count = 0;" ) ;
518+ codeBlocker . NewLine ( ) ;
519+ } ,
520+ } ) ) ;
521+
522+ [ TestMethod ]
523+ public void ABlankLineInsideABracedBodyIsKept ( )
524+ {
525+ MethodTemplate method = new ( )
526+ {
527+ Type = "void" ,
528+ Name = "Run" ,
529+ Keywords = { "public" } ,
530+ BodyFactory = codeBlocker =>
531+ {
532+ using Scope scope = new ( codeBlocker ) ;
533+ codeBlocker . WriteLine ( "First();" ) ;
534+ codeBlocker . NewLine ( ) ;
535+ codeBlocker . WriteLine ( "Second();" ) ;
536+ } ,
537+ } ;
538+
539+ Assert . AreEqual ( "public void Run()\n {\n \t First();\n \n \t Second();\n }\n " , Render ( method ) ) ;
540+ }
541+
481542 [ TestMethod ]
482543 public void AMultiLineBodyIsIndentedToWhereItIsSpliced ( )
483544 {
@@ -568,6 +629,25 @@ public void AConstructorWithNoBaseCallIsAnEmptyBlock() =>
568629 "public Widget() { }\n " ,
569630 Render ( new ConstructorTemplate { Name = "Widget" , Keywords = { "public" } } ) ) ;
570631
632+ [ TestMethod ]
633+ [ DataRow ( 1 ) ]
634+ [ DataRow ( 2 ) ]
635+ public void AConstructorBodyThatWritesOnlyBlankLinesIsAnEmptyBlock ( int newLines ) =>
636+ Assert . AreEqual (
637+ "public Widget() { }\n " ,
638+ Render ( new ConstructorTemplate
639+ {
640+ Name = "Widget" ,
641+ Keywords = { "public" } ,
642+ BodyFactory = codeBlocker =>
643+ {
644+ for ( int i = 0 ; i < newLines ; i ++ )
645+ {
646+ codeBlocker . NewLine ( ) ;
647+ }
648+ } ,
649+ } ) ) ;
650+
571651 [ TestMethod ]
572652 public void AConstructorInitialiserIsIndentedOnItsOwnLine ( )
573653 {
0 commit comments