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 // Tests function statement and expression syntax. | 5 // Tests function statement and expression syntax. |
6 | 6 |
7 class FunctionSyntaxTest { | 7 class FunctionSyntaxTest { |
8 | 8 |
9 static void testMain | 9 static void testMain |
10 /* /// 00: compile-time error | 10 /* /// 00: compile-time error |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 Expect.equals(87, eval1( | 194 Expect.equals(87, eval1( |
195 /* /// 27: compile-time error | 195 /* /// 27: compile-time error |
196 (a) | 196 (a) |
197 */ /// 27: continued | 197 */ /// 27: continued |
198 { return a; }, 87)); | 198 { return a; }, 87)); |
199 Expect.equals(1 + 2, eval2( | 199 Expect.equals(1 + 2, eval2( |
200 /* /// 28: compile-time error | 200 /* /// 28: compile-time error |
201 (a, b) | 201 (a, b) |
202 */ /// 28: continued | 202 */ /// 28: continued |
203 { return a + b; }, 1, 2)); | 203 { return a + b; }, 1, 2)); |
204 Expect.equals(42, eval0(nb0 | 204 Expect.equals(42, eval0( |
205 /* /// 29: compile-time error | 205 /* /// 29: compile-time error |
206 () | 206 () |
207 */ /// 29: continued | 207 */ /// 29: continued |
208 { return 42; })); | 208 { return 42; })); |
209 Expect.equals(87, eval1(nb1 | 209 Expect.equals(87, eval1( |
210 /* /// 30: compile-time error | 210 /* /// 30: compile-time error |
211 (a) | 211 (a) |
212 */ /// 30: continued | 212 */ /// 30: continued |
213 { return a; }, 87)); | 213 { return a; }, 87)); |
214 Expect.equals(1 + 2, eval2(nb2 | 214 Expect.equals(1 + 2, eval2( |
215 /* /// 31: compile-time error | 215 /* /// 31: compile-time error |
216 (a, b) | 216 (a, b) |
217 */ /// 31: continued | 217 */ /// 31: continued |
218 { return a + b; }, 1, 2)); | 218 { return a + b; }, 1, 2)); |
219 | 219 |
220 // No types - arrows. | 220 // No types - arrows. |
221 Expect.equals(42, eval0( | 221 Expect.equals(42, eval0( |
222 /* /// 32: compile-time error | 222 /* /// 32: compile-time error |
223 () | 223 () |
224 */ /// 32: continued | 224 */ /// 32: continued |
225 => 42)); | 225 => 42)); |
226 Expect.equals(87, eval1( | 226 Expect.equals(87, eval1( |
227 /* /// 33: compile-time error | 227 /* /// 33: compile-time error |
228 (a) | 228 (a) |
229 */ /// 33: continued | 229 */ /// 33: continued |
230 => a, 87)); | 230 => a, 87)); |
231 Expect.equals(1 + 2, eval2( | 231 Expect.equals(1 + 2, eval2( |
232 /* /// 34: compile-time error | 232 /* /// 34: compile-time error |
233 (a, b) | 233 (a, b) |
234 */ /// 34: continued | 234 */ /// 34: continued |
235 => a + b, 1, 2)); | 235 => a + b, 1, 2)); |
236 Expect.equals(42, eval0(na0 | 236 Expect.equals(42, eval0( |
237 /* /// 35: compile-time error | 237 /* /// 35: compile-time error |
238 () | 238 () |
239 */ /// 35: continued | 239 */ /// 35: continued |
240 => 42)); | 240 => 42)); |
241 Expect.equals(87, eval1(na1 | 241 Expect.equals(87, eval1( |
242 /* /// 36: compile-time error | 242 /* /// 36: compile-time error |
243 (a) | 243 (a) |
244 */ /// 36: continued | 244 */ /// 36: continued |
245 => a, 87)); | 245 => a, 87)); |
246 Expect.equals(1 + 2, eval2(na2 | 246 Expect.equals(1 + 2, eval2( |
247 /* /// 37: compile-time error | 247 /* /// 37: compile-time error |
248 (a, b) | 248 (a, b) |
249 */ /// 37: continued | 249 */ /// 37: continued |
250 => a + b, 1, 2)); | 250 => a + b, 1, 2)); |
251 | 251 |
252 // Return type - braces. | |
253 Expect.equals(42, eval0(int rb0 | |
254 /* /// 38: compile-time error | |
255 () | |
256 */ /// 38: continued | |
257 { return 42; })); | |
258 Expect.equals(87, eval1(int rb1 | |
259 /* /// 39: compile-time error | |
260 (a) | |
261 */ /// 39: continued | |
262 { return a; }, 87)); | |
263 Expect.equals(1 + 2, eval2(int rb2 | |
264 /* /// 40: compile-time error | |
265 (a, b) | |
266 */ /// 40: continued | |
267 { return a + b; }, 1, 2)); | |
268 | |
269 // Return type - arrows. | |
270 Expect.equals(42, eval0(int ra0 | |
271 /* /// 41: compile-time error | |
272 () | |
273 */ /// 41: continued | |
274 => 42)); | |
275 Expect.equals(87, eval1(int ra1 | |
276 /* /// 42: compile-time error | |
277 (a) | |
278 */ /// 42: continued | |
279 => a, 87)); | |
280 Expect.equals(1 + 2, eval2(int ra2 | |
281 /* /// 43: compile-time error | |
282 (a, b) | |
283 */ /// 43: continued | |
284 => a + b, 1, 2)); | |
285 | |
286 // Argument types - braces. | 252 // Argument types - braces. |
287 Expect.equals(42, eval0( | 253 Expect.equals(42, eval0( |
288 /* /// 44: compile-time error | 254 /* /// 44: compile-time error |
289 () | 255 () |
290 */ /// 44: continued | 256 */ /// 44: continued |
291 { return 42; })); | 257 { return 42; })); |
292 Expect.equals(87, eval1( | 258 Expect.equals(87, eval1( |
293 /* /// 45: compile-time error | 259 /* /// 45: compile-time error |
294 (int a) | 260 (int a) |
295 */ /// 45: continued | 261 */ /// 45: continued |
296 { return a; }, 87)); | 262 { return a; }, 87)); |
297 Expect.equals(1 + 2, eval2( | 263 Expect.equals(1 + 2, eval2( |
298 /* /// 46: compile-time error | 264 /* /// 46: compile-time error |
299 (int a, int b) | 265 (int a, int b) |
300 */ /// 46: continued | 266 */ /// 46: continued |
301 { return a + b; }, 1, 2)); | 267 { return a + b; }, 1, 2)); |
302 Expect.equals(42, eval0( ab0 | 268 Expect.equals(42, eval0( |
303 /* /// 47: compile-time error | 269 /* /// 47: compile-time error |
304 () | 270 () |
305 */ /// 47: continued | 271 */ /// 47: continued |
306 { return 42; })); | 272 { return 42; })); |
307 Expect.equals(87, eval1(ab1 | 273 Expect.equals(87, eval1( |
308 /* /// 48: compile-time error | 274 /* /// 48: compile-time error |
309 (int a) | 275 (int a) |
310 */ /// 48: continued | 276 */ /// 48: continued |
311 { return a; }, 87)); | 277 { return a; }, 87)); |
312 Expect.equals(1 + 2, eval2(ab2 | 278 Expect.equals(1 + 2, eval2( |
313 /* /// 49: compile-time error | 279 /* /// 49: compile-time error |
314 (int a, int b) | 280 (int a, int b) |
315 */ /// 49: continued | 281 */ /// 49: continued |
316 { return a + b; }, 1, 2)); | 282 { return a + b; }, 1, 2)); |
317 | 283 |
318 // Argument types - arrows. | 284 // Argument types - arrows. |
319 Expect.equals(42, eval0( | 285 Expect.equals(42, eval0( |
320 /* /// 50: compile-time error | 286 /* /// 50: compile-time error |
321 () | 287 () |
322 */ /// 50: continued | 288 */ /// 50: continued |
323 => 42)); | 289 => 42)); |
324 Expect.equals(87, eval1( | 290 Expect.equals(87, eval1( |
325 /* /// 51: compile-time error | 291 /* /// 51: compile-time error |
326 (int a) | 292 (int a) |
327 */ /// 51: continued | 293 */ /// 51: continued |
328 => a, 87)); | 294 => a, 87)); |
329 Expect.equals(1 + 2, eval2( | 295 Expect.equals(1 + 2, eval2( |
330 /* /// 52: compile-time error | 296 /* /// 52: compile-time error |
331 (int a, int b) | 297 (int a, int b) |
332 */ /// 52: continued | 298 */ /// 52: continued |
333 => a + b, 1, 2)); | 299 => a + b, 1, 2)); |
334 Expect.equals(42, eval0(aa0 | 300 Expect.equals(42, eval0( |
335 /* /// 53: compile-time error | 301 /* /// 53: compile-time error |
336 () | 302 () |
337 */ /// 53: continued | 303 */ /// 53: continued |
338 => 42)); | 304 => 42)); |
339 Expect.equals(87, eval1(aa1 | 305 Expect.equals(87, eval1( |
340 /* /// 54: compile-time error | 306 /* /// 54: compile-time error |
341 (int a) | 307 (int a) |
342 */ /// 54: continued | 308 */ /// 54: continued |
343 => a, 87)); | 309 => a, 87)); |
344 Expect.equals(1 + 2, eval2(aa2 | 310 Expect.equals(1 + 2, eval2( |
345 /* /// 55: compile-time error | 311 /* /// 55: compile-time error |
346 (int a, int b) | 312 (int a, int b) |
347 */ /// 55: continued | 313 */ /// 55: continued |
348 => a + b, 1, 2)); | 314 => a + b, 1, 2)); |
349 | 315 |
350 // Fully typed - braces. | |
351 Expect.equals(87, eval1(int fb1 | |
352 /* /// 56: compile-time error | |
353 (int a) | |
354 */ /// 56: continued | |
355 { return a; }, 87)); | |
356 Expect.equals(1 + 2, eval2(int fb2 | |
357 /* /// 57: compile-time error | |
358 (int a, int b) | |
359 */ /// 57: continued | |
360 { return a + b; }, 1, 2)); | |
361 | |
362 // Fully typed - arrows. | |
363 Expect.equals(87, eval1(int fa1 | |
364 /* /// 58: compile-time error | |
365 (int a) | |
366 */ /// 58: continued | |
367 => a, 87)); | |
368 Expect.equals(1 + 2, eval2(int fa2 | |
369 /* /// 59: compile-time error | |
370 (int a, int b) | |
371 */ /// 59: continued | |
372 => a + b, 1, 2)); | |
373 | |
374 // Generic types - braces. | |
375 Expect.equals(42, eval0(List<int> gb0 | |
376 /* /// 60: compile-time error | |
377 () | |
378 */ /// 60: continued | |
379 { return [42]; })[0]); | |
380 Expect.equals(87, eval1(List<int> gb1 | |
381 /* /// 61: compile-time error | |
382 (List<int> a) | |
383 */ /// 61: continued | |
384 { return a; }, [87])[0]); | |
385 | |
386 // Generic types - arrows. | |
387 Expect.equals(42, eval0(List<int> ga0 | |
388 /* /// 62: compile-time error | |
389 () | |
390 */ /// 62: continued | |
391 => [42])[0]); | |
392 Expect.equals(87, eval1(List<int> ga1 | |
393 /* /// 63: compile-time error | |
394 (List<int> a) | |
395 */ /// 63: continued | |
396 => a, [87])[0]); | |
397 } | 316 } |
398 | 317 |
399 static void testPrecedence | 318 static void testPrecedence |
400 /* /// 64: compile-time error | 319 /* /// 64: compile-time error |
401 () | 320 () |
402 */ /// 64: continued | 321 */ /// 64: continued |
403 { | 322 { |
404 expectEvaluatesTo | 323 expectEvaluatesTo |
405 /* /// 65: compile-time error | 324 /* /// 65: compile-time error |
406 (value, fn) | 325 (value, fn) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 461 |
543 f3(fn(int a)) => fn(42); | 462 f3(fn(int a)) => fn(42); |
544 Expect.equals(44, f3((int a)=> a + 2)); | 463 Expect.equals(44, f3((int a)=> a + 2)); |
545 } | 464 } |
546 | 465 |
547 static void testFunctionIdentifierExpression | 466 static void testFunctionIdentifierExpression |
548 /* /// 69: compile-time error | 467 /* /// 69: compile-time error |
549 () | 468 () |
550 */ /// 69: continued | 469 */ /// 69: continued |
551 { | 470 { |
552 Expect.equals(87, (function | 471 Expect.equals(87, ( |
553 /* /// 70: compile-time error | 472 /* /// 70: compile-time error |
554 () | 473 () |
555 */ /// 70: continued | 474 */ /// 70: continued |
556 => 87)()); | 475 => 87)()); |
557 } | 476 } |
558 | 477 |
559 static void testFunctionIdentifierStatement | 478 static void testFunctionIdentifierStatement |
560 /* /// 71: compile-time error | 479 /* /// 71: compile-time error |
561 () | 480 () |
562 */ /// 71: continued | 481 */ /// 71: continued |
(...skipping 17 matching lines...) Expand all Loading... |
580 | 499 |
581 C.cb1() : fn = wrap(() { return 44; }) { } | 500 C.cb1() : fn = wrap(() { return 44; }) { } |
582 C.ca1() : fn = wrap(()=> 45) { } | 501 C.ca1() : fn = wrap(()=> 45) { } |
583 | 502 |
584 C.cb2() : fn = [() { return 46; }][0] { } | 503 C.cb2() : fn = [() { return 46; }][0] { } |
585 C.ca2() : fn = [() => 47][0] { } | 504 C.ca2() : fn = [() => 47][0] { } |
586 | 505 |
587 C.cb3() : fn = {'x': () { return 48; }}['x'] { } | 506 C.cb3() : fn = {'x': () { return 48; }}['x'] { } |
588 C.ca3() : fn = {'x': () => 49}['x'] { } | 507 C.ca3() : fn = {'x': () => 49}['x'] { } |
589 | 508 |
590 C.nb0() : fn = (f() { return 52; }) { } | 509 C.nb0() : fn = (() { return 52; }) { } |
591 C.na0() : fn = (f() => 53) { } | 510 C.na0() : fn = (() => 53) { } |
592 | 511 |
593 C.nb1() : fn = wrap(f() { return 54; }) { } | 512 C.nb1() : fn = wrap(() { return 54; }) { } |
594 C.na1() : fn = wrap(f()=> 55) { } | 513 C.na1() : fn = wrap(()=> 55) { } |
595 | 514 |
596 C.nb2() : fn = [f() { return 56; }][0] { } | 515 C.nb2() : fn = [() { return 56; }][0] { } |
597 C.na2() : fn = [f() => 57][0] { } | 516 C.na2() : fn = [() => 57][0] { } |
598 | 517 |
599 C.nb3() : fn = {'x': f() { return 58; }}['x'] { } | 518 C.nb3() : fn = {'x': () { return 58; }}['x'] { } |
600 C.na3() : fn = {'x': f() => 59}['x'] { } | 519 C.na3() : fn = {'x': () => 59}['x'] { } |
601 | 520 |
602 C.rb0() : fn = (int _() { return 62; }) { } | 521 C.rb0() : fn = (() { return 62; }) { } |
603 C.ra0() : fn = (int _() => 63) { } | 522 C.ra0() : fn = (() => 63) { } |
604 | 523 |
605 C.rb1() : fn = wrap(int _() { return 64; }) { } | 524 C.rb1() : fn = wrap(() { return 64; }) { } |
606 C.ra1() : fn = wrap(int _()=> 65) { } | 525 C.ra1() : fn = wrap(()=> 65) { } |
607 | 526 |
608 C.rb2() : fn = [int _() { return 66; }][0] { } | 527 C.rb2() : fn = [() { return 66; }][0] { } |
609 C.ra2() : fn = [int _() => 67][0] { } | 528 C.ra2() : fn = [() => 67][0] { } |
610 | 529 |
611 C.rb3() : fn = {'x': int _() { return 68; }}['x'] { } | 530 C.rb3() : fn = {'x': () { return 68; }}['x'] { } |
612 C.ra3() : fn = {'x': int _() => 69}['x'] { } | 531 C.ra3() : fn = {'x': () => 69}['x'] { } |
613 | 532 |
614 static wrap | 533 static wrap |
615 /* /// 73: compile-time error | 534 /* /// 73: compile-time error |
616 (fn) | 535 (fn) |
617 */ /// 73: continued | 536 */ /// 73: continued |
618 { return fn; } | 537 { return fn; } |
619 | 538 |
620 final fn; | 539 final fn; |
621 | 540 |
622 } | 541 } |
623 | 542 |
624 main | 543 main |
625 /* /// 74: compile-time error | 544 /* /// 74: compile-time error |
626 () | 545 () |
627 */ /// 74: continued | 546 */ /// 74: continued |
628 { | 547 { |
629 FunctionSyntaxTest.testMain(); | 548 FunctionSyntaxTest.testMain(); |
630 } | 549 } |
OLD | NEW |