Skip to content

Commit e6ecea9

Browse files
committed
Tweaked test specification.
Originally I had intended to remove any extraneous parentheses such as those that surround language expressions. Unfortunately, this proved to be more difficult than I had anticipated as it is hard to differentiate said extraneous parentheses from meaningful ones such as those used to invoke a method. It is for these reasons that I have changed the test specification to allow extraneous parentheses.
1 parent 18f018a commit e6ecea9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

TestStack.FluentMVCTesting.Tests/Internal/ExpressionInspectorTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Correctly_parse_equality_comparison_with_string_operands()
1414
Expression<Func<string, bool>> func = text => text == "any";
1515
ExpressionInspector sut = new ExpressionInspector();
1616
var actual = sut.Inspect(func);
17-
Assert.AreEqual("text => text == \"any\"", actual);
17+
Assert.AreEqual("text => (text == \"any\")", actual);
1818
}
1919

2020
[Test]
@@ -23,7 +23,7 @@ public void Correctly_parse_equality_comparison_with_int_operands()
2323
Expression<Func<int, bool>> func = number => number == 5;
2424
ExpressionInspector sut = new ExpressionInspector();
2525
var actual = sut.Inspect(func);
26-
Assert.AreEqual("number => number == 5", actual);
26+
Assert.AreEqual("number => (number == 5)", actual);
2727
}
2828

2929
[Test]
@@ -32,7 +32,7 @@ public void Correctly_parse_equality_comparison_with_property_operand()
3232
Expression<Func<PostViewModel, bool>> func = post => post.Title == "A";
3333
ExpressionInspector sut = new ExpressionInspector();
3434
var actual = sut.Inspect(func);
35-
Assert.AreEqual("post => post.Title == \"A\"", actual);
35+
Assert.AreEqual("post => (post.Title == \"A\")", actual);
3636
}
3737

3838
[Test]
@@ -41,7 +41,7 @@ public void Correctly_parse_equality_comparison_with_property_operands()
4141
Expression<Func<PostViewModel, bool>> func = post => post.Title == post.Slug;
4242
ExpressionInspector sut = new ExpressionInspector();
4343
var actual = sut.Inspect(func);
44-
Assert.AreEqual("post => post.Title == post.Slug", actual);
44+
Assert.AreEqual("post => (post.Title == post.Slug)", actual);
4545
}
4646

4747
[Test]
@@ -50,7 +50,7 @@ public void Correctly_parse_inequality_comparison()
5050
Expression<Func<int, bool>> func = number => number != 5;
5151
ExpressionInspector sut = new ExpressionInspector();
5252
var actual = sut.Inspect(func);
53-
Assert.AreEqual("number => number != 5", actual);
53+
Assert.AreEqual("number => (number != 5)", actual);
5454
}
5555

5656
[Test]
@@ -60,7 +60,8 @@ public void Correctly_parse_equality_comparison_with_captured_constant_operand()
6060
Expression<Func<int, bool>> func = number => number == Number;
6161
ExpressionInspector sut = new ExpressionInspector();
6262
var actual = sut.Inspect(func);
63-
Assert.AreEqual("number => number == " + Number, actual);
63+
Assert.AreEqual(
64+
string.Concat("number => (number == ", Number, ")"), actual);
6465
}
6566

6667
[Test]
@@ -69,7 +70,7 @@ public void Correctly_parse_relational_comparison()
6970
Expression<Func<int, bool>> func = number => number < 5;
7071
ExpressionInspector sut = new ExpressionInspector();
7172
var actual = sut.Inspect(func);
72-
Assert.AreEqual("number => number < 5", actual);
73+
Assert.AreEqual("number => (number < 5)", actual);
7374
}
7475

7576
[Test]
@@ -79,7 +80,7 @@ public void Correctly_parse_conditional_or_operator()
7980
text => text == "any" || text.Length == 3;
8081
ExpressionInspector sut = new ExpressionInspector();
8182
var actual = sut.Inspect(func);
82-
Assert.AreEqual("text => text == \"any\" || text.Length == 3", actual);
83+
Assert.AreEqual("text => ((text == \"any\") || (text.Length == 3))", actual);
8384
}
8485

8586
[Test]
@@ -89,7 +90,7 @@ public void Correctly_parse_two_conditional_or_operators()
8990
text => text == "any" || text.Length == 3 || text.Length == 9;
9091
ExpressionInspector sut = new ExpressionInspector();
9192
var actual = sut.Inspect(func);
92-
Assert.AreEqual("text => text == \"any\" || text.Length == 3 || text.Length == 9", actual);
93+
Assert.AreEqual("text => (((text == \"any\") || (text.Length == 3)) || (text.Length == 9))", actual);
9394
}
9495

9596
[Test]
@@ -99,7 +100,7 @@ public void Not_mistake_property_called_OrElse_for_conditional_or_operator()
99100
post => post.Title == "" || post.OrElse == "";
100101
ExpressionInspector sut = new ExpressionInspector();
101102
var actual = sut.Inspect(func);
102-
Assert.AreEqual("post => post.Title == \"\" || post.OrElse == \"\"", actual);
103+
Assert.AreEqual("post => ((post.Title == \"\") || (post.OrElse == \"\"))", actual);
103104
}
104105

105106
[Test]

TestStack.FluentMvcTesting/Internal/ExpressionInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal class ExpressionInspector
77
{
88
internal string Inspect(LambdaExpression expression)
99
{
10-
return Regex.Replace(expression.ToString(), "[()]", "")
10+
return expression.ToString()
1111
.Replace(" OrElse ", " || ");
1212
}
1313
}

0 commit comments

Comments
 (0)