Skip to content

Commit dba3bf4

Browse files
authored
Merge pull request #34 from codingseb/dev
Dev
2 parents ca5c6ac + 2835363 commit dba3bf4

31 files changed

+1147
-333
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,29 @@
1313
<PackageReference Include="Shouldly" Version="3.0.2" />
1414
</ItemGroup>
1515
<ItemGroup>
16+
<Compile Update="OthersTests.cs">
17+
<SubType>Code</SubType>
18+
</Compile>
1619
<Compile Update="Resources.Designer.cs">
1720
<AutoGen>True</AutoGen>
1821
<DesignTime>True</DesignTime>
1922
<DependentUpon>Resources.resx</DependentUpon>
2023
</Compile>
24+
<Compile Update="TestsUtils\ClassStructContainer.cs">
25+
<SubType>Code</SubType>
26+
</Compile>
27+
<Compile Update="TestsUtils\StructForTest3.cs">
28+
<SubType>Code</SubType>
29+
</Compile>
30+
<Compile Update="TestsUtils\StructForTest1.cs">
31+
<SubType>Code</SubType>
32+
</Compile>
33+
<Compile Update="TestsUtils\StructForTest4.cs">
34+
<SubType>Code</SubType>
35+
</Compile>
36+
<Compile Update="TestsUtils\StructForTest2.cs">
37+
<SubType>Code</SubType>
38+
</Compile>
2139
</ItemGroup>
2240
<ItemGroup>
2341
<ProjectReference Include="..\CodingSeb.ExpressionEvaluator\CodingSeb.ExpressionEvaluator.csproj" />

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,26 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
11811181
.SetCategory("return")
11821182
.Returns("The result is : 7");
11831183

1184+
yield return new TestCaseData(Resources.Script0051, null, null, null)
1185+
.SetCategory("Script")
1186+
.SetCategory("Init of ExpandoObject")
1187+
.Returns("{\"Hello\":3,\"No\":\"Yes\"}");
1188+
1189+
yield return new TestCaseData(Resources.Script0052, null, null, null)
1190+
.SetCategory("Script")
1191+
.SetCategory("Using already define vars in inits")
1192+
.SetCategory("Init of ExpandoObject")
1193+
.SetCategory("conflict variable assignation vs on the fly in object with same name")
1194+
.Returns("{\"Hello\":3,\"No\":\"Yes\"}");
1195+
1196+
yield return new TestCaseData(Resources.Script0053, null, null, null)
1197+
.SetCategory("Script")
1198+
.SetCategory("Using already define vars in inits")
1199+
.SetCategory("Anonymous type init as ExpandoObject")
1200+
.SetCategory("Init of ExpandoObject")
1201+
.SetCategory("conflict variable assignation vs on the fly in object with same name")
1202+
.Returns("{\"Hello\":3,\"No\":\"Yes\"}");
1203+
11841204
#endregion
11851205

11861206
#region Diactitics
@@ -1273,11 +1293,12 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
12731293
.Returns("[6,4,10,6,10,4]");
12741294

12751295
#endregion
1276-
1296+
12771297
#region For Bug correction (no regression)
12781298

12791299
yield return new TestCaseData(Resources.Script0049, null, null, null)
12801300
.SetCategory("Script")
1301+
.SetCategory("Conflict between generics and <> operators")
12811302
.SetCategory("variable assignation")
12821303
.SetCategory("Bug")
12831304
.SetCategory("#26")
@@ -1289,6 +1310,59 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
12891310
.SetCategory("Bug")
12901311
.Returns("{\"Hello\":3,\"No\":\"Yes\"}");
12911312

1313+
StructForTest1 structForTest1 = new StructForTest1();
1314+
ExpressionEvaluator evaluatorForStructs = new ExpressionEvaluator(
1315+
new Dictionary<string, object>
1316+
{
1317+
{ "myStruct", structForTest1 }
1318+
});
1319+
1320+
yield return new TestCaseData("return myStruct.myIntvalue;", evaluatorForStructs, null, null)
1321+
.SetCategory("Script")
1322+
.SetCategory("struct tests")
1323+
.SetCategory("Bug")
1324+
.Returns(0);
1325+
1326+
yield return new TestCaseData(Resources.Script0054, evaluatorForStructs, null, null)
1327+
.SetCategory("Script")
1328+
.SetCategory("struct tests")
1329+
.SetCategory("Bug")
1330+
.Returns("Result Test 3");
1331+
1332+
evaluatorForStructs.Variables["otherStruct"] = new StructForTest2();
1333+
1334+
yield return new TestCaseData(Resources.Script0055, evaluatorForStructs, null, null)
1335+
.SetCategory("Script")
1336+
.SetCategory("struct tests")
1337+
.SetCategory("Bug")
1338+
.Returns("Result Hey 9, 5");
1339+
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+
1352+
yield return new TestCaseData(Resources.Script0058,null, null, null)
1353+
.SetCategory("Script")
1354+
.SetCategory("struct tests")
1355+
.SetCategory("Bug")
1356+
.SetCategory("Better Than C#")
1357+
.Returns("Result Hey 9");
1358+
1359+
yield return new TestCaseData(Resources.Script0059,null, null, null)
1360+
.SetCategory("Script")
1361+
.SetCategory("struct tests")
1362+
.SetCategory("Bug")
1363+
.SetCategory("Better Than C#")
1364+
.Returns("Result Hey 9, 5");
1365+
12921366
#endregion
12931367
}
12941368
}

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,28 +1478,59 @@ public static IEnumerable<TestCaseData> TestCasesEvaluateWithSpecificEvaluator
14781478
#region Force Integer numbers default type
14791479

