Merge pull request #4431 from vkargov/vk-leaking-points
[mono.git] / mcs / tests / gtest-lambda-01.cs
1
2 //
3 // Lambda expression test, basics.
4 //
5 using System;
6
7 delegate int IntFunc (int x);
8 delegate void VoidFunc (int x);
9
10 class X {
11
12         static IntFunc func, increment;
13         static VoidFunc nothing;
14         
15         public static int Main ()
16         {
17                 int y = 0;
18                 int r;
19                 
20                 //
21                 // The following tests body-style lambda
22                 //
23                 increment = (int x) => { return x + 1; };
24                 r = increment (4);
25                 Console.WriteLine ("Should be 5={0}", r);
26                 if (r != 5)
27                         return 1;
28
29                 //
30                 // This tests the body of a lambda being an expression
31                 //
32                 func = (int x) => x + 1;
33                 r = func (10);
34                 Console.WriteLine ("Should be 11={0}", r);
35                 if (r != 11)
36                         return 2;
37                 
38                 //
39                 // The following tests that the body is a statement
40                 //
41                 nothing = (int x) => { y = x; };
42                 nothing (10);
43                 Console.WriteLine ("Should be 10={0}", y);
44                 if (y != 10)
45                         return 3;
46
47                 nothing = (int x) => { new X (x); };
48                 nothing (314);
49                 if (instantiated_value != 314)
50                         return 4;
51                 
52                 Console.WriteLine ("All tests pass");
53                 return 0;
54         }
55
56         static int instantiated_value;
57
58         X (int v)
59         {
60                 instantiated_value = v;
61         }
62 }