New tests.
[mono.git] / mcs / tests / gtest-anon-24.cs
index 4bc12f7747cf00a7319c839b299017f055efc81c..103ba8d0537fc87baa348a1b8927e296b203322f 100644 (file)
@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
 
+// Generics mutate tests
+
 class Disposable<T> : IDisposable
 {
        public void Dispose ()
@@ -8,6 +10,19 @@ class Disposable<T> : IDisposable
        }
 }
 
+interface IFoo<TOne,TTwo>
+{
+}
+
+class CA<T>
+{
+       public struct Nested
+       {
+               public static readonly T Value;
+               public readonly T Value2;
+       }
+}
+
 class Test
 {
        static Func<T[]> For<T> (List<T> list)
@@ -30,6 +45,18 @@ class Test
                };
        }
        
+       static Func<Type> TypeOf<T> (T t)
+       {
+               T l = t;
+               return () => {
+                       l = t;
+                       var e = typeof (Disposable <T>);
+                       e = typeof (Disposable <>);
+                       e = typeof (IFoo <,>);
+                       return typeof (T);
+               };
+       }
+       
        static Func<T> Do<T> (T t)
        {
                T l = t;
@@ -113,6 +140,36 @@ class Test
                };
        }
        
+       public void ArrayMutate<T> (T[] array)
+       {
+               int r = 4;
+               Action<int> anonMeth = delegate (int slc) {
+                       long[] idx = new long[] { 0, 0 };
+                       for (int i = 0; i < r; i++) {
+                               idx [0] = i;
+                       }
+               };
+       }
+       
+       static Func<T[][]> ArrayMultiMutate<T> (T[][] array)
+       {
+               return () => {
+                       for (int i = 0; i < 3; i++) {
+                               array [i][i] = default (T);
+                       }
+                       
+                       return array;
+               };
+       }
+       
+       static Func<T[]> NestedTypeMutate<T> ()
+       {
+               var local = new CA<T>.Nested ();
+               return () => {
+                       return new [] { CA<T>.Nested.Value, local.Value2 };
+               };
+       }
+       
        public static int Main ()
        {
                if (For (new List<int> { 5, 10 })() [1] != 10)
@@ -153,8 +210,20 @@ class Test
                var t9 = ForForeach (new [] { 4, 1 });
                if (t9 ()[0] != 4)
                        return 9;
+                       
+               var t10 = ArrayMultiMutate (new string [][] { new string [] { "a", "b", "c" }, new string [] { "1", "2", "3" }, new string [] { "A", "B", "C" }});
+               if (t10 () [2] [2] != null)
+                       return 10;
+               
+               var t11 = TypeOf ("b");
+               if (t11 () != typeof (string))
+                       return 11;
                
+               var t12 = NestedTypeMutate<ulong> ()();
+               if (t12 [0] != 0 || t12 [1] != 0)
+                       return 12;
+
                Console.WriteLine ("OK");
                return 0;
        }
-}
\ No newline at end of file
+}