File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
ReadableExpressions.UnitTests
ReadableExpressions/Translators Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -735,6 +735,36 @@ public void ShouldLeaveABlankLineBeforeAnIfStatement()
735735 Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
736736 }
737737
738+ [ TestMethod ]
739+ public void ShouldNotLeaveDoubleBlankLinesBetweenIfStatements ( )
740+ {
741+ var intVariable = Expression . Variable ( typeof ( int ) , "i" ) ;
742+ var one = Expression . Constant ( 1 ) ;
743+ var intVariableEqualsOne = Expression . Equal ( intVariable , one ) ;
744+ var doNothing = Expression . Default ( typeof ( void ) ) ;
745+ var ifIntEqualsOneDoNothing = Expression . IfThen ( intVariableEqualsOne , doNothing ) ;
746+
747+ var block = Expression . Block (
748+ new [ ] { intVariable } ,
749+ ifIntEqualsOneDoNothing ,
750+ ifIntEqualsOneDoNothing ) ;
751+
752+ const string EXPECTED = @"
753+ int i;
754+
755+ if (i == 1)
756+ {
757+ }
758+
759+ if (i == 1)
760+ {
761+ }" ;
762+
763+ var translated = block . ToReadableString ( ) ;
764+
765+ Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
766+ }
767+
738768 [ TestMethod ]
739769 public void ShouldTranslateMultilineBlockSingleMethodArguments ( )
740770 {
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ private static IEnumerable<string> GetBlockStatements(
6969 {
7070 var line = lines [ i ] ;
7171
72- if ( ( i > 0 ) && LeaveBlankLineBefore ( line ) )
72+ if ( ( i > 0 ) && LeaveBlankLineBefore ( line , lines [ i - 1 ] ) )
7373 {
7474 yield return string . Empty ;
7575 }
@@ -191,8 +191,13 @@ private static bool UseFullTypeName(BinaryExpression assignment)
191191 return conditional . IfTrue . Type != conditional . IfFalse . Type ;
192192 }
193193
194- private static bool LeaveBlankLineBefore ( string line )
194+ private static bool LeaveBlankLineBefore ( string line , string previousLine = null )
195195 {
196+ if ( ( previousLine != null ) && LeaveBlankLineBefore ( previousLine ) )
197+ {
198+ return false ;
199+ }
200+
196201 return line . StartsWith ( "if (" ) || line . StartsWith ( "switch " ) ;
197202 }
198203
You can’t perform that action at this time.
0 commit comments