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()
735
735
Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
736
736
}
737
737
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
+
738
768
[ TestMethod ]
739
769
public void ShouldTranslateMultilineBlockSingleMethodArguments ( )
740
770
{
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ private static IEnumerable<string> GetBlockStatements(
69
69
{
70
70
var line = lines [ i ] ;
71
71
72
- if ( ( i > 0 ) && LeaveBlankLineBefore ( line ) )
72
+ if ( ( i > 0 ) && LeaveBlankLineBefore ( line , lines [ i - 1 ] ) )
73
73
{
74
74
yield return string . Empty ;
75
75
}
@@ -191,8 +191,13 @@ private static bool UseFullTypeName(BinaryExpression assignment)
191
191
return conditional . IfTrue . Type != conditional . IfFalse . Type ;
192
192
}
193
193
194
- private static bool LeaveBlankLineBefore ( string line )
194
+ private static bool LeaveBlankLineBefore ( string line , string previousLine = null )
195
195
{
196
+ if ( ( previousLine != null ) && LeaveBlankLineBefore ( previousLine ) )
197
+ {
198
+ return false ;
199
+ }
200
+
196
201
return line . StartsWith ( "if (" ) || line . StartsWith ( "switch " ) ;
197
202
}
198
203
You can’t perform that action at this time.
0 commit comments