OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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 |
| 5 // Simple test program for sync* generator functions. |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 import "dart:async"; |
| 9 |
| 10 var sync = "topLevelSync"; |
| 11 var async = "topLevelAync"; |
| 12 var await = "topLevelAwait"; |
| 13 var yield = "topLevelYield"; |
| 14 |
| 15 test01() sync* { |
| 16 var yield = 0; /// 01: compile-time error |
| 17 var await = 0; /// 02: compile-time error |
| 18 var async = 0; /// 03: compile-time error |
| 19 bool yield() => false; /// 04: compile-time error |
| 20 bool await() => false; /// 05: compile-time error |
| 21 bool async() => false; /// 06: compile-time error |
| 22 |
| 23 var x1 = sync; |
| 24 var x2 = async; /// 07: compile-time error |
| 25 var x3 = await; /// 08: compile-time error |
| 26 var x4 = await 55; /// 09: compile-time error |
| 27 var x4 = yield; /// 10: compile-time error |
| 28 |
| 29 var stream = new Stream.fromIterable([1, 2, 3]); |
| 30 await for (var e in stream) print(e); /// 11: compile-time error |
| 31 } |
| 32 |
| 33 test02() sync* { |
| 34 yield 12321; |
| 35 return null; /// 20: compile-time error |
| 36 } |
| 37 |
| 38 test03() sync* => null; /// 30: compile-time error |
| 39 |
| 40 get test04 sync* => null; /// 40: compile-time error |
| 41 set test04(a) sync* { print(a); } /// 41: compile-time error |
| 42 |
| 43 class K { |
| 44 K() sync* {}; /// 50: compile-time error |
| 45 get nix sync* { } |
| 46 get garnix sync* => null; /// 51: compile-time error |
| 47 set etwas(var z) sync* { } /// 52: compile-time error |
| 48 sync() sync* { |
| 49 yield sync; // Yields a tear-off of the sync() method. |
| 50 } |
| 51 } |
| 52 |
| 53 main() { |
| 54 var x; |
| 55 x = test01(); |
| 56 Expect.equals("()", x.toString()); |
| 57 x = test02(); |
| 58 Expect.equals("(12321)", x.toString()); |
| 59 x = test04; /// 40: continued |
| 60 test04 = x; /// 41: continued |
| 61 x = new K(); |
| 62 Expect.equals(1, x.sync().length); |
| 63 Expect.isTrue(x.sync().single is Function); |
| 64 } |
OLD | NEW |