Skip to content

Commit 1bfb9a3

Browse files
committed
Support for parsing logical operators.
1 parent e5a2530 commit 1bfb9a3

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

TestStack.FluentMVCTesting.Tests/Internal/ExpressionInspectorTests.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ public void Correctly_parse_conditional_or_operator()
8383
Assert.AreEqual("text => ((text == \"any\") || (text.Length == 3))", actual);
8484
}
8585

86+
[Test]
87+
public void Correctly_parse_two_conditional_or_operators()
88+
{
89+
Expression<Func<string, bool>> func =
90+
text => text == "any" || text.Length == 3 || text.Length == 9;
91+
ExpressionInspector sut = new ExpressionInspector();
92+
var actual = sut.Inspect(func);
93+
Assert.AreEqual("text => (((text == \"any\") || (text.Length == 3)) || (text.Length == 9))", actual);
94+
}
95+
8696

8797
[Test]
8898
public void Correctly_parse_conditional_and_operator()
@@ -95,15 +105,27 @@ public void Correctly_parse_conditional_and_operator()
95105
}
96106

97107
[Test]
98-
public void Correctly_parse_two_conditional_or_operators()
108+
public void Correctly_parse_logical_and_operator()
99109
{
100110
Expression<Func<string, bool>> func =
101-
text => text == "any" || text.Length == 3 || text.Length == 9;
111+
text => text == "any" & text.Length == 3;
102112
ExpressionInspector sut = new ExpressionInspector();
103113
var actual = sut.Inspect(func);
104-
Assert.AreEqual("text => (((text == \"any\") || (text.Length == 3)) || (text.Length == 9))", actual);
114+
Assert.AreEqual("text => ((text == \"any\") & (text.Length == 3))", actual);
105115
}
106116

117+
118+
[Test]
119+
public void Correctly_parse_logical_or_operator()
120+
{
121+
Expression<Func<string, bool>> func =
122+
text => text == "any" | text.Length == 3;
123+
ExpressionInspector sut = new ExpressionInspector();
124+
var actual = sut.Inspect(func);
125+
Assert.AreEqual("text => ((text == \"any\") | (text.Length == 3))", actual);
126+
}
127+
128+
107129
[Test]
108130
public void Not_mistake_property_called_OrElse_for_conditional_or_operator()
109131
{

TestStack.FluentMvcTesting/Internal/ExpressionInspector.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ internal string Inspect(LambdaExpression expression)
99
{
1010
return expression.ToString()
1111
.Replace(" OrElse ", " || ")
12-
.Replace(" AndAlso ", " && ");
12+
.Replace(" AndAlso ", " && ")
13+
.Replace(" Or ", " | ")
14+
.Replace(" And ", " & ");
15+
1316
}
1417
}
1518
}

0 commit comments

Comments
 (0)