Merge pull request #1843 from info-lvsys/patch-1
[mono.git] / mcs / class / System.Core / Test / System.Linq.Expressions / ExpressionTest_Lambda.cs
index 9342722287ce411e92fa115eb7ff434bda3e90fa..07b8f0381828a76eeb8c0f031b36434dd2ec3697 100644 (file)
@@ -18,6 +18,8 @@
 //
 // Authors:
 //   Miguel de Icaza (miguel@novell.com)
+//   Jb Evain (jbevain@novell.com)
+//
 
 using System;
 using System.Reflection;
@@ -95,6 +97,13 @@ namespace MonoTests.System.Linq.Expressions
                        Expression.Lambda (typeof (delegate_object_object), Expression.Constant ("foo"), new ParameterExpression [1] {p});
                }
 
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void NullParameter ()
+               {
+                       Expression.Lambda<Func<int, int>> (Expression.Constant (1), new ParameterExpression [] { null });
+               }
+
                [Test]
                public void Assignability ()
                {
@@ -208,16 +217,55 @@ namespace MonoTests.System.Linq.Expressions
                }
 
                [Test]
-               public void LambdaReturningExpression ()
+               [Category ("NotWorking")]
+               public void LambdaPassedAsDelegateUsingParentParameter ()
                {
-                       var l = Expression.Lambda<Func<Expression>> (Expression.Constant (42));
-                       Assert.AreEqual (ExpressionType.Quote, l.Body.NodeType);
+                       var a = Expression.Parameter (typeof (int), "a");
+                       var b = Expression.Parameter (typeof (int), "b");
+
+                       var l = Expression.Lambda<Func<int, int>> (
+                               Expression.Call (
+                                       this.GetType ().GetMethod ("CallDelegate"),
+                                       Expression.Lambda<Func<int, int>> (
+                                                       Expression.Multiply (a, b), b)),
+                               a).Compile ();
 
-                       var quoter = l.Compile ();
+                       Assert.AreEqual (84, l (2));
+               }
 
-                       var q = quoter ();
+               public static int CallFunc (Func<int, int> e, int i)
+               {
+                       return e (i);
+               }
 
-                       Assert.AreEqual (ExpressionType.Constant, q.NodeType);
+               [Test]
+               public void NestedParentParameterUse ()
+               {
+                       var a = Expression.Parameter (typeof (int), null);
+                       var b = Expression.Parameter (typeof (int), null);
+                       var c = Expression.Parameter (typeof (int), null);
+                       var d = Expression.Parameter (typeof (int), null);
+
+                       var l = Expression.Lambda<Func<int, int>> (
+                               Expression.Call (
+                                       this.GetType ().GetMethod ("CallFunc"),
+                                       Expression.Lambda<Func<int, int>> (
+                                               Expression.Call (
+                                                       this.GetType ().GetMethod ("CallFunc"),
+                                                       Expression.Lambda<Func<int, int>> (
+                                                               Expression.Call (
+                                                                       this.GetType ().GetMethod ("CallFunc"),
+                                                                       Expression.Lambda<Func<int, int>> (
+                                                                               Expression.Add (c, d),
+                                                                               d),
+                                                                       Expression.Add (b, c)),
+                                                               c),
+                                                       Expression.Add (a, b)),
+                                               b),
+                                       a),
+                               a).Compile ();
+
+                       Assert.AreEqual (5, l (1));
                }
        }
 }