14801480
yield return new TestCaseData(new ExpressionEvaluator()
1481-
, "(130-120)/(2*250)")
1482-
.Returns(0)
1483-
.SetCategory("Options")
1484-
.SetCategory("Integer Numbers default types");
1481+
, "(130-120)/(2*250)")
1482+
.Returns(0)
1483+
.SetCategory("Options")
1484+
.SetCategory("Integer Numbers default types");
14851485

1486-
yield return new TestCaseData(new ExpressionEvaluator
1487-
{
1488-
OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = false
1489-
}
1490-
, "(130-120)/(2*250)")
1491-
.Returns(0)
1492-
.SetCategory("Options")
1493-
.SetCategory("Integer Numbers default types");
14941486

14951487
yield return new TestCaseData(new ExpressionEvaluator
1488+
{
1489+
OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = false
1490+
}
1491+
, "(130-120)/(2*250)")
1492+
.Returns(0)
1493+
.SetCategory("Options")
1494+
.SetCategory("Integer Numbers default types");
1495+
1496+
ExpressionEvaluator evaluatorWithIntForceToDouble = new ExpressionEvaluator
14961497
{
14971498
OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = true
1498-
}
1499-
, "(130-120)/(2*250)")
1500-
.Returns(0.02)
1501-
.SetCategory("Options")
1502-
.SetCategory("Integer Numbers default types");
1499+
};
1500+
1501+
yield return new TestCaseData(evaluatorWithIntForceToDouble
1502+
, "(130-120)/(2*250)")
1503+
.Returns(0.02)
1504+
.SetCategory("Options")
1505+
.SetCategory("Integer Numbers default types");
1506+
1507+
yield return new TestCaseData(evaluatorWithIntForceToDouble
1508+
, "Round(5.54,1)")
1509+
.Returns(5.5)
1510+
.SetCategory("Bug")
1511+
.SetCategory("Options")
1512+
.SetCategory("Integer Numbers default types");
1513+
1514+
yield return new TestCaseData(evaluatorWithIntForceToDouble
1515+
, "Round(5.54,1, MidpointRounding.ToEven)")
1516+
.Returns(5.5)
1517+
.SetCategory("Bug")
1518+
.SetCategory("Options")
1519+
.SetCategory("Integer Numbers default types");
1520+
1521+
yield return new TestCaseData(evaluatorWithIntForceToDouble
1522+
, "Round(5.54,1, MidpointRounding.AwayFromZero)")
1523+
.Returns(5.5)
1524+
.SetCategory("Bug")
1525+
.SetCategory("Options")
1526+
.SetCategory("Integer Numbers default types");
1527+
1528+
yield return new TestCaseData(evaluatorWithIntForceToDouble
1529+
, "(new string[2]).Length")
1530+
.Returns(2)
1531+
.SetCategory("Bug")
1532+
.SetCategory("Options")
1533+
.SetCategory("Integer Numbers default types");
15031534

15041535
#endregion
15051536
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using NUnit.Framework;
2+
using Shouldly;
3+
4+
namespace CodingSeb.ExpressionEvaluator.Tests
5+
{
6+
public class OthersTests
7+
{
8+
[Test]
9+
public void RealNestedStructAssignationToSeeHowItWorksScript0055()
10+
{
11+
// The real version of Script0055
12+
StructForTest2 otherStruct;
13+
14+
otherStruct.AnOtherIntValue = 5;
15+
otherStruct.nestedStruct = new StructForTest1()
16+
{
17+
myIntvalue = 8,
18+
myStringValue = "Hey"
19+
};
20+
21+
otherStruct.nestedStruct.myIntvalue = 9;
22+
23+
$"Result {otherStruct.nestedStruct.myStringValue} {otherStruct.nestedStruct.myIntvalue}, {otherStruct.AnOtherIntValue}".ShouldBe("Result Hey 9, 5");
24+
}
25+
26+
[Test]
27+
public void RealNestedStructByPropertyAssignationToSeeHowItWorks()
28+
{
29+
// Same as Script0055 with properties
30+
StructForTest4 otherStruct = new StructForTest4();
31+
32+
otherStruct.AnOtherIntValue = 5;
33+
otherStruct.NestedStruct = new StructForTest3()
34+
{
35+
MyIntvalue = 8,
36+
MyStringValue = "Hey"
37+
};
38+
39+
// Do not compile
40+
//otherStruct.NestedStruct.MyIntvalue = 9;
41+
42+
$"Result {otherStruct.NestedStruct.MyStringValue} {otherStruct.NestedStruct.MyIntvalue}, {otherStruct.AnOtherIntValue}".ShouldBe("Result Hey 8, 5");
43+
}
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+
}
97+
}
98+
}

0 commit comments

Comments
 (0)