Add new tests
authorMiguel de Icaza <miguel@gnome.org>
Fri, 2 Apr 2004 05:13:05 +0000 (05:13 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 2 Apr 2004 05:13:05 +0000 (05:13 -0000)
svn path=/trunk/mcs/; revision=24956

mcs/tests/2test-a1.cs [new file with mode: 0644]
mcs/tests/2test-a2.cs [new file with mode: 0644]
mcs/tests/2test-a3.cs [new file with mode: 0644]
mcs/tests/2test-a4.cs [new file with mode: 0644]
mcs/tests/2test-a5.cs [new file with mode: 0644]
mcs/tests/2test-a6.cs [new file with mode: 0644]
mcs/tests/2test-a7.cs [new file with mode: 0644]
mcs/tests/2test-a8.cs [new file with mode: 0644]
mcs/tests/2test-a9.cs [new file with mode: 0644]

diff --git a/mcs/tests/2test-a1.cs b/mcs/tests/2test-a1.cs
new file mode 100644 (file)
index 0000000..f63b923
--- /dev/null
@@ -0,0 +1,16 @@
+//
+// Parameter and return value compilation tests for anonymous methods
+//
+delegate void D (int x);
+delegate void E (out int x);
+
+class X {
+       static int Main ()
+       {
+               // This should create an AnonymousMethod with the implicit argument
+               D d1 = delegate {};
+               D d2 = delegate (int a) {};
+
+               return 0;
+       }
+}
diff --git a/mcs/tests/2test-a2.cs b/mcs/tests/2test-a2.cs
new file mode 100644 (file)
index 0000000..0bb2390
--- /dev/null
@@ -0,0 +1,18 @@
+delegate void S ();
+
+class X {
+
+       //
+       // DO NOT ADD ANYTHING ELSE TO THIS TEST
+       //
+       static int Main ()
+       {
+               int a;
+
+               S b = delegate {
+                       a = 2;
+               };
+
+               return 0;
+       }
+}
diff --git a/mcs/tests/2test-a3.cs b/mcs/tests/2test-a3.cs
new file mode 100644 (file)
index 0000000..400059c
--- /dev/null
@@ -0,0 +1,35 @@
+delegate void S ();
+using System;
+
+class X {
+       static int Main ()
+       {
+               int a = 1;
+               Console.WriteLine ("A is = " + a);
+               int c = a;
+               Console.WriteLine (c);
+               if (a != 1){
+                       return 1;
+               }
+               
+               S b = delegate {
+                       if (a != 1)
+                               Environment.Exit (1);
+                       Console.WriteLine ("in Delegate");
+                       a = 2;
+                       if (a != 2)
+                               Environment.Exit (2);
+                       Console.WriteLine ("Inside = " + a);
+                       a = 3;
+                       Console.WriteLine ("After = " + a);
+               };
+               if (a != 1)
+                       return 3;
+               b ();
+               if (a != 3)
+                       return 4;
+               Console.WriteLine ("Back, got " + a);
+
+               return 0;
+       }
+}
diff --git a/mcs/tests/2test-a4.cs b/mcs/tests/2test-a4.cs
new file mode 100644 (file)
index 0000000..ebf4060
--- /dev/null
@@ -0,0 +1,14 @@
+delegate void S ();
+using System;
+
+class X {
+       static void Main ()
+       {
+               int a = 1;
+               S b = delegate {
+                       a = 2;
+               };
+               b ();
+               Console.WriteLine ("Back, got " + a);
+       }
+}
diff --git a/mcs/tests/2test-a5.cs b/mcs/tests/2test-a5.cs
new file mode 100644 (file)
index 0000000..290ebe2
--- /dev/null
@@ -0,0 +1,17 @@
+delegate void S ();
+using System;
+
+class X {
+       static void Main ()
+       {
+               int a = 1;
+               S b = delegate {
+                       float f = 1;
+                       Console.WriteLine (a);
+                       if (f == 2)
+                               return;
+               };
+               b ();
+               Console.WriteLine ("Back, got " + a);
+       }
+}
diff --git a/mcs/tests/2test-a6.cs b/mcs/tests/2test-a6.cs
new file mode 100644 (file)
index 0000000..e34d61f
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// Tests capturing of double nested variables
+//
+delegate void S ();
+using System;
+
+class X {
+       static int Main ()
+       {
+               int i;
+               S b = null;
+               
+               for (i = 0; i < 10; i++){
+                       int j = 0;
+                       b = delegate {
+                               Console.WriteLine ("i={0} j={1}", i, j);
+                               i = i + 1;
+                               j = j + 1;
+                       };
+               }
+               b ();
+               Console.WriteLine ("i = {0}", i);
+               if (!t (i, 11))
+                       return 1;
+               b ();
+               if (!t (i, 12))
+                       return 2;
+               Console.WriteLine ("i = {0}", i);
+               return 0;
+       }
+
+       static bool t (int a, int b)
+       {
+               return a == b;
+       }
+}
diff --git a/mcs/tests/2test-a7.cs b/mcs/tests/2test-a7.cs
new file mode 100644 (file)
index 0000000..ecb5c51
--- /dev/null
@@ -0,0 +1,28 @@
+//
+// Tests capturing of variables
+//
+delegate void S ();
+using System;
+
+class X {
+       static int Main ()
+       {
+               int a = 1;
+               if (a != 1)
+                       return 1;
+               
+               Console.WriteLine ("A is = " + a);
+               S b= delegate {
+                       Console.WriteLine ("on delegate");
+                       a = 2;
+               };
+               if (a != 1)
+                       return 2;
+               b();
+               if (a != 2)
+                       return 3;
+               Console.WriteLine ("OK");
+               return 0;
+       }
+}
+               
diff --git a/mcs/tests/2test-a8.cs b/mcs/tests/2test-a8.cs
new file mode 100644 (file)
index 0000000..0dcd92f
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// Tests havign more than one anonymous method that captures the same variable
+//
+using System;
+
+delegate void D ();
+
+class X {
+       static int Main ()
+       {
+               int a = 0;
+               D d1 = delegate {
+                       Console.WriteLine ("First");
+                       a = 1;
+               };
+               
+               D d2 = delegate {
+                       Console.WriteLine ("Second");
+                       a = 2;
+               };
+               if (!t (a, 0))
+                       return 1;
+               d1 ();
+               if (!t (a, 1))
+                       return 2;
+               d2 ();
+               if (!t (a, 2))
+                       return 3;
+               Console.WriteLine ("Test passes OK");
+               return 0;
+       }
+
+       static bool t (int a, int b)
+       {
+               return a == b;
+       }
+}
diff --git a/mcs/tests/2test-a9.cs b/mcs/tests/2test-a9.cs
new file mode 100644 (file)
index 0000000..a951710
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// Tests capturing of double nested variables
+//
+delegate void S ();
+using System;
+
+class X {
+       static int Main ()
+       {
+               int i;
+               int a = 0;
+               S b = null;
+               
+               for (i = 0; i < 10; i++){
+                       int j = 0;
+                       b = delegate {
+                               Console.WriteLine ("i={0} j={1}", i, j);
+                               i = i + 1;
+                               j = j + 1;
+                               a = j;
+                       };
+               }
+               b ();
+               Console.WriteLine ("i = {0}", i);
+               if (!t (i, 11))
+                       return 1;
+               b ();
+               if (!t (i, 12))
+                       return 2;
+               Console.WriteLine ("i = {0}", i);
+               Console.WriteLine ("a = {0}", a);
+               if (!t (a, 2))
+                       return 3;
+               
+               return 0;
+       }
+
+       static bool t (int a, int b)
+       {
+               return a == b;
+       }
+}