Initial set of Ward sgen annotations (#5705)
[mono.git] / mcs / tests / gtest-linq-01.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4
5 namespace from
6 {
7         interface ITest
8         {
9                 int Id { get; }
10         }
11
12         class C
13         {
14                 // This is pure grammar/parser test
15                 public static void Main ()
16                 {
17                         int[] i2 = new int [] { 0, 1 };
18                         int[] i_b = new int [] { 0, 1 };
19                         ITest[] join_test = new ITest[0];
20                         
21                         IEnumerable<int> e;
22                         IEnumerable<IGrouping<int,int>> g;
23
24                         // FROM
25                         e = from i in i2 select i;
26                         e = from int i in i2 select i;
27                         var e2 = from bool? i in i2 select i;
28                         e = from i in new int[0] select i;
29                         e = from x in i2 from y in i2 select y;
30
31                         // WHERE
32                         e = from i in i2 where i % 3 != 0 select i;
33
34                         // ORDER BY
35                         e = from i in i2 orderby i select i;
36                         e = from i in i2 orderby i, i, i, i select i;
37                         e = from i in i2 orderby i descending select i;
38                         e = from i in i2 orderby i ascending select i;
39                         
40                         // JOIN
41                         e = from i in i2 join j in join_test on i equals j.Id select i;
42                         e = from i in i2 join ITest j in join_test on i equals j.Id select i;
43                         e = from i in i2 join j in join_test on i equals j.Id
44                                 join j2 in join_test on i equals j2.Id select i;
45                         e = from i in i2 join j in i_b on i equals j into j select i;
46                         e = from i in i2 join int j in i_b on i equals j into j select i;
47
48                         // GROUP BY
49                         g = from i in i2 group i by 2;
50                         g = from i in i2 group i by 2 into i select i;
51
52                         // LET
53                         e = from i in i2 let l = i + 4 select i;
54                         e = from i in i2 let l = i + 4 let l2 = l + 2 select i;
55                         
56                         // INTO
57                         g = from i in i2 group i by 2 into i9
58                                 from i in i2 group i by 2 into i9
59                                 from i in i2 group i by 2 into i9
60                                 from i in i2 group i by 2 into i9
61                                 select i9;
62                                 
63                         // NESTED
64                         var e3 = from a in
65                                         from b in i2
66                                         select b
67                                 orderby a
68                                 select a;
69                                 
70                         var e4 = from i in
71                                         from x in i2
72                                         select x
73                                 let l = from x2 in i2 select x2
74                                 let l2 = 50
75                                 select 1;
76
77                         int from = 0;
78                         bool let = false;
79                         
80                         // TODO: Re-enable when we fix cast of query expression
81                         //object o = (object)from i in i2 select i;
82                 }
83                 
84                 void Foo (int from, bool where)
85                 {
86                         int Foo = 0;
87                         if (from < Foo) // This tests generics micro-parser awareness
88                                 return;
89                 }
90                 
91                 int foo;
92                 void Do (string[] args)
93                 {
94                         int from = this.foo;
95                         Console.WriteLine (args [from]);
96                 }               
97         }
98         
99         class D
100         {
101                 public bool check (object from, object to)
102                 {
103                         if (from is int && to is int) return true;
104                                 return false;
105                 }
106         }
107 }
108
109 namespace FromProblems2
110 {
111         class from
112         {
113         }
114         
115         class C
116         {
117                 void M1 ()
118                 {
119                         from local = new from ();
120                 }
121                 
122                 from M2 ()
123                 {
124                         return null;
125                 }
126         }
127 }
128