@@ -2143,6 +2143,105 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
21432143
21442144 #endregion
21452145
2146+ #region Method with params parameter
2147+
2148+ ExpressionEvaluator evaluatorForParamsTests ( )
2149+ {
2150+ ExpressionEvaluator ee = new ExpressionEvaluator ( new Dictionary < string , object > ( )
2151+ {
2152+ { "paramsObj" , new MethodArgKeywordClass ( ) }
2153+ } ) ;
2154+
2155+ ee . StaticTypesForExtensionsMethods . Add ( typeof ( MethodArgKeywordClassExtension ) ) ;
2156+ return ee ;
2157+ }
2158+
2159+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2160+ , "paramsObj.SumOf(1, 2)"
2161+ , null )
2162+ . Returns ( 3 )
2163+ . SetCategory ( "ParamsKeywordMethod" ) ;
2164+
2165+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2166+ , "paramsObj.SumOf(1, 2, 3)"
2167+ , null )
2168+ . Returns ( 6 )
2169+ . SetCategory ( "ParamsKeywordMethod" ) ;
2170+
2171+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2172+ , "paramsObj.SumOf(1,2,3,4)"
2173+ , null )
2174+ . Returns ( 10 )
2175+ . SetCategory ( "ParamsKeywordMethod" ) ;
2176+
2177+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2178+ , "paramsObj.SumOf2()"
2179+ , null )
2180+ . Returns ( 0 )
2181+ . SetCategory ( "ParamsKeywordMethod" ) ;
2182+
2183+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2184+ , "paramsObj.SumOf2(1)"
2185+ , null )
2186+ . Returns ( 1 )
2187+ . SetCategory ( "ParamsKeywordMethod" ) ;
2188+
2189+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2190+ , "paramsObj.SumOf2(1,2,3,4)"
2191+ , null )
2192+ . Returns ( 10 )
2193+ . SetCategory ( "ParamsKeywordMethod" ) ;
2194+
2195+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2196+ , "string.Join(\" ,\" , 2, 3.5, \" Hello\" , true)"
2197+ , null )
2198+ . Returns ( "2,3.5,Hello,True" )
2199+ . SetCategory ( "ParamsKeywordMethod" ) ;
2200+
2201+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2202+ , "string.Join(\" ,\" , 2, 3.5, null, \" Hello\" , true)"
2203+ , null )
2204+ . Returns ( "2,3.5,,Hello,True" )
2205+ . SetCategory ( "ParamsKeywordMethod" ) ;
2206+
2207+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2208+ , "\" ,\" .UseAsSepForJoin(2, 3.5, \" Hello\" , true)"
2209+ , null )
2210+ . Returns ( "2,3.5,Hello,True" )
2211+ . SetCategory ( "ParamsKeywordMethod" ) ;
2212+
2213+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2214+ , "\" ,\" .UseAsSepForJoin(2, 3.5, null, \" Hello\" , true)"
2215+ , null )
2216+ . Returns ( "2,3.5,,Hello,True" )
2217+ . SetCategory ( "ParamsKeywordMethod" ) ;
2218+
2219+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2220+ , "paramsObj.Join(out x, \" ,\" , 2, 3.5, \" Hello\" , true) ?? x"
2221+ , null )
2222+ . Returns ( "2,3.5,Hello,True" )
2223+ . SetCategory ( "ParamsKeywordMethod" ) ;
2224+
2225+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2226+ , "paramsObj.Join(out x, \" ,\" , 2, 3.5, null, \" Hello\" , true) ?? x"
2227+ , null )
2228+ . Returns ( "2,3.5,,Hello,True" )
2229+ . SetCategory ( "ParamsKeywordMethod" ) ;
2230+
2231+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2232+ , "\" ,\" .UseAsSepForJoin(ref string x, 2, 3.5, \" Hello\" , true) ?? x"
2233+ , null )
2234+ . Returns ( "2,3.5,Hello,True" )
2235+ . SetCategory ( "ParamsKeywordMethod" ) ;
2236+
2237+ yield return new TestCaseData ( evaluatorForParamsTests ( )
2238+ , "\" ,\" .UseAsSepForJoin(ref x, 2, 3.5, null, \" Hello\" , true) ?? x"
2239+ , null )
2240+ . Returns ( "2,3.5,,Hello,True" )
2241+ . SetCategory ( "ParamsKeywordMethod" ) ;
2242+
2243+ #endregion
2244+
21462245 #region Bug resolution
21472246
21482247 yield return new TestCaseData ( new ExpressionEvaluator ( )
@@ -2222,5 +2321,245 @@ public void EvaluateWithSubExpressionsVariables()
22222321 }
22232322
22242323 #endregion
2324+
2325+ #region Method with out parameter
2326+
2327+ [ Test ]
2328+ [ Category ( "OutKeywordMethod" ) ]
2329+ public void MethodWithOutParameter ( )
2330+ {
2331+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2332+
2333+ evaluator . Variables [ "myDict" ] = new Dictionary < string , object >
2334+ {
2335+ { "ANumber" , 10 } ,
2336+ } ;
2337+
2338+ evaluator . Variables [ "x" ] = null ;
2339+
2340+ evaluator . Evaluate < bool > ( "myDict.TryGetValue(\" ANumber\" ,out x)" ) . ShouldBeTrue ( ) ;
2341+
2342+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2343+ evaluator . Variables [ "x" ]
2344+ . ShouldBeOfType < int > ( )
2345+ . ShouldBe ( 10 ) ;
2346+ }
2347+
2348+ [ Test ]
2349+ [ Category ( "OutKeywordMethod" ) ]
2350+ public void MethodWithOutParameterWithoutExistingVariable ( )
2351+ {
2352+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2353+
2354+ evaluator . Variables [ "myDict" ] = new Dictionary < string , object >
2355+ {
2356+ { "ANumber" , 10 } ,
2357+ } ;
2358+
2359+ evaluator . Evaluate < bool > ( "myDict.TryGetValue(\" ANumber\" ,out x)" ) . ShouldBeTrue ( ) ;
2360+
2361+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2362+ evaluator . Variables [ "x" ]
2363+ . ShouldBeOfType < int > ( )
2364+ . ShouldBe ( 10 ) ;
2365+ }
2366+
2367+ [ Test ]
2368+ [ Category ( "OutKeywordMethod" ) ]
2369+ public void MethodWithOutParameterInlineVarDeclaration ( )
2370+ {
2371+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2372+
2373+ evaluator . Variables [ "myDict" ] = new Dictionary < string , object >
2374+ {
2375+ { "ANumber" , 10 } ,
2376+ } ;
2377+
2378+ evaluator . Evaluate < bool > ( "myDict.TryGetValue(\" ANumber\" ,out int x)" ) . ShouldBeTrue ( ) ;
2379+
2380+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2381+ evaluator . Variables [ "x" ]
2382+ . ShouldBeOfType < StronglyTypedVariable > ( )
2383+ . Value . ShouldBe ( 10 ) ;
2384+ }
2385+
2386+ #endregion
2387+
2388+ #region Method with ref parameter
2389+
2390+ [ Test ]
2391+ [ Category ( "RefKeywordMethod" ) ]
2392+ public void MethodWithRefParameter ( )
2393+ {
2394+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2395+
2396+ evaluator . Variables [ "refObj" ] = new MethodArgKeywordClass ( ) ;
2397+
2398+ evaluator . Variables [ "x" ] = 3 ;
2399+
2400+ evaluator . Evaluate ( "refObj.AddOneOnRef(ref x)" ) ;
2401+
2402+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2403+ evaluator . Variables [ "x" ]
2404+ . ShouldBeOfType < int > ( )
2405+ . ShouldBe ( 4 ) ;
2406+ }
2407+
2408+ [ Test ]
2409+ [ Category ( "RefKeywordMethod" ) ]
2410+ public void MethodWithRefParameterWithoutExistingVariable ( )
2411+ {
2412+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2413+
2414+ evaluator . Variables [ "refObj" ] = new MethodArgKeywordClass ( ) ;
2415+
2416+ evaluator . Evaluate ( "refObj.AddOneOnRef(ref x)" ) ;
2417+
2418+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2419+ evaluator . Variables [ "x" ]
2420+ . ShouldBeOfType < int > ( )
2421+ . ShouldBe ( 1 ) ;
2422+ }
2423+
2424+ [ Test ]
2425+ [ Category ( "RefKeywordMethod" ) ]
2426+ public void MethodWithRefParameterInlineVarDeclaration ( )
2427+ {
2428+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2429+
2430+ evaluator . Variables [ "refObj" ] = new MethodArgKeywordClass ( ) ;
2431+
2432+ evaluator . Evaluate ( "refObj.AddOneOnRef(ref int x)" ) ;
2433+
2434+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2435+ evaluator . Variables [ "x" ]
2436+ . ShouldBeOfType < StronglyTypedVariable > ( )
2437+ . Value . ShouldBe ( 1 ) ;
2438+ }
2439+
2440+ [ Test ]
2441+ [ Category ( "RefKeywordMethod" ) ]
2442+ public void MethodWithRefParameterWithoutExistingVariableAndInit ( )
2443+ {
2444+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2445+
2446+ evaluator . Variables [ "refObj" ] = new MethodArgKeywordClass ( ) ;
2447+
2448+ evaluator . Evaluate ( "refObj.AddOneOnRef(ref x = 4)" ) ;
2449+
2450+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2451+ evaluator . Variables [ "x" ]
2452+ . ShouldBeOfType < int > ( )
2453+ . ShouldBe ( 5 ) ;
2454+ }
2455+
2456+ [ Test ]
2457+ [ Category ( "RefKeywordMethod" ) ]
2458+ public void MethodWithRefParameterInlineVarDeclarationAndInit ( )
2459+ {
2460+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2461+
2462+ evaluator . Variables [ "refObj" ] = new MethodArgKeywordClass ( ) ;
2463+
2464+ evaluator . Evaluate ( "refObj.AddOneOnRef(ref int x = 6)" ) ;
2465+
2466+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2467+ evaluator . Variables [ "x" ]
2468+ . ShouldBeOfType < StronglyTypedVariable > ( )
2469+ . Value . ShouldBe ( 7 ) ;
2470+ }
2471+
2472+ #endregion
2473+
2474+ #region Method with in parameter
2475+
2476+ [ Test ]
2477+ [ Category ( "InKeywordMethod" ) ]
2478+ public void MethodWithInParameter ( )
2479+ {
2480+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2481+
2482+ evaluator . Variables [ "inObj" ] = new MethodArgKeywordClass ( ) ;
2483+
2484+ evaluator . Variables [ "x" ] = 3 ;
2485+
2486+ evaluator . Evaluate ( "inObj.AddOneOnIn(in x)" )
2487+ . ShouldBe ( 4 ) ;
2488+
2489+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2490+ evaluator . Variables [ "x" ]
2491+ . ShouldBeOfType < int > ( )
2492+ . ShouldBe ( 3 ) ;
2493+ }
2494+
2495+ [ Test ]
2496+ [ Category ( "InKeywordMethod" ) ]
2497+ public void MethodWithInParameterWithoutExistingVariable ( )
2498+ {
2499+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2500+
2501+ evaluator . Variables [ "inObj" ] = new MethodArgKeywordClass ( ) ;
2502+
2503+ evaluator . Evaluate ( "inObj.AddOneOnIn(in x)" )
2504+ . ShouldBe ( 1 ) ;
2505+
2506+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2507+ evaluator . Variables [ "x" ]
2508+ . ShouldBeNull ( ) ;
2509+ }
2510+
2511+ [ Test ]
2512+ [ Category ( "InKeywordMethod" ) ]
2513+ public void MethodWithInParameterInlineVarDeclaration ( )
2514+ {
2515+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2516+
2517+ evaluator . Variables [ "inObj" ] = new MethodArgKeywordClass ( ) ;
2518+
2519+ evaluator . Evaluate ( "inObj.AddOneOnIn(in int x)" )
2520+ . ShouldBe ( 1 ) ;
2521+
2522+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2523+ evaluator . Variables [ "x" ]
2524+ . ShouldBeOfType < StronglyTypedVariable > ( )
2525+ . Value . ShouldBe ( 0 ) ;
2526+ }
2527+
2528+ [ Test ]
2529+ [ Category ( "InKeywordMethod" ) ]
2530+ public void MethodWithInParameterWithoutExistingVariableAndInit ( )
2531+ {
2532+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2533+
2534+ evaluator . Variables [ "inObj" ] = new MethodArgKeywordClass ( ) ;
2535+
2536+ evaluator . Evaluate ( "inObj.AddOneOnIn(in x = 4)" )
2537+ . ShouldBe ( 5 ) ;
2538+
2539+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2540+ evaluator . Variables [ "x" ]
2541+ . ShouldBeOfType < int > ( )
2542+ . ShouldBe ( 4 ) ;
2543+ }
2544+
2545+ [ Test ]
2546+ [ Category ( "InKeywordMethod" ) ]
2547+ public void MethodWithInParameterInlineVarDeclarationAndInit ( )
2548+ {
2549+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
2550+
2551+ evaluator . Variables [ "inObj" ] = new MethodArgKeywordClass ( ) ;
2552+
2553+ evaluator . Evaluate ( "inObj.AddOneOnIn(in int x = 6)" )
2554+ . ShouldBe ( 7 ) ;
2555+
2556+ evaluator . Variables . ShouldContainKey ( "x" ) ;
2557+ evaluator . Variables [ "x" ]
2558+ . ShouldBeOfType < StronglyTypedVariable > ( )
2559+ . Value . ShouldBe ( 6 ) ;
2560+ }
2561+
2562+ #endregion
2563+
22252564 }
22262565}
0 commit comments