File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
ReadableExpressions.UnitTests
ReadableExpressions/Translators/Formatting Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,27 @@ public void ShouldTranslateAMultipleLineIfStatement()
9595 Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
9696 }
9797
98+ [ TestMethod ]
99+ public void ShouldTranslateAMultipleClauseIfStatement ( )
100+ {
101+ var intVariable = Expression . Variable ( typeof ( int ) , "i" ) ;
102+ var one = Expression . Constant ( 1 ) ;
103+ var intVariableLessThanOne = Expression . LessThan ( intVariable , one ) ;
104+ var intVariableMoreThanOne = Expression . GreaterThan ( intVariable , one ) ;
105+ var intVariableInRange = Expression . AndAlso ( intVariableLessThanOne , intVariableMoreThanOne ) ;
106+ Expression < Action > writeHello = ( ) => Console . WriteLine ( "Hello" ) ;
107+ var ifLessThanOneThenWrite = Expression . IfThen ( intVariableInRange , writeHello . Body ) ;
108+
109+ var translated = ifLessThanOneThenWrite . ToReadableString ( ) ;
110+
111+ const string EXPECTED = @"
112+ if ((i < 1) && (i > 1))
113+ {
114+ Console.WriteLine(""Hello"");
115+ }" ;
116+ Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
117+ }
118+
98119 [ TestMethod ]
99120 public void ShouldTranslateAMultipleLineIfStatementTest ( )
100121 {
Original file line number Diff line number Diff line change @@ -23,11 +23,17 @@ public FormattedCondition(
2323 test = test . Indented ( ) . TrimStart ( ) ;
2424 }
2525
26- _singleLineTest = test . WithSurroundingParentheses ( checkExisting : true ) ;
26+ _singleLineTest = test . WithSurroundingParentheses ( CheckExistingParentheses ( ) ) ;
2727
2828 MultipleLineTranslationFactory = GetMultipleLineTranslation ;
2929 }
3030
31+ private bool CheckExistingParentheses ( )
32+ {
33+ // ReSharper disable once UnusedVariable
34+ return IsNotRelevantBinary ( _condition , out BinaryExpression binary ) ;
35+ }
36+
3137 protected override Func < string > SingleLineTranslationFactory => ( ) => _singleLineTest ;
3238
3339 protected override Func < string > MultipleLineTranslationFactory { get ; }
You can’t perform that action at this time.
0 commit comments