Skip to content

Commit be88848

Browse files
authored
Merge pull request #13 from codingseb/dev
For version 1.2.2.0 - ExpandoObjects - Try catch finally - throw - code with diactitics
2 parents ee5c1a5 + f993e28 commit be88848

24 files changed

+1016
-85
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="TestsUtils\ClassForTest1.cs" />
5656
<Compile Include="TestsUtils\ClassForTest2.cs" />
5757
<Compile Include="TestsUtils\ClassInOtherNameSpace1.cs" />
58+
<Compile Include="TestsUtils\DiactiticsClass.cs" />
5859
</ItemGroup>
5960
<ItemGroup>
6061
<None Include="packages.config" />
@@ -125,6 +126,48 @@
125126
<ItemGroup>
126127
<None Include="Resources\Script0018.txt" />
127128
</ItemGroup>
129+
<ItemGroup>
130+
<None Include="Resources\Script0019.txt" />
131+
</ItemGroup>
132+
<ItemGroup>
133+
<None Include="Resources\Script0020.txt" />
134+
</ItemGroup>
135+
<ItemGroup>
136+
<None Include="Resources\Script0021.txt" />
137+
</ItemGroup>
138+
<ItemGroup>
139+
<None Include="Resources\Script0022.txt" />
140+
</ItemGroup>
141+
<ItemGroup>
142+
<None Include="Resources\Script0023.txt" />
143+
</ItemGroup>
144+
<ItemGroup>
145+
<None Include="Resources\Script0024.txt" />
146+
</ItemGroup>
147+
<ItemGroup>
148+
<None Include="Resources\Script0025.txt" />
149+
</ItemGroup>
150+
<ItemGroup>
151+
<None Include="Resources\Script0026.txt" />
152+
</ItemGroup>
153+
<ItemGroup>
154+
<None Include="Resources\Script0027.txt" />
155+
</ItemGroup>
156+
<ItemGroup>
157+
<None Include="Resources\Script0028.txt" />
158+
</ItemGroup>
159+
<ItemGroup>
160+
<None Include="Resources\Script0029.txt" />
161+
</ItemGroup>
162+
<ItemGroup>
163+
<None Include="Resources\Script0030.txt" />
164+
</ItemGroup>
165+
<ItemGroup>
166+
<None Include="Resources\Script0031.txt" />
167+
</ItemGroup>
168+
<ItemGroup>
169+
<None Include="Resources\Script0032.txt" />
170+
</ItemGroup>
128171
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
129172
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
130173
<PropertyGroup>

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,41 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
812812

813813
#endregion
814814

815+
#region try, catch, finally
816+
817+
yield return new TestCaseData(Resources.Script0028, null, null, null)
818+
.SetCategory("Script")
819+
.SetCategory("Try")
820+
.SetCategory("Catch")
821+
.SetCategory("Finally")
822+
.SetCategory("Exception")
823+
.Returns("catch : True, finally : True");
824+
825+
yield return new TestCaseData(Resources.Script0030, null, null, null)
826+
.SetCategory("Script")
827+
.SetCategory("Try")
828+
.SetCategory("Catch")
829+
.SetCategory("Exception")
830+
.Returns("catch : True, finally : False");
831+
832+
yield return new TestCaseData(Resources.Script0031, null, null, null)
833+
.SetCategory("Script")
834+
.SetCategory("Try")
835+
.SetCategory("Catch")
836+
.SetCategory("Finally")
837+
.SetCategory("Exception")
838+
.Returns("catch : 1, finally : True");
839+
840+
yield return new TestCaseData(Resources.Script0032, null, null, null)
841+
.SetCategory("Script")
842+
.SetCategory("Try")
843+
.SetCategory("Catch")
844+
.SetCategory("Finally")
845+
.SetCategory("Exception")
846+
.Returns("catch : 2, finally : True");
847+
848+
#endregion
849+
815850
#region block for lambda body
816851

817852
yield return new TestCaseData(Resources.Script0006, null, null, null)
@@ -969,6 +1004,66 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
9691004

9701005
#endregion
9711006

1007+
#region ExpandoObject
1008+
1009+
yield return new TestCaseData(Resources.Script0019, null, null, null)
1010+
.SetCategory("Script")
1011+
.SetCategory("ExpandoObject")
1012+
.SetCategory("return")
1013+
.Returns(58.3);
1014+
yield return new TestCaseData(Resources.Script0020, null, null, null)
1015+
.SetCategory("Script")
1016+
.SetCategory("ExpandoObject")
1017+
.SetCategory("Indexing")
1018+
.SetCategory("return")
1019+
.Returns(58.3);
1020+
yield return new TestCaseData(Resources.Script0021, null, null, null)
1021+
.SetCategory("Script")
1022+
.SetCategory("ExpandoObject")
1023+
.SetCategory("Indexing")
1024+
.SetCategory("return")
1025+
.Returns(58.3);
1026+
yield return new TestCaseData(Resources.Script0022, null, null, null)
1027+
.SetCategory("Script")
1028+
.SetCategory("ExpandoObject")
1029+
.SetCategory("Indexing")
1030+
.SetCategory("return")
1031+
.Returns(58.3);
1032+
yield return new TestCaseData(Resources.Script0023, null, null, null)
1033+
.SetCategory("Script")
1034+
.SetCategory("ExpandoObject")
1035+
.SetCategory("Indexing")
1036+
.SetCategory("Postfix operator")
1037+
.SetCategory("++")
1038+
.SetCategory("return")
1039+
.Returns(5);
1040+
yield return new TestCaseData(Resources.Script0024, null, null, null)
1041+
.SetCategory("Script")
1042+
.SetCategory("ExpandoObject")
1043+
.SetCategory("lambda")
1044+
.SetCategory("lambda call")
1045+
.SetCategory("lambda assignation")
1046+
.SetCategory("return")
1047+
.Returns("The result is : 7");
1048+
1049+
#endregion
1050+
1051+
#region Diactitics
1052+
1053+
yield return new TestCaseData(Resources.Script0026, null, null, null)
1054+
.SetCategory("Script")
1055+
.SetCategory("Diactitics")
1056+
.SetCategory("=")
1057+
.Returns("A value in diactitic varçÿ && very complex var");
1058+
1059+
yield return new TestCaseData(Resources.Script0027, null, null, null)
1060+
.SetCategory("Script")
1061+
.SetCategory("Diactitics")
1062+
.SetCategory("=")
1063+
.Returns("ç");
1064+
1065+
#endregion
1066+
9721067
#region More complex script
9731068

