Skip to content

Commit 5aaa472

Browse files
author
Sébastien Geiser
committed
Other struct and class imbrications tests bug when property in struct found
1 parent 19ce94d commit 5aaa472

File tree

8 files changed

+163
-5
lines changed

8 files changed

+163
-5
lines changed

CodingSeb.ExpressionEvaluator.Tests/CodingSeb.ExpressionEvaluator.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<DesignTime>True</DesignTime>
2222
<DependentUpon>Resources.resx</DependentUpon>
2323
</Compile>
24+
<Compile Update="TestsUtils\ClassStructContainer.cs">
25+
<SubType>Code</SubType>
26+
</Compile>
2427
<Compile Update="TestsUtils\StructForTest3.cs">
2528
<SubType>Code</SubType>
2629
</Compile>

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,18 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
13371337
.SetCategory("Bug")
13381338
.Returns("Result Hey 9, 5");
13391339

1340+
yield return new TestCaseData(Resources.Script0056,null, null, null)
1341+
.SetCategory("Script")
1342+
.SetCategory("struct tests")
1343+
.SetCategory("Bug")
1344+
.Returns("Result Hey 9");
1345+
1346+
yield return new TestCaseData(Resources.Script0057,null, null, null)
1347+
.SetCategory("Script")
1348+
.SetCategory("struct tests")
1349+
.SetCategory("Bug")
1350+
.Returns("Result Hey 9");
1351+
13401352
#endregion
13411353
}
13421354
}

CodingSeb.ExpressionEvaluator.Tests/OthersTests.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void RealNestedStructAssignationToSeeHowItWorksScript0055()
2626
[Test]
2727
public void RealNestedStructByPropertyAssignationToSeeHowItWorks()
2828
{
29-
// Same sa Script0055 with properties
29+
// Same as Script0055 with properties
3030
StructForTest4 otherStruct = new StructForTest4();
3131

3232
otherStruct.AnOtherIntValue = 5;
@@ -41,5 +41,58 @@ public void RealNestedStructByPropertyAssignationToSeeHowItWorks()
4141

4242
$"Result {otherStruct.NestedStruct.MyStringValue} {otherStruct.NestedStruct.MyIntvalue}, {otherStruct.AnOtherIntValue}".ShouldBe("Result Hey 8, 5");
4343
}
44+
45+
[Test]
46+
public void RealNestedStructInClassAssignationToSeeHowItWorksScript0056()
47+
{
48+
// The real version of Script0056
49+
ClassStructContainer classStructContainer = new ClassStructContainer()
50+
{
51+
nestedStructField = new StructForTest1()
52+
{
53+
myIntvalue = 8,
54+
myStringValue = "Hey"
55+
}
56+
};
57+
58+
classStructContainer.nestedStructField.myIntvalue = 9;
59+
60+
$"Result {classStructContainer.nestedStructField.myStringValue} {classStructContainer.nestedStructField.myIntvalue}".ShouldBe("Result Hey 9");
61+
}
62+
63+
[Test]
64+
public void RealNestedStructInClassPropertyAssignationToSeeHowItWorks()
65+
{
66+
ClassStructContainer classStructContainer = new ClassStructContainer()
67+
{
68+
NestedStructProperty = new StructForTest1()
69+
{
70+
myIntvalue = 8,
71+
myStringValue = "Hey"
72+
}
73+
};
74+
75+
// Do not compile
76+
//classStructContainer.NestedStructProperty.myIntvalue = 9;
77+
78+
$"Result {classStructContainer.NestedStructProperty.myStringValue} {classStructContainer.NestedStructProperty.myIntvalue}".ShouldBe("Result Hey 8");
79+
}
80+
81+
[Test]
82+
public void RealNestedStructPropertyInClassAttributeAssignationToSeeHowItWorksScript0057()
83+
{
84+
ClassStructContainer classStructContainer = new ClassStructContainer()
85+
{
86+
nestedStructField2 = new StructForTest3()
87+
{
88+
MyIntvalue = 8,
89+
MyStringValue = "Hey"
90+
}
91+
};
92+
93+
classStructContainer.nestedStructField2.MyIntvalue = 9;
94+
95+
$"Result {classStructContainer.nestedStructField2.MyStringValue} {classStructContainer.nestedStructField2.MyIntvalue}".ShouldBe("Result Hey 9");
96+
}
4497
}
4598
}

CodingSeb.ExpressionEvaluator.Tests/Resources.Designer.cs

Lines changed: 51 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingSeb.ExpressionEvaluator.Tests/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,10 @@
283283
<data name="Script0055" type="System.Resources.ResXFileRef, System.Windows.Forms">
284284
<value>resources\script0055.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
285285
</data>
286+
<data name="Script0056" type="System.Resources.ResXFileRef, System.Windows.Forms">
287+
<value>resources\script0056.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
288+
</data>
289+
<data name="Script0057" type="System.Resources.ResXFileRef, System.Windows.Forms">
290+
<value>resources\script0057.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
291+
</data>
286292
</root>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Script0056 */
2+
classStructContainer = new ClassStructContainer()
3+
{
4+
nestedStructField = new StructForTest1()
5+
{
6+
myIntvalue = 8,
7+
myStringValue = "Hey"
8+
}
9+
};
10+
11+
classStructContainer.nestedStructField.myIntvalue = 9;
12+
13+
return $"Result {classStructContainer.nestedStructField.myStringValue} {classStructContainer.nestedStructField.myIntvalue}";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Script0057 */
2+
classStructContainer = new ClassStructContainer()
3+
{
4+
nestedStructField2 = new StructForTest3()
5+
{
6+
MyIntvalue = 8,
7+
MyStringValue = "Hey"
8+
}
9+
};
10+
11+
classStructContainer.nestedStructField2.MyIntvalue = 9;
12+
13+
return $"Result {classStructContainer.nestedStructField2.MyStringValue} {classStructContainer.nestedStructField2.MyIntvalue}";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace CodingSeb.ExpressionEvaluator.Tests
2+
{
3+
public class ClassStructContainer
4+
{
5+
public StructForTest1 nestedStructField;
6+
public StructForTest3 nestedStructField2;
7+
8+
public StructForTest1 NestedStructProperty { get; set; }
9+
}
10+
}
11+

0 commit comments

Comments
 (0)