tests for compiled new array bounds
authorJb Evain <jbevain@gmail.com>
Thu, 13 Mar 2008 10:07:10 +0000 (10:07 -0000)
committerJb Evain <jbevain@gmail.com>
Thu, 13 Mar 2008 10:07:10 +0000 (10:07 -0000)
svn path=/trunk/mcs/; revision=98127

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

index f90589238c9e7314cf523e2d334e2040915436d9..ab9ff8ed48d9b88422f22d5ff1339c6597c2c855 100644 (file)
@@ -67,5 +67,51 @@ namespace MonoTests.System.Linq.Expressions {
                        Assert.AreEqual (2, ab.Expressions.Count);
                        Assert.AreEqual ("new System.Int32[,](1, 2)", ab.ToString ());
                }
+
+               static Func<object> CreateNewArrayFactory<T> (params int [] bounds)
+               {
+                       return Expression.Lambda<Func<object>> (
+                               Expression.NewArrayBounds (
+                                       typeof (T),
+                                       (from bound in bounds select bound.ToConstant ()).ToArray ())).Compile ();
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void TestArrayAssignability ()
+               {
+                       var l = Expression.Lambda<Func<int []>> (
+                               Expression.NewArrayBounds (
+                                       typeof (int),
+                                       4.ToConstant ()));
+               }
+
+               [Test]
+               public void CompileNewArraySingleDimensional ()
+               {
+                       var factory = CreateNewArrayFactory<int> (3);
+
+                       var array = (int []) factory ();
+                       var type = array.GetType ();
+
+                       Assert.IsNotNull (array);
+                       Assert.AreEqual (3, array.Length);
+                       Assert.IsTrue (type.IsArray);
+                       Assert.AreEqual (1, type.GetArrayRank ());
+               }
+
+               [Test]
+               public void CompileNewArrayMultiDimensional ()
+               {
+                       var factory = CreateNewArrayFactory<int> (3, 3);
+
+                       var array = (int [,]) factory ();
+                       var type = array.GetType ();
+
+                       Assert.IsNotNull (array);
+                       Assert.IsTrue (type.IsArray);
+                       Assert.AreEqual (2, type.GetArrayRank ());
+                       Assert.AreEqual (9, array.Length);
+               }
        }
 }