OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Tests function statement and expression syntax. | 7 // Tests function statement and expression syntax. |
8 | 8 |
9 class FunctionSyntaxTest { | 9 class FunctionSyntaxTest { |
| 10 |
10 static void testMain | 11 static void testMain |
11 /* //# 00: compile-time error | 12 /* //# 00: compile-time error |
12 () | 13 () |
13 */ //# 00: continued | 14 */ //# 00: continued |
14 { | 15 { |
15 testNestedFunctions(); | 16 testNestedFunctions(); |
16 testFunctionExpressions(); | 17 testFunctionExpressions(); |
17 testPrecedence(); | 18 testPrecedence(); |
18 testInitializers(); | 19 testInitializers(); |
19 testFunctionParameter(); | 20 testFunctionParameter(); |
20 testFunctionIdentifierExpression(); | 21 testFunctionIdentifierExpression(); |
21 testFunctionIdentifierStatement(); | 22 testFunctionIdentifierStatement(); |
22 } | 23 } |
23 | 24 |
24 static void testNestedFunctions | 25 static void testNestedFunctions |
25 /* //# 01: compile-time error | 26 /* //# 01: compile-time error |
26 () | 27 () |
27 */ //# 01: continued | 28 */ //# 01: continued |
28 { | 29 { |
29 // No types - braces. | 30 // No types - braces. |
30 nb0 | 31 nb0 |
31 /* //# 02: compile-time error | 32 /* //# 02: compile-time error |
32 () | 33 () |
33 */ //# 02: continued | 34 */ //# 02: continued |
34 { | 35 { return 42; } |
35 return 42; | |
36 } | |
37 | |
38 nb1 | 36 nb1 |
39 /* //# 03: compile-time error | 37 /* //# 03: compile-time error |
40 (a) | 38 (a) |
41 */ //# 03: continued | 39 */ //# 03: continued |
42 { | 40 { return a; } |
43 return a; | |
44 } | |
45 | |
46 nb2 | 41 nb2 |
47 /* //# 04: compile-time error | 42 /* //# 04: compile-time error |
48 (a, b) | 43 (a, b) |
49 */ //# 04: continued | 44 */ //# 04: continued |
50 { | 45 { return a + b; } |
51 return a + b; | |
52 } | |
53 | |
54 Expect.equals(42, nb0()); | 46 Expect.equals(42, nb0()); |
55 Expect.equals(87, nb1(87)); | 47 Expect.equals(87, nb1(87)); |
56 Expect.equals(1 + 2, nb2(1, 2)); | 48 Expect.equals(1 + 2, nb2(1, 2)); |
57 | 49 |
58 // No types - arrows. | 50 // No types - arrows. |
59 na0 | 51 na0 |
60 /* //# 05: compile-time error | 52 /* //# 05: compile-time error |
61 () | 53 () |
62 */ //# 05: continued | 54 */ //# 05: continued |
63 => | 55 => 42; |
64 42; | |
65 na1 | 56 na1 |
66 /* //# 06: compile-time error | 57 /* //# 06: compile-time error |
67 (a) | 58 (a) |
68 */ //# 06: continued | 59 */ //# 06: continued |
69 => | 60 => a; |
70 a; | |
71 na2 | 61 na2 |
72 /* //# 07: compile-time error | 62 /* //# 07: compile-time error |
73 (a, b) | 63 (a, b) |
74 */ //# 07: continued | 64 */ //# 07: continued |
75 => | 65 => a + b; |
76 a + b; | |
77 Expect.equals(42, na0()); | 66 Expect.equals(42, na0()); |
78 Expect.equals(87, na1(87)); | 67 Expect.equals(87, na1(87)); |
79 Expect.equals(1 + 2, na2(1, 2)); | 68 Expect.equals(1 + 2, na2(1, 2)); |
80 | 69 |
81 // Return type - braces. | 70 // Return type - braces. |
82 int rb0 | 71 int rb0 |
83 /* //# 08: compile-time error | 72 /* //# 08: compile-time error |
84 () | 73 () |
85 */ //# 08: continued | 74 */ //# 08: continued |
86 { | 75 { return 42; } |
87 return 42; | |
88 } | |
89 | |
90 int rb1 | 76 int rb1 |
91 /* //# 09: compile-time error | 77 /* //# 09: compile-time error |
92 (a) | 78 (a) |
93 */ //# 09: continued | 79 */ //# 09: continued |
94 { | 80 { return a; } |
95 return a; | |
96 } | |
97 | |
98 int rb2 | 81 int rb2 |
99 /* //# 10: compile-time error | 82 /* //# 10: compile-time error |
100 (a, b) | 83 (a, b) |
101 */ //# 10: continued | 84 */ //# 10: continued |
102 { | 85 { return a + b; } |
103 return a + b; | |
104 } | |
105 | |
106 Expect.equals(42, rb0()); | 86 Expect.equals(42, rb0()); |
107 Expect.equals(87, rb1(87)); | 87 Expect.equals(87, rb1(87)); |
108 Expect.equals(1 + 2, rb2(1, 2)); | 88 Expect.equals(1 + 2, rb2(1, 2)); |
109 | 89 |
110 // Return type - arrows. | 90 // Return type - arrows. |
111 int ra0 | 91 int ra0 |
112 /* //# 11: compile-time error | 92 /* //# 11: compile-time error |
113 () | 93 () |
114 */ //# 11: continued | 94 */ //# 11: continued |
115 => | 95 => 42; |
116 42; | |
117 int ra1 | 96 int ra1 |
118 /* //# 12: compile-time error | 97 /* //# 12: compile-time error |
119 (a) | 98 (a) |
120 */ //# 12: continued | 99 */ //# 12: continued |
121 => | 100 => a; |
122 a; | |
123 int ra2 | 101 int ra2 |
124 /* //# 13: compile-time error | 102 /* //# 13: compile-time error |
125 (a, b) | 103 (a, b) |
126 */ //# 13: continued | 104 */ //# 13: continued |
127 => | 105 => a + b; |
128 a + b; | |
129 Expect.equals(42, ra0()); | 106 Expect.equals(42, ra0()); |
130 Expect.equals(87, ra1(87)); | 107 Expect.equals(87, ra1(87)); |
131 Expect.equals(1 + 2, ra2(1, 2)); | 108 Expect.equals(1 + 2, ra2(1, 2)); |
132 | 109 |
133 // Fully typed - braces. | 110 // Fully typed - braces. |
134 int fb1 | 111 int fb1 |
135 /* //# 14: compile-time error | 112 /* //# 14: compile-time error |
136 (int a) | 113 (int a) |
137 */ //# 14: continued | 114 */ //# 14: continued |
138 { | 115 { return a; } |
139 return a; | |
140 } | |
141 | |
142 int fb2 | 116 int fb2 |
143 /* //# 15: compile-time error | 117 /* //# 15: compile-time error |
144 (int a, int b) | 118 (int a, int b) |
145 */ //# 15: continued | 119 */ //# 15: continued |
146 { | 120 { return a + b; } |
147 return a + b; | |
148 } | |
149 | |
150 Expect.equals(42, rb0()); | 121 Expect.equals(42, rb0()); |
151 Expect.equals(87, rb1(87)); | 122 Expect.equals(87, rb1(87)); |
152 Expect.equals(1 + 2, rb2(1, 2)); | 123 Expect.equals(1 + 2, rb2(1, 2)); |
153 | 124 |
154 // Fully typed - arrows. | 125 // Fully typed - arrows. |
155 int fa1 | 126 int fa1 |
156 /* //# 16: compile-time error | 127 /* //# 16: compile-time error |
157 (int a) | 128 (int a) |
158 */ //# 16: continued | 129 */ //# 16: continued |
159 => | 130 => a; |
160 a; | |
161 int fa2 | 131 int fa2 |
162 /* //# 17: compile-time error | 132 /* //# 17: compile-time error |
163 (int a, int b) | 133 (int a, int b) |
164 */ //# 17: continued | 134 */ //# 17: continued |
165 => | 135 => a + b; |
166 a + b; | |
167 Expect.equals(42, ra0()); | 136 Expect.equals(42, ra0()); |
168 Expect.equals(87, ra1(87)); | 137 Expect.equals(87, ra1(87)); |
169 Expect.equals(1 + 2, ra2(1, 2)); | 138 Expect.equals(1 + 2, ra2(1, 2)); |
170 | 139 |
171 // Generic types - braces. | 140 // Generic types - braces. |
172 List<int> gb0 | 141 List<int> gb0 |
173 /* //# 18: compile-time error | 142 /* //# 18: compile-time error |
174 () | 143 () |
175 */ //# 18: continued | 144 */ //# 18: continued |
176 { | 145 { return [42]; } |
177 return [42]; | |
178 } | |
179 | |
180 List<int> gb1 | 146 List<int> gb1 |
181 /* //# 19: compile-time error | 147 /* //# 19: compile-time error |
182 (List<int> a) | 148 (List<int> a) |
183 */ //# 19: continued | 149 */ //# 19: continued |
184 { | 150 { return a; } |
185 return a; | |
186 } | |
187 | |
188 Expect.equals(42, gb0()[0]); | 151 Expect.equals(42, gb0()[0]); |
189 Expect.equals(87, gb1([87])[0]); | 152 Expect.equals(87, gb1([87])[0]); |
190 | 153 |
191 // Generic types - arrows. | 154 // Generic types - arrows. |
192 List<int> ga0 | 155 List<int> ga0 |
193 /* //# 20: compile-time error | 156 /* //# 20: compile-time error |
194 () | 157 () |
195 */ //# 20: continued | 158 */ //# 20: continued |
196 => | 159 => [42]; |
197 [42]; | |
198 List<int> ga1 | 160 List<int> ga1 |
199 /* //# 21: compile-time error | 161 /* //# 21: compile-time error |
200 (List<int> a) | 162 (List<int> a) |
201 */ //# 21: continued | 163 */ //# 21: continued |
202 => | 164 => a; |
203 a; | |
204 Expect.equals(42, ga0()[0]); | 165 Expect.equals(42, ga0()[0]); |
205 Expect.equals(87, ga1([87])[0]); | 166 Expect.equals(87, ga1([87])[0]); |
206 } | 167 } |
207 | 168 |
208 static void testFunctionExpressions | 169 static void testFunctionExpressions |
209 /* //# 22: compile-time error | 170 /* //# 22: compile-time error |
210 () | 171 () |
211 */ //# 22: continued | 172 */ //# 22: continued |
212 { | 173 { |
213 eval0 | 174 eval0 |
214 /* //# 23: compile-time error | 175 /* //# 23: compile-time error |
215 (fn) | 176 (fn) |
216 */ //# 23: continued | 177 */ //# 23: continued |
217 => | 178 => fn(); |
218 fn(); | |
219 eval1 | 179 eval1 |
220 /* //# 24: compile-time error | 180 /* //# 24: compile-time error |
221 (fn, a) | 181 (fn, a) |
222 */ //# 24: continued | 182 */ //# 24: continued |
223 => | 183 => fn(a); |
224 fn(a); | |
225 eval2 | 184 eval2 |
226 /* //# 25: compile-time error | 185 /* //# 25: compile-time error |
227 (fn, a, b) | 186 (fn, a, b) |
228 */ //# 25: continued | 187 */ //# 25: continued |
229 => | 188 => fn(a, b); |
230 fn(a, b); | |
231 | 189 |
232 // No types - braces. | 190 // No types - braces. |
233 Expect.equals(42, eval0( | 191 Expect.equals(42, eval0( |
234 /* //# 26: compile-time error | 192 /* //# 26: compile-time error |
235 () | 193 () |
236 */ //# 26: continued | 194 */ //# 26: continued |
237 { | 195 { return 42; })); |
238 return 42; | 196 Expect.equals(87, eval1( |
239 })); | |
240 Expect.equals( | |
241 87, | |
242 eval1( | |
243 /* //# 27: compile-time error | 197 /* //# 27: compile-time error |
244 (a) | 198 (a) |
245 */ //# 27: continued | 199 */ //# 27: continued |
246 { | 200 { return a; }, 87)); |
247 return a; | 201 Expect.equals(1 + 2, eval2( |
248 }, 87)); | |
249 Expect.equals( | |
250 1 + 2, | |
251 eval2( | |
252 /* //# 28: compile-time error | 202 /* //# 28: compile-time error |
253 (a, b) | 203 (a, b) |
254 */ //# 28: continued | 204 */ //# 28: continued |
255 { | 205 { return a + b; }, 1, 2)); |
256 return a + b; | |
257 }, 1, 2)); | |
258 Expect.equals(42, eval0( | 206 Expect.equals(42, eval0( |
259 /* //# 29: compile-time error | 207 /* //# 29: compile-time error |
260 () | 208 () |
261 */ //# 29: continued | 209 */ //# 29: continued |
262 { | 210 { return 42; })); |
263 return 42; | 211 Expect.equals(87, eval1( |
264 })); | |
265 Expect.equals( | |
266 87, | |
267 eval1( | |
268 /* //# 30: compile-time error | 212 /* //# 30: compile-time error |
269 (a) | 213 (a) |
270 */ //# 30: continued | 214 */ //# 30: continued |
271 { | 215 { return a; }, 87)); |
272 return a; | 216 Expect.equals(1 + 2, eval2( |
273 }, 87)); | |
274 Expect.equals( | |
275 1 + 2, | |
276 eval2( | |
277 /* //# 31: compile-time error | 217 /* //# 31: compile-time error |
278 (a, b) | 218 (a, b) |
279 */ //# 31: continued | 219 */ //# 31: continued |
280 { | 220 { return a + b; }, 1, 2)); |
281 return a + b; | |
282 }, 1, 2)); | |
283 | 221 |
284 // No types - arrows. | 222 // No types - arrows. |
285 Expect.equals( | 223 Expect.equals(42, eval0( |
286 42, | |
287 eval0( | |
288 /* //# 32: compile-time error | 224 /* //# 32: compile-time error |
289 () | 225 () |
290 */ //# 32: continued | 226 */ //# 32: continued |
291 => | 227 => 42)); |
292 42)); | 228 Expect.equals(87, eval1( |
293 Expect.equals( | |
294 87, | |
295 eval1( | |
296 /* //# 33: compile-time error | 229 /* //# 33: compile-time error |
297 (a) | 230 (a) |
298 */ //# 33: continued | 231 */ //# 33: continued |
299 => | 232 => a, 87)); |
300 a, | 233 Expect.equals(1 + 2, eval2( |
301 87)); | |
302 Expect.equals( | |
303 1 + 2, | |
304 eval2( | |
305 /* //# 34: compile-time error | 234 /* //# 34: compile-time error |
306 (a, b) | 235 (a, b) |
307 */ //# 34: continued | 236 */ //# 34: continued |
308 => | 237 => a + b, 1, 2)); |
309 a + b, | 238 Expect.equals(42, eval0( |
310 1, | |
311 2)); | |
312 Expect.equals( | |
313 42, | |
314 eval0( | |
315 /* //# 35: compile-time error | 239 /* //# 35: compile-time error |
316 () | 240 () |
317 */ //# 35: continued | 241 */ //# 35: continued |
318 => | 242 => 42)); |
319 42)); | 243 Expect.equals(87, eval1( |
320 Expect.equals( | |
321 87, | |
322 eval1( | |
323 /* //# 36: compile-time error | 244 /* //# 36: compile-time error |
324 (a) | 245 (a) |
325 */ //# 36: continued | 246 */ //# 36: continued |
326 => | 247 => a, 87)); |
327 a, | 248 Expect.equals(1 + 2, eval2( |
328 87)); | |
329 Expect.equals( | |
330 1 + 2, | |
331 eval2( | |
332 /* //# 37: compile-time error | 249 /* //# 37: compile-time error |
333 (a, b) | 250 (a, b) |
334 */ //# 37: continued | 251 */ //# 37: continued |
335 => | 252 => a + b, 1, 2)); |
336 a + b, | |
337 1, | |
338 2)); | |
339 | 253 |
340 // Argument types - braces. | 254 // Argument types - braces. |
341 Expect.equals(42, eval0( | 255 Expect.equals(42, eval0( |
342 /* //# 44: compile-time error | 256 /* //# 44: compile-time error |
343 () | 257 () |
344 */ //# 44: continued | 258 */ //# 44: continued |
345 { | 259 { return 42; })); |
346 return 42; | 260 Expect.equals(87, eval1( |
347 })); | |
348 Expect.equals( | |
349 87, | |
350 eval1( | |
351 /* //# 45: compile-time error | 261 /* //# 45: compile-time error |
352 (int a) | 262 (int a) |
353 */ //# 45: continued | 263 */ //# 45: continued |
354 { | 264 { return a; }, 87)); |
355 return a; | 265 Expect.equals(1 + 2, eval2( |
356 }, 87)); | |
357 Expect.equals( | |
358 1 + 2, | |
359 eval2( | |
360 /* //# 46: compile-time error | 266 /* //# 46: compile-time error |
361 (int a, int b) | 267 (int a, int b) |
362 */ //# 46: continued | 268 */ //# 46: continued |
363 { | 269 { return a + b; }, 1, 2)); |
364 return a + b; | |
365 }, 1, 2)); | |
366 Expect.equals(42, eval0( | 270 Expect.equals(42, eval0( |
367 /* //# 47: compile-time error | 271 /* //# 47: compile-time error |
368 () | 272 () |
369 */ //# 47: continued | 273 */ //# 47: continued |
370 { | 274 { return 42; })); |
371 return 42; | 275 Expect.equals(87, eval1( |
372 })); | |
373 Expect.equals( | |
374 87, | |
375 eval1( | |
376 /* //# 48: compile-time error | 276 /* //# 48: compile-time error |
377 (int a) | 277 (int a) |
378 */ //# 48: continued | 278 */ //# 48: continued |
379 { | 279 { return a; }, 87)); |
380 return a; | 280 Expect.equals(1 + 2, eval2( |
381 }, 87)); | |
382 Expect.equals( | |
383 1 + 2, | |
384 eval2( | |
385 /* //# 49: compile-time error | 281 /* //# 49: compile-time error |
386 (int a, int b) | 282 (int a, int b) |
387 */ //# 49: continued | 283 */ //# 49: continued |
388 { | 284 { return a + b; }, 1, 2)); |
389 return a + b; | |
390 }, 1, 2)); | |
391 | 285 |
392 // Argument types - arrows. | 286 // Argument types - arrows. |
393 Expect.equals( | 287 Expect.equals(42, eval0( |
394 42, | |
395 eval0( | |
396 /* //# 50: compile-time error | 288 /* //# 50: compile-time error |
397 () | 289 () |
398 */ //# 50: continued | 290 */ //# 50: continued |
399 => | 291 => 42)); |
400 42)); | 292 Expect.equals(87, eval1( |
401 Expect.equals( | |
402 87, | |
403 eval1( | |
404 /* //# 51: compile-time error | 293 /* //# 51: compile-time error |
405 (int a) | 294 (int a) |
406 */ //# 51: continued | 295 */ //# 51: continued |
407 => | 296 => a, 87)); |
408 a, | 297 Expect.equals(1 + 2, eval2( |
409 87)); | |
410 Expect.equals( | |
411 1 + 2, | |
412 eval2( | |
413 /* //# 52: compile-time error | 298 /* //# 52: compile-time error |
414 (int a, int b) | 299 (int a, int b) |
415 */ //# 52: continued | 300 */ //# 52: continued |
416 => | 301 => a + b, 1, 2)); |
417 a + b, | 302 Expect.equals(42, eval0( |
418 1, | |
419 2)); | |
420 Expect.equals( | |
421 42, | |
422 eval0( | |
423 /* //# 53: compile-time error | 303 /* //# 53: compile-time error |
424 () | 304 () |
425 */ //# 53: continued | 305 */ //# 53: continued |
426 => | 306 => 42)); |
427 42)); | 307 Expect.equals(87, eval1( |
428 Expect.equals( | |
429 87, | |
430 eval1( | |
431 /* //# 54: compile-time error | 308 /* //# 54: compile-time error |
432 (int a) | 309 (int a) |
433 */ //# 54: continued | 310 */ //# 54: continued |
434 => | 311 => a, 87)); |
435 a, | 312 Expect.equals(1 + 2, eval2( |
436 87)); | |
437 Expect.equals( | |
438 1 + 2, | |
439 eval2( | |
440 /* //# 55: compile-time error | 313 /* //# 55: compile-time error |
441 (int a, int b) | 314 (int a, int b) |
442 */ //# 55: continued | 315 */ //# 55: continued |
443 => | 316 => a + b, 1, 2)); |
444 a + b, | 317 |
445 1, | |
446 2)); | |
447 } | 318 } |
448 | 319 |
449 static void testPrecedence | 320 static void testPrecedence |
450 /* //# 64: compile-time error | 321 /* //# 64: compile-time error |
451 () | 322 () |
452 */ //# 64: continued | 323 */ //# 64: continued |
453 { | 324 { |
454 expectEvaluatesTo | 325 expectEvaluatesTo |
455 /* //# 65: compile-time error | 326 /* //# 65: compile-time error |
456 (value, fn) | 327 (value, fn) |
457 */ //# 65: continued | 328 */ //# 65: continued |
458 { | 329 { Expect.equals(value, fn()); } |
459 Expect.equals(value, fn()); | |
460 } | |
461 | 330 |
462 // Assignment. | 331 // Assignment. |
463 var x; | 332 var x; |
464 expectEvaluatesTo(42, () => x = 42); | 333 expectEvaluatesTo(42, ()=> x = 42); |
465 Expect.equals(42, x); | 334 Expect.equals(42, x); |
466 x = 1; | 335 x = 1; |
467 expectEvaluatesTo(100, () => x += 99); | 336 expectEvaluatesTo(100, ()=> x += 99); |
468 Expect.equals(100, x); | 337 Expect.equals(100, x); |
469 x = 1; | 338 x = 1; |
470 expectEvaluatesTo(87, () => x *= 87); | 339 expectEvaluatesTo(87, ()=> x *= 87); |
471 Expect.equals(87, x); | 340 Expect.equals(87, x); |
472 | 341 |
473 // Conditional. | 342 // Conditional. |
474 expectEvaluatesTo(42, () => true ? 42 : 87); | 343 expectEvaluatesTo(42, ()=> true ? 42 : 87); |
475 expectEvaluatesTo(87, () => false ? 42 : 87); | 344 expectEvaluatesTo(87, ()=> false ? 42 : 87); |
476 | 345 |
477 // Logical or. | 346 // Logical or. |
478 expectEvaluatesTo(true, () => true || true); | 347 expectEvaluatesTo(true, ()=> true || true); |
479 expectEvaluatesTo(true, () => true || false); | 348 expectEvaluatesTo(true, ()=> true || false); |
480 expectEvaluatesTo(true, () => false || true); | 349 expectEvaluatesTo(true, ()=> false || true); |
481 expectEvaluatesTo(false, () => false || false); | 350 expectEvaluatesTo(false, ()=> false || false); |
482 | 351 |
483 // Logical and. | 352 // Logical and. |
484 expectEvaluatesTo(true, () => true && true); | 353 expectEvaluatesTo(true, ()=> true && true); |
485 expectEvaluatesTo(false, () => true && false); | 354 expectEvaluatesTo(false, ()=> true && false); |
486 expectEvaluatesTo(false, () => false && true); | 355 expectEvaluatesTo(false, ()=> false && true); |
487 expectEvaluatesTo(false, () => false && false); | 356 expectEvaluatesTo(false, ()=> false && false); |
488 | 357 |
489 // Bitwise operations. | 358 // Bitwise operations. |
490 expectEvaluatesTo(3, () => 1 | 2); | 359 expectEvaluatesTo(3, ()=> 1 | 2); |
491 expectEvaluatesTo(2, () => 3 ^ 1); | 360 expectEvaluatesTo(2, ()=> 3 ^ 1); |
492 expectEvaluatesTo(1, () => 3 & 1); | 361 expectEvaluatesTo(1, ()=> 3 & 1); |
493 | 362 |
494 // Equality. | 363 // Equality. |
495 expectEvaluatesTo(true, () => 1 == 1); | 364 expectEvaluatesTo(true, ()=> 1 == 1); |
496 expectEvaluatesTo(false, () => 1 != 1); | 365 expectEvaluatesTo(false, ()=> 1 != 1); |
497 expectEvaluatesTo(true, () => identical(1, 1)); | 366 expectEvaluatesTo(true, ()=> identical(1, 1)); |
498 expectEvaluatesTo(false, () => !identical(1, 1)); | 367 expectEvaluatesTo(false, ()=> !identical(1, 1)); |
499 | 368 |
500 // Relational. | 369 // Relational. |
501 expectEvaluatesTo(true, () => 1 <= 1); | 370 expectEvaluatesTo(true, ()=> 1 <= 1); |
502 expectEvaluatesTo(false, () => 1 < 1); | 371 expectEvaluatesTo(false, ()=> 1 < 1); |
503 expectEvaluatesTo(false, () => 1 > 1); | 372 expectEvaluatesTo(false, ()=> 1 > 1); |
504 expectEvaluatesTo(true, () => 1 >= 1); | 373 expectEvaluatesTo(true, ()=> 1 >= 1); |
505 | 374 |
506 // Is. | 375 // Is. |
507 expectEvaluatesTo(true, () => 1 is int); | 376 expectEvaluatesTo(true, ()=> 1 is int); |
508 expectEvaluatesTo(true, () => 1.0 is double); | 377 expectEvaluatesTo(true, ()=> 1.0 is double); |
509 | 378 |
510 // Shift. | 379 // Shift. |
511 expectEvaluatesTo(2, () => 1 << 1); | 380 expectEvaluatesTo(2, ()=> 1 << 1); |
512 expectEvaluatesTo(1, () => 2 >> 1); | 381 expectEvaluatesTo(1, ()=> 2 >> 1); |
513 | 382 |
514 // Additive. | 383 // Additive. |
515 expectEvaluatesTo(2, () => 1 + 1); | 384 expectEvaluatesTo(2, ()=> 1 + 1); |
516 expectEvaluatesTo(1, () => 2 - 1); | 385 expectEvaluatesTo(1, ()=> 2 - 1); |
517 | 386 |
518 // Multiplicative. | 387 // Multiplicative. |
519 expectEvaluatesTo(2, () => 1 * 2); | 388 expectEvaluatesTo(2, ()=> 1 * 2); |
520 expectEvaluatesTo(2.0, () => 4 / 2); | 389 expectEvaluatesTo(2.0, ()=> 4 / 2); |
521 expectEvaluatesTo(2, () => 4 ~/ 2); | 390 expectEvaluatesTo(2, ()=> 4 ~/ 2); |
522 expectEvaluatesTo(0, () => 4 % 2); | 391 expectEvaluatesTo(0, ()=> 4 % 2); |
523 | 392 |
524 // Negate. | 393 // Negate. |
525 expectEvaluatesTo(false, () => !true); | 394 expectEvaluatesTo(false, ()=> !true); |
526 | 395 |
527 // Postfix / prefix. | 396 // Postfix / prefix. |
528 var y = 0; | 397 var y = 0; |
529 expectEvaluatesTo(0, () => y++); | 398 expectEvaluatesTo(0, ()=> y++); |
530 expectEvaluatesTo(2, () => ++y); | 399 expectEvaluatesTo(2, ()=> ++y); |
531 expectEvaluatesTo(1, () => --y); | 400 expectEvaluatesTo(1, ()=> --y); |
532 expectEvaluatesTo(1, () => y--); | 401 expectEvaluatesTo(1, ()=> y--); |
533 Expect.equals(0, y); | 402 Expect.equals(0, y); |
534 | 403 |
535 // Selector. | 404 // Selector. |
536 fn | 405 fn |
537 /* //# 66: compile-time error | 406 /* //# 66: compile-time error |
538 () | 407 () |
539 */ //# 66: continued | 408 */ //# 66: continued |
540 => | 409 => 42; |
541 42; | |
542 var list = [87]; | 410 var list = [87]; |
543 expectEvaluatesTo(42, () => fn()); | 411 expectEvaluatesTo(42, ()=> fn()); |
544 expectEvaluatesTo(1, () => list.length); | 412 expectEvaluatesTo(1, ()=> list.length); |
545 expectEvaluatesTo(87, () => list[0]); | 413 expectEvaluatesTo(87, ()=> list[0]); |
546 expectEvaluatesTo(87, () => list.removeLast()); | 414 expectEvaluatesTo(87, ()=> list.removeLast()); |
547 } | 415 } |
548 | 416 |
549 static void testInitializers | 417 static void testInitializers |
550 /* //# 67: compile-time error | 418 /* //# 67: compile-time error |
551 () | 419 () |
552 */ //# 67: continued | 420 */ //# 67: continued |
553 { | 421 { |
554 Expect.equals(42, (new C.cb0().fn)()); | 422 Expect.equals(42, (new C.cb0().fn)()); |
555 Expect.equals(43, (new C.ca0().fn)()); | 423 Expect.equals(43, (new C.ca0().fn)()); |
556 Expect.equals(44, (new C.cb1().fn)()); | 424 Expect.equals(44, (new C.cb1().fn)()); |
557 Expect.equals(45, (new C.ca1().fn)()); | 425 Expect.equals(45, (new C.ca1().fn)()); |
558 Expect.equals(46, (new C.cb2().fn)()); | 426 Expect.equals(46, (new C.cb2().fn)()); |
559 Expect.equals(47, (new C.ca2().fn)()); | 427 Expect.equals(47, (new C.ca2().fn)()); |
560 Expect.equals(48, (new C.cb3().fn)()); | 428 Expect.equals(48, (new C.cb3().fn)()); |
561 Expect.equals(49, (new C.ca3().fn)()); | 429 Expect.equals(49, (new C.ca3().fn)()); |
562 | 430 |
563 Expect.equals(52, (new C.nb0().fn)()); | 431 Expect.equals(52, (new C.nb0().fn)()); |
(...skipping 10 matching lines...) Expand all Loading... |
574 Expect.equals(64, (new C.rb1().fn)()); | 442 Expect.equals(64, (new C.rb1().fn)()); |
575 Expect.equals(65, (new C.ra1().fn)()); | 443 Expect.equals(65, (new C.ra1().fn)()); |
576 Expect.equals(66, (new C.rb2().fn)()); | 444 Expect.equals(66, (new C.rb2().fn)()); |
577 Expect.equals(67, (new C.ra2().fn)()); | 445 Expect.equals(67, (new C.ra2().fn)()); |
578 Expect.equals(68, (new C.rb3().fn)()); | 446 Expect.equals(68, (new C.rb3().fn)()); |
579 Expect.equals(69, (new C.ra3().fn)()); | 447 Expect.equals(69, (new C.ra3().fn)()); |
580 } | 448 } |
581 | 449 |
582 static void testFunctionParameter | 450 static void testFunctionParameter |
583 /* //# 68: compile-time error | 451 /* //# 68: compile-time error |
584 () | 452 () |
585 */ //# 68: continued | 453 */ //# 68: continued |
586 { | 454 { |
587 f0(fn()) => fn(); | 455 f0(fn()) => fn(); |
588 Expect.equals(42, f0(() => 42)); | 456 Expect.equals(42, f0(()=> 42)); |
589 | 457 |
590 f1(int fn()) => fn(); | 458 f1(int fn()) => fn(); |
591 Expect.equals(87, f1(() => 87)); | 459 Expect.equals(87, f1(()=> 87)); |
592 | 460 |
593 f2(fn(a)) => fn(42); | 461 f2(fn(a)) => fn(42); |
594 Expect.equals(43, f2((a) => a + 1)); | 462 Expect.equals(43, f2((a)=> a + 1)); |
595 | 463 |
596 f3(fn(int a)) => fn(42); | 464 f3(fn(int a)) => fn(42); |
597 Expect.equals(44, f3((int a) => a + 2)); | 465 Expect.equals(44, f3((int a)=> a + 2)); |
598 } | 466 } |
599 | 467 |
600 static void testFunctionIdentifierExpression | 468 static void testFunctionIdentifierExpression |
601 /* //# 69: compile-time error | 469 /* //# 69: compile-time error |
602 () | 470 () |
603 */ //# 69: continued | 471 */ //# 69: continued |
604 { | 472 { |
605 Expect.equals( | 473 Expect.equals(87, ( |
606 87, | |
607 ( | |
608 /* //# 70: compile-time error | 474 /* //# 70: compile-time error |
609 () | 475 () |
610 */ //# 70: continued | 476 */ //# 70: continued |
611 => | 477 => 87)()); |
612 87)()); | |
613 } | 478 } |
614 | 479 |
615 static void testFunctionIdentifierStatement | 480 static void testFunctionIdentifierStatement |
616 /* //# 71: compile-time error | 481 /* //# 71: compile-time error |
617 () | 482 () |
618 */ //# 71: continued | 483 */ //# 71: continued |
619 { | 484 { |
620 function | 485 function |
621 /* //# 72: compile-time error | 486 /* //# 72: compile-time error |
622 () | 487 () |
623 */ //# 72: continued | 488 */ //# 72: continued |
624 => | 489 => 42; |
625 42; | |
626 Expect.equals(42, function()); | 490 Expect.equals(42, function()); |
627 Expect.equals(true, function is Function); | 491 Expect.equals(true, function is Function); |
628 } | 492 } |
| 493 |
629 } | 494 } |
630 | 495 |
| 496 |
631 class C { | 497 class C { |
632 C.cb0() | |
633 : fn = (() { | |
634 return 42; | |
635 }) {} | |
636 C.ca0() : fn = (() => 43) {} | |
637 | 498 |
638 C.cb1() | 499 C.cb0() : fn = (() { return 42; }) { } |
639 : fn = wrap(() { | 500 C.ca0() : fn = (() => 43) { } |
640 return 44; | |
641 }) {} | |
642 C.ca1() : fn = wrap(() => 45) {} | |
643 | 501 |
644 C.cb2() | 502 C.cb1() : fn = wrap(() { return 44; }) { } |
645 : fn = [ | 503 C.ca1() : fn = wrap(()=> 45) { } |
646 () { | |
647 return 46; | |
648 } | |
649 ][0] {} | |
650 C.ca2() : fn = [() => 47][0] {} | |
651 | 504 |
652 C.cb3() | 505 C.cb2() : fn = [() { return 46; }][0] { } |
653 : fn = { | 506 C.ca2() : fn = [() => 47][0] { } |
654 'x': () { | |
655 return 48; | |
656 } | |
657 }['x'] {} | |
658 C.ca3() : fn = {'x': () => 49}['x'] {} | |
659 | 507 |
660 C.nb0() | 508 C.cb3() : fn = {'x': () { return 48; }}['x'] { } |
661 : fn = (() { | 509 C.ca3() : fn = {'x': () => 49}['x'] { } |
662 return 52; | |
663 }) {} | |
664 C.na0() : fn = (() => 53) {} | |
665 | 510 |
666 C.nb1() | 511 C.nb0() : fn = (() { return 52; }) { } |
667 : fn = wrap(() { | 512 C.na0() : fn = (() => 53) { } |
668 return 54; | |
669 }) {} | |
670 C.na1() : fn = wrap(() => 55) {} | |
671 | 513 |
672 C.nb2() | 514 C.nb1() : fn = wrap(() { return 54; }) { } |
673 : fn = [ | 515 C.na1() : fn = wrap(()=> 55) { } |
674 () { | |
675 return 56; | |
676 } | |
677 ][0] {} | |
678 C.na2() : fn = [() => 57][0] {} | |
679 | 516 |
680 C.nb3() | 517 C.nb2() : fn = [() { return 56; }][0] { } |
681 : fn = { | 518 C.na2() : fn = [() => 57][0] { } |
682 'x': () { | |
683 return 58; | |
684 } | |
685 }['x'] {} | |
686 C.na3() : fn = {'x': () => 59}['x'] {} | |
687 | 519 |
688 C.rb0() | 520 C.nb3() : fn = {'x': () { return 58; }}['x'] { } |
689 : fn = (() { | 521 C.na3() : fn = {'x': () => 59}['x'] { } |
690 return 62; | |
691 }) {} | |
692 C.ra0() : fn = (() => 63) {} | |
693 | 522 |
694 C.rb1() | 523 C.rb0() : fn = (() { return 62; }) { } |
695 : fn = wrap(() { | 524 C.ra0() : fn = (() => 63) { } |
696 return 64; | |
697 }) {} | |
698 C.ra1() : fn = wrap(() => 65) {} | |
699 | 525 |
700 C.rb2() | 526 C.rb1() : fn = wrap(() { return 64; }) { } |
701 : fn = [ | 527 C.ra1() : fn = wrap(()=> 65) { } |
702 () { | |
703 return 66; | |
704 } | |
705 ][0] {} | |
706 C.ra2() : fn = [() => 67][0] {} | |
707 | 528 |
708 C.rb3() | 529 C.rb2() : fn = [() { return 66; }][0] { } |
709 : fn = { | 530 C.ra2() : fn = [() => 67][0] { } |
710 'x': () { | 531 |
711 return 68; | 532 C.rb3() : fn = {'x': () { return 68; }}['x'] { } |
712 } | 533 C.ra3() : fn = {'x': () => 69}['x'] { } |
713 }['x'] {} | |
714 C.ra3() : fn = {'x': () => 69}['x'] {} | |
715 | 534 |
716 static wrap | 535 static wrap |
717 /* //# 73: compile-time error | 536 /* //# 73: compile-time error |
718 (fn) | 537 (fn) |
719 */ //# 73: continued | 538 */ //# 73: continued |
720 { | 539 { return fn; } |
721 return fn; | |
722 } | |
723 | 540 |
724 final fn; | 541 final fn; |
| 542 |
725 } | 543 } |
726 | 544 |
727 main | 545 main |
728 /* //# 74: compile-time error | 546 /* //# 74: compile-time error |
729 () | 547 () |
730 */ //# 74: continued | 548 */ //# 74: continued |
731 { | 549 { |
732 FunctionSyntaxTest.testMain(); | 550 FunctionSyntaxTest.testMain(); |
733 } | 551 } |
OLD | NEW |