OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Dart test program for testing params. | |
5 | |
6 // Convenience values. | |
7 var c = new C(); | |
8 var x = 42; | |
9 var y = 42; | |
10 var z = 42; | |
11 | |
12 // Trailing comma in parameter litss. | |
13 | |
14 // Typedefs. | |
15 typedef fx(x, ); | |
16 typedef fy([y,]); | |
17 typedef fxy(x, [y, ]); | |
18 typedef fz({z,}); | |
19 typedef fxz(x, {z, }); | |
20 | |
21 // As arguments type. | |
22 argfx(void f(x, )) {} | |
23 argfy(void f([y, ])) {} | |
24 argfxy(void f(x, [y, ])) {} | |
25 argfz(void f({z, })) {} | |
26 argfxz(void f(x, {z, })) {} | |
27 | |
28 // Top level functions | |
29 void topx(x,) {} | |
30 void topy([y, ]) {} | |
31 void topxy(x, [y, ]) {} | |
32 void topz({z, }) {} | |
33 void topxz(x, {z, }) {} | |
34 | |
35 void set topsetx(x, ) {} | |
36 | |
37 // After specific parameter formats. | |
38 void afterDefaultValueY([int y = 42, ]) {} | |
39 void afterDefaultValueZ({int z : 42, }) {} | |
40 void afterFunsigX(int f(),) {} | |
41 void afterFunsigY([int f(),]) {} | |
42 void afterFunsigZ({int f(),}) {} | |
43 void afterFunctionSignatre([int f(), ]) {} | |
44 | |
45 class C { | |
46 C(); | |
47 | |
48 // Constructors. | |
49 C.x(x, ); | |
50 C.y([y, ]); | |
51 C.xy(x, [y, ]); | |
52 C.z({z, }); | |
53 C.xz(x, {z, }); | |
54 | |
55 // Static members | |
56 static void staticx(x,) {} | |
57 static void staticy([y, ]) {} | |
58 static void staticxy(x, [y, ]) {} | |
59 static void staticz({z, }) {} | |
60 static void staticxz(x, {z, }) {} | |
61 | |
62 static void set staticsetx(x, ) {} | |
63 | |
64 // Instance members | |
65 void instancex(x,) {} | |
66 void instancey([y, ]) {} | |
67 void instancexy(x, [y, ]) {} | |
68 void instancez({z, }) {} | |
69 void instancexz(x, {z, }) {} | |
70 | |
71 void set instancesetx(x, ) {} | |
72 | |
73 operator +(x, ) => this; | |
74 operator []=(x, y, ) {} | |
75 } | |
76 | |
77 main(args, ) { | |
78 // Check that all functions can be called normally | |
79 topx(x); | |
80 topy(y); | |
81 topxy(x, y); | |
82 topz(); | |
83 topz(z: z); | |
84 topxz(x); | |
85 topxz(x, z: z); | |
86 topsetx = x; | |
87 afterDefaultValueY(); | |
88 afterDefaultValueY(y); | |
89 afterDefaultValueZ(); | |
90 afterDefaultValueZ(z: z); | |
91 new C.x(x); | |
92 new C.xy(x); | |
93 new C.xy(x, y); | |
94 new C.y(y); | |
95 new C.xz(x); | |
96 new C.xz(x, z: z); | |
97 new C.z(z: z); | |
98 C.staticx(x); | |
99 C.staticy(y); | |
100 C.staticxy(x); | |
101 C.staticxy(x, y); | |
102 C.staticz(); | |
103 C.staticz(z: z); | |
104 C.staticxz(x); | |
105 C.staticxz(x, z: z); | |
106 C.staticsetx = x; | |
107 c.instancex(x); | |
108 c.instancey(); | |
109 c.instancey(y); | |
110 c.instancexy(x); | |
111 c.instancexy(x, y); | |
112 c.instancez(); | |
113 c.instancez(z: z); | |
114 c.instancexz(x); | |
115 c.instancexz(x, z: z); | |
116 c.instancesetx = x; | |
117 c + x; | |
118 c[x] = y; | |
119 | |
120 // Call with ekstra comma (not possible for setters and operators). | |
hausner
2016/06/22 17:19:41
Dijkstra style comment :-)
Lasse Reichstein Nielsen
2016/06/24 11:50:55
I regret nothing!
| |
121 topx(x, ); | |
122 topy(y, ); | |
123 topxy(x, y, ); | |
124 topxy(x, ); | |
125 topz(z: z, ); | |
126 topxz(x, ); | |
127 topxz(x, z: z, ); | |
128 new C.x(x, ); | |
129 new C.xy(x, y, ); | |
130 new C.xy(x, ); | |
131 new C.y(y, ); | |
132 new C.xz(x, ); | |
133 new C.xz(x, z: z, ); | |
134 new C.z(z: z, ); | |
135 C.staticx(x, ); | |
136 C.staticy(y, ); | |
137 C.staticxy(x, y, ); | |
138 C.staticxy(x, ); | |
139 C.staticz(z: z, ); | |
140 C.staticxz(x, ); | |
141 C.staticxz(x, z: z, ); | |
142 c.instancex(x, ); | |
143 c.instancey(y, ); | |
144 c.instancexy(x, y, ); | |
145 c.instancexy(x, ); | |
146 c.instancez(z: z, ); | |
147 c.instancexz(x, ); | |
148 c.instancexz(x, z: z, ); | |
149 | |
150 // Typedefs work. | |
151 if (topx is! fx) throw "Bad type: $fx"; | |
152 if (topy is! fy) throw "Bad type: $fy"; | |
153 if (topxy is! fxy) throw "Bad type: $fxy"; | |
154 if (topz is! fz) throw "Bad type: $fz"; | |
155 if (topxz is! fxz) throw "Bad type: $fxz"; | |
156 | |
157 // Parameter types work (checked mode only test). | |
158 argfx(topx); | |
159 argfy(topy); | |
160 argfxy(topxy); | |
161 argfz(topz); | |
162 argfxz(topxz); | |
163 | |
164 // Make sure the Bad class is parsed. | |
165 new Bad().method(); | |
166 } | |
167 | |
168 | |
169 // Invalid syntax | |
170 void topBadEmpty(,) {} /// 01: compile-time error | |
floitsch
2016/06/22 18:23:38
In theory, you would have a better test, if you on
Lasse Reichstein Nielsen
2016/06/24 11:50:55
True, that would ensure that some other unintended
| |
171 void topBadStart(, a) {} /// 02: compile-time error | |
172 void topBadEnd(a,,) {} /// 03: compile-time error | |
173 void topBadMiddle(a,, b) {} /// 04: compile-time error | |
174 void topBadPosEmpty([,]) {} /// 01: compile-time error | |
175 void topBadPosStart([, a]) {} /// 02: compile-time error | |
176 void topBadPosEnd([a,,]) {} /// 03: compile-time error | |
177 void topBadPosMiddle({a,, b}) {} /// 04: compile-time error | |
178 void topBadPosEmpty({,}) {} /// 01: compile-time error | |
179 void topBadPosStart({, a}) {} /// 02: compile-time error | |
180 void topBadPosEnd({a,,}) {} /// 03: compile-time error | |
181 void topBadPosMiddle([a,, b]) {} /// 04: compile-time error | |
182 void set topSetBadEmpty(,) {} /// 05: compile-time error | |
183 void set topSetBadStart(, a) {} /// 06: compile-time error | |
184 void set topSetBadEnd(a,,) {} /// 07: compile-time error | |
185 void set topSetBadMiddle(a,, b) {} /// 08: compile-time error | |
186 class Bad { | |
187 Bad.empty(,) {} /// 09: compile-time error | |
188 Bad.start(, a) {} /// 10: compile-time error | |
189 Bad.end(a,,) {} /// 11: compile-time error | |
190 Bad.middle(a,, b) {} /// 12: compile-time error | |
191 static staticBadEmpty(,) {} /// 13: compile-time error | |
192 static staticBadStart(, a) {} /// 14: compile-time error | |
193 static staticBadEnd(a,,) {} /// 15: compile-time error | |
194 static staticBadMiddle(a,, b) {} /// 16: compile-time error | |
195 static void set staticSetBadEmpty(,) {} /// 17: compile-time error | |
196 static void set staticSetBadStart(, a) {} /// 18: compile-time error | |
197 static void set staticSetBadEnd(a,,) {} /// 19: compile-time error | |
198 static void set staticSetBadMiddle(a,, b) {} /// 20: compile-time error | |
199 instanceBadEmpty(,) {} /// 21: compile-time error | |
200 instanceBadStart(, a) {} /// 22: compile-time error | |
201 instanceBadEnd(a,,) {} /// 23: compile-time error | |
202 instanceBadMiddle(a,, b) {} /// 24: compile-time error | |
203 void set instanceSetBadEmpty(,) {} /// 25: compile-time error | |
204 void set instanceSetBadStart(, a) {} /// 26: compile-time error | |
205 void set instanceSetBadEnd(a,,) {} /// 27: compile-time error | |
206 void set instanceSetBadMiddle(a,, b) {} /// 28: compile-time error | |
207 void operator *(,); /// 29: compile-time error | |
208 void operator *(, a); /// 30: compile-time error | |
209 void operator *(a,,); /// 31: compile-time error | |
210 void operator []=(, a); /// 32: compile-time error | |
211 void operator []=(a,,); /// 33: compile-time error | |
212 void operator []=(a,, b); /// 34: compile-time error | |
213 void operator []=(a,); /// 35: compile-time error | |
214 | |
215 method() { | |
216 // invalid calls. | |
217 | |
218 topx(,); /// 36: compile-time error | |
219 topy(,); /// 37: compile-time error | |
220 topz(,); /// 38: compile-time error | |
221 topx(, x); /// 39: compile-time error | |
222 topz(, z:z); /// 40: compile-time error | |
223 topxy(x,, y); /// 41: compile-time error | |
224 topxz(x,, z:z); /// 42: compile-time error | |
225 topx(x,,); /// 43: compile-time error | |
226 topz(z:z,,); /// 44: compile-time error | |
227 | |
228 new C.x(,); /// 45: compile-time error | |
229 new C.y(,); /// 46: compile-time error | |
230 new C.z(,); /// 47: compile-time error | |
231 new C.x(, x); /// 48: compile-time error | |
232 new C.z(, z:z); /// 49: compile-time error | |
233 new C.xy(x,, y); /// 50: compile-time error | |
234 new C.xz(x,, z:z); /// 51: compile-time error | |
235 new C.x(x,,); /// 52: compile-time error | |
236 new C.z(z:z,,); /// 53: compile-time error | |
237 | |
238 C.staticx(,); /// 54: compile-time error | |
239 C.staticy(,); /// 55: compile-time error | |
240 C.staticz(,); /// 56: compile-time error | |
241 C.staticx(, x); /// 57: compile-time error | |
242 C.staticz(, z:z); /// 58: compile-time error | |
243 C.staticxy(x,, y); /// 59: compile-time error | |
244 C.staticxz(x,, z:z); /// 60: compile-time error | |
245 C.staticx(x,,); /// 61: compile-time error | |
246 C.staticz(z:z,,); /// 62: compile-time error | |
247 | |
248 c.instancex(,); /// 63: compile-time error | |
249 c.instancey(,); /// 64: compile-time error | |
250 c.instancez(,); /// 65: compile-time error | |
251 c.instancex(, x); /// 66: compile-time error | |
252 c.instancez(, z:z); /// 67: compile-time error | |
253 c.instancexy(x,, y); /// 68: compile-time error | |
254 c.instancexz(x,, z:z); /// 69: compile-time error | |
255 c.instancex(x,,); /// 70: compile-time error | |
256 c.instancez(z:z,,); /// 71: compile-time error | |
257 | |
258 c[x,] = y; /// 72: compile-time error | |
259 } | |
260 } | |
OLD | NEW |