@@ -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
0 commit comments