@@ -812,6 +812,41 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
812
812
813
813
#endregion
814
814
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
+
815
850
#region block for lambda body
816
851
817
852
yield return new TestCaseData ( Resources . Script0006 , null , null , null )
@@ -969,6 +1004,66 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
969
1004
970
1005
#endregion
971
1006
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
+
972
1067
#region More complex script
973
1068
974
1069
yield return new TestCaseData ( Resources . Script0007 , null , null , null )
@@ -1091,14 +1186,14 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingScriptEvalu
1091
1186
OptionOnNoReturnKeywordFoundInScriptAction = OptionOnNoReturnKeywordFoundInScriptAction . ThrowSyntaxException
1092
1187
} ;
1093
1188
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 )
1095
1190
. SetCategory ( "Script" )
1096
1191
. SetCategory ( "return" )
1097
1192
. SetCategory ( "if" )
1098
1193
. SetCategory ( "variable assignation" )
1099
1194
. SetCategory ( "Options" )
1100
1195
. 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 )
1102
1197
. SetCategory ( "Script" )
1103
1198
. SetCategory ( "return" )
1104
1199
. SetCategory ( "if" )
@@ -1109,13 +1204,44 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingScriptEvalu
1109
1204
#endregion
1110
1205
1111
1206
#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
1112
1222
}
1113
1223
}
1114
1224
1115
1225
[ 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 )
1117
1227
{
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 ( ) ;
1119
1245
}
1120
1246
1121
1247
#endregion
0 commit comments