9741069
yield return new TestCaseData(Resources.Script0007, null, null, null)
@@ -1091,14 +1186,14 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingScriptEvalu
10911186
OptionOnNoReturnKeywordFoundInScriptAction = OptionOnNoReturnKeywordFoundInScriptAction.ThrowSyntaxException
10921187
};
10931188

1094-
yield return new TestCaseData(evaluator, Resources.Script0008.Replace("[valx]", "1"), typeof(ExpressionEvaluatorSyntaxErrorException))
1189+
yield return new TestCaseData(evaluator, Resources.Script0008.Replace("[valx]", "1"), typeof(ExpressionEvaluatorSyntaxErrorException), null,null)
10951190
.SetCategory("Script")
10961191
.SetCategory("return")
10971192
.SetCategory("if")
10981193
.SetCategory("variable assignation")
10991194
.SetCategory("Options")
11001195
.SetCategory("OptionOnNoReturnKeywordFoundInScriptAction = ThrowSyntaxException");
1101-
yield return new TestCaseData(evaluator, Resources.Script0008.Replace("[valx]", "2"), typeof(ExpressionEvaluatorSyntaxErrorException))
1196+
yield return new TestCaseData(evaluator, Resources.Script0008.Replace("[valx]", "2"), typeof(ExpressionEvaluatorSyntaxErrorException), null,null)
11021197
.SetCategory("Script")
11031198
.SetCategory("return")
11041199
.SetCategory("if")
@@ -1109,13 +1204,44 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingScriptEvalu
11091204
#endregion
11101205

11111206
#endregion
1207+
1208+
#region Throw Exception
1209+
1210+
yield return new TestCaseData(new ExpressionEvaluator(), Resources.Script0025, typeof(Exception), "Exception for test",null)
1211+
.SetCategory("Script")
1212+
.SetCategory("Throw")
1213+
.SetCategory("Exception");
1214+
1215+
yield return new TestCaseData(new ExpressionEvaluator(), Resources.Script0029, typeof(DivideByZeroException), null, new Action(() => ClassForTest1.StaticIntProperty.ShouldEqual(20)))
1216+
.SetCategory("Script")
1217+
.SetCategory("Try")
1218+
.SetCategory("Finally")
1219+
.SetCategory("Exception");
1220+
1221+
#endregion
11121222
}
11131223
}
11141224

11151225
[TestCaseSource(nameof(TestCasesForExceptionThrowingScriptEvaluation))]
1116-
public void ExceptionThrowingScriptEvaluation(ExpressionEvaluator evaluator, string script, Type exceptionType)
1226+
public void ExceptionThrowingScriptEvaluation(ExpressionEvaluator evaluator, string script, Type exceptionType, string exceptionMessage, Action ToTestAfter)
11171227
{
1118-
Assert.Catch(exceptionType, () => evaluator.ScriptEvaluate(script));
1228+
evaluator.Namespaces.Add("CodingSeb.ExpressionEvaluator.Tests");
1229+
1230+
Assert.Catch(exceptionType, () => evaluator.ScriptEvaluate(evaluator.RemoveComments(script)));
1231+
1232+
if (exceptionMessage != null)
1233+
{
1234+
try
1235+
{
1236+
evaluator.ScriptEvaluate(evaluator.RemoveComments(script));
1237+
}
1238+
catch(Exception exception)
1239+
{
1240+
exception.Message.ShouldEqual(exceptionMessage);
1241+
}
1242+
}
1243+
1244+
ToTestAfter?.Invoke();
11191245
}
11201246

11211247
#endregion

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,13 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
10131013
yield return new TestCaseData("Test(5)", delegatesInVariable, true).SetCategory("Delegate as a variable").Returns(null);
10141014

10151015
#endregion
1016+
1017+
#region Delegates as Property of object
1018+
1019+
yield return new TestCaseData("customObject.AddAsDelegate(6, 10)", onInstanceVariables, true).SetCategory("Delegate as a instance Property").Returns(16);
1020+
yield return new TestCaseData("ClassForTest1.AddAsStaticDelegate(6, 10)", onInstanceVariables, true).SetCategory("Delegate as a static Property").Returns(16);
1021+
1022+
#endregion
10161023
}
10171024
}
10181025

0 commit comments

Comments
 (0)