Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-tuple-05.cs
1 //
2 // tuple names attribute decoration
3 //
4
5 using System;
6 using System.Collections;
7 using System.Runtime.CompilerServices;
8 using System.Collections.Generic;
9 using System.Linq;
10
11 interface I<T>
12 {
13 }
14
15 class B<T>
16 {
17 }
18
19 class C // : B<(int a, int b)> // TODO: I<(a, b)
20 {
21     public C((int a, int b) d)
22     {
23     }
24
25     public (int a, int b) a;
26     public (int, (int a, int b)) c;
27
28     public (int a, int b) Prop { set; get; }
29     public (int a, int b) Prop2 { set { } }
30
31     public (int a, int b)? this[(int a, int b) d] { set { } get { return null; } }
32
33     public (int a, int b)? Method(ref (int a, int b) d)
34     {
35         return null;
36     }
37
38     public (int a, int b)[] t;
39     public (int a, int b)[,] t2;
40     // TODO:    public Func<(int a, int b), int, (int c, int d)[]> v;
41     //    public I<(int a, int b)>[] iface;
42     // TODO:    public Action<(long, (long u, long))[], object, (int a, int b)> d2;
43     public (((int aa1, int aa2) a1, (int, int) a2) x1, ((int cc1, int cc2) b1, (int dd1, int dd2) b2) x2) d3;
44 }
45
46 delegate (int a, int b) Del((int a, int b) d);
47
48 class Test
49 {
50     public static int Main()
51     {
52         Type t = typeof(C);
53         Type ca = typeof(TupleElementNamesAttribute);
54         TupleElementNamesAttribute da;
55
56         if (t.GetMember("a")[0].GetCustomAttributes(ca, false).Length != 1)
57             return 1;
58
59         if (t.GetMember("c")[0].GetCustomAttributes(ca, false).Length != 1)
60             return 3;
61
62         if (t.GetMember("Prop")[0].GetCustomAttributes(ca, false).Length != 1)
63             return 4;
64
65         if (t.GetMember("get_Prop")[0].GetCustomAttributes(ca, false).Length != 0)
66             return 5;
67
68         if (t.GetMethod("get_Prop").ReturnParameter.GetCustomAttributes(ca, false).Length != 1)
69             return 6;
70
71         if (t.GetMember("set_Prop")[0].GetCustomAttributes(ca, false).Length != 0)
72             return 7;
73
74         if (t.GetMethod("set_Prop").ReturnParameter.GetCustomAttributes(ca, false).Length != 0)
75             return 8;
76
77         if (t.GetMethod("set_Prop").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
78             return 9;
79
80         if (t.GetMember("Prop2")[0].GetCustomAttributes(ca, false).Length != 1)
81             return 10;
82
83         if (t.GetMember("set_Prop2")[0].GetCustomAttributes(ca, false).Length != 0)
84             return 11;
85
86         if (t.GetMember("Item")[0].GetCustomAttributes(ca, false).Length != 1)
87             return 12;
88
89         if (t.GetMethod("get_Item").ReturnParameter.GetCustomAttributes(ca, false).Length != 1)
90             return 13;
91
92         if (t.GetMethod("get_Item").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
93             return 14;
94
95         if (t.GetMethod("set_Item").ReturnParameter.GetCustomAttributes(ca, false).Length != 0)
96             return 15;
97
98         if (t.GetMethod("set_Item").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
99             return 16;
100
101         if (t.GetMethod("set_Item").GetParameters()[1].GetCustomAttributes(ca, false).Length != 1)
102             return 17;
103
104         if (t.GetMember("Method")[0].GetCustomAttributes(ca, false).Length != 0)
105             return 18;
106
107         var res = t.GetMethod("Method").GetParameters()[0].GetCustomAttributes(ca, false);
108         if (res.Length != 1)
109             return 19;
110
111         da = res[0] as TupleElementNamesAttribute;
112         if (da == null)
113             return 190;
114         if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
115             return 191;
116
117         if (t.GetConstructors()[0].GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
118             return 20;
119
120         if (t.GetConstructors()[0].GetCustomAttributes(ca, false).Length != 0)
121             return 21;
122
123         //        if (t.GetCustomAttributes(ca, false).Length != 1)
124         //            return 22;
125
126         // Transformations
127         da = t.GetMember("t")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
128         if (da == null)
129             return 40;
130
131         if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
132             return 41;
133
134         da = t.GetMember("t2")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
135         if (da == null)
136             return 42;
137
138         if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
139             return 43;
140
141         //da = t.GetMember("v")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
142         //if (da == null)
143         //    return 44;
144
145         //if (!da.TransformNames.SequenceEqual(new string[] { "a", "b", "c", "d" }))
146         //    return 45;
147
148         //da = t.GetMember("iface")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
149         //if (da == null)
150         //    return 46;
151
152         //if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
153         //    return 47;
154
155         //da = t.GetMember("d2")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
156         //if (da == null)
157         //    return 48;
158         //if (!da.TransformNames.SequenceEqual(new string[] { null, null, "u", null, "a", "b" }))
159         //    return 49;
160
161         da = t.GetMember("d3")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
162         if (da == null)
163             return 50;
164         if (!da.TransformNames.SequenceEqual(new string[] { "x1", "x2", "a1", "a2", "aa1", "aa2", null, null, "b1", "b2", "cc1", "cc2", "dd1", "dd2" }))
165             return 51;
166
167         t = typeof(Del);
168
169         if (t.GetMember("Invoke")[0].GetCustomAttributes(ca, false).Length != 0)
170             return 100;
171
172         if (t.GetMethod("Invoke").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
173             return 101;
174
175         if (t.GetMethod("Invoke").ReturnParameter.GetCustomAttributes(ca, false).Length != 1)
176             return 102;
177
178         Console.WriteLine("ok");
179         return 0;
180     }
181 }