tests for lifted not
[mono.git] / mcs / class / System.Core / Test / System.Linq.Expressions / ExpressionTest_Invoke.cs
index f3a9491b6ddfb6f794683eef44963b8d22f14355..1c7c30784130595874cbccb3476bb0e0ffd7d109 100644 (file)
@@ -94,7 +94,48 @@ namespace MonoTests.System.Linq.Expressions {
                        var invoke = Expression.Invoke (CreateInvokable<Func<string, string, int>> (), "foo".ToConstant (), "bar".ToConstant ());
                        Assert.AreEqual (typeof (int), invoke.Type);
                        Assert.AreEqual (2, invoke.Arguments.Count);
-                       Assert.AreEqual ("Invoke(invokable, \"foo\", \"bar\")", invoke.ToString ());
+                       if (OnMono ())
+                               Assert.AreEqual ("Invoke(invokable, \"foo\", \"bar\")", invoke.ToString ());
+                       else
+                               Assert.AreEqual ("Invoke(invokable,\"foo\",\"bar\")", invoke.ToString ());
+               }
+
+               [Test]
+               public void InvokeLambda ()
+               {
+                       var p = Expression.Parameter (typeof (int), "i");
+                       var lambda = Expression.Lambda<Func<int, int>> (p, p);
+
+                       var invoke = Expression.Invoke (lambda, 1.ToConstant ());
+                       Assert.AreEqual (typeof (int), invoke.Type);
+                       Assert.AreEqual (1, invoke.Arguments.Count);
+                       if (OnMono ())
+                               Assert.AreEqual ("Invoke(i => i, 1)", invoke.ToString ());
+                       else
+                               Assert.AreEqual ("Invoke(i => i,1)", invoke.ToString ());
+               }
+
+               static bool OnMono ()
+               {
+                       return typeof (Expression).Assembly.GetType ("Consts") != null;
+               }
+
+               delegate string StringAction (string s);
+
+               static string Identity (string s)
+               {
+                       return s;
+               }
+
+               [Test]
+               public void TestCompileInvokePrivateDelegate ()
+               {
+                       var action = Expression.Parameter (typeof (StringAction), "action");
+                       var str = Expression.Parameter (typeof (string), "str");
+                       var invoker = Expression.Lambda<Func<StringAction, string, string>> (
+                               Expression.Invoke (action, str), action, str).Compile ();
+
+                       Assert.AreEqual ("foo", invoker (Identity, "foo"));
                }
        }
 }