[test] Test for System.Linq.Expressions.MethodCallExpression with a DynamicMethod
authorAleksey Kliger <aleksey@xamarin.com>
Tue, 13 Dec 2016 21:17:08 +0000 (16:17 -0500)
committerAleksey Kliger <aleksey@xamarin.com>
Tue, 13 Dec 2016 21:34:16 +0000 (16:34 -0500)
Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=49686

mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Call.cs

index 976b50109d0c0b4deba28eb9ff0d7e29016a876b..85e011bc277b62d792a7a8a56a4101d3ef85f90f 100644 (file)
@@ -29,6 +29,7 @@
 
 using System;
 using System.Reflection;
+using System.Reflection.Emit;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq.Expressions;
@@ -295,6 +296,36 @@ namespace MonoTests.System.Linq.Expressions {
                        Assert.AreEqual ("foo42", lamda (42, "foo"));
                }
 
+               [Test]
+               public void CallDynamicMethod_ToString ()
+               {
+                       // Regression test for #49686
+                       var m = new DynamicMethod ("intIntId", typeof (int), new Type [] { typeof (int) });
+                       var ilg = m.GetILGenerator ();
+                       ilg.Emit (OpCodes.Ldarg_0);
+                       ilg.Emit (OpCodes.Ret);
+
+                       var i = Expression.Parameter (typeof (int), "i");
+                       var e = Expression.Call (m, i);
+
+                       Assert.IsNotNull (e.ToString ());
+               }
+
+               [Test]
+               public void CallDynamicMethod_CompileInvoke ()
+               {
+                       var m = new DynamicMethod ("intIntId", typeof (int), new Type [] { typeof (int) });
+                       var ilg = m.GetILGenerator ();
+                       ilg.Emit (OpCodes.Ldarg_0);
+                       ilg.Emit (OpCodes.Ret);
+
+                       var i = Expression.Parameter (typeof (int), "i");
+                       var e = Expression.Call (m, i);
+
+                       var lambda = Expression.Lambda<Func<int, int>> (e, i).Compile ();
+                       Assert.AreEqual (42, lambda (42));
+               }
+
                public static int Bang (Expression i)
                {
                        return (int) (i as ConstantExpression).Value;