| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Simple test program for sync* generator functions. | 5 // Simple test program for sync* generator functions. |
| 6 | 6 |
| 7 // VMOptions=--optimization_counter_threshold=10 | 7 // VMOptions=--optimization_counter_threshold=10 |
| 8 | 8 |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 einsZwei() sync* { | 37 einsZwei() sync* { |
| 38 yield 1; | 38 yield 1; |
| 39 yield* [2, 3]; | 39 yield* [2, 3]; |
| 40 yield* []; | 40 yield* []; |
| 41 yield 5; | 41 yield 5; |
| 42 yield [6]; | 42 yield [6]; |
| 43 } | 43 } |
| 44 | 44 |
| 45 dreiVier() sync* { | 45 dreiVier() sync* { |
| 46 yield* 3; // Throws type error: yielded object is not an iterable. | 46 // Throws type error: yielded object is not an iterable. |
| 47 yield* 3; /// 01: static type warning |
| 47 } | 48 } |
| 48 | 49 |
| 49 main() { | 50 main() { |
| 50 for (int i = 0; i < 10; i++) { | 51 for (int i = 0; i < 10; i++) { |
| 51 var sums = sum10(); | 52 var sums = sum10(); |
| 52 print(sums); | 53 print(sums); |
| 53 Expect.isTrue(sums is Iterable); | 54 Expect.isTrue(sums is Iterable); |
| 54 Expect.equals(10, sums.length); | 55 Expect.equals(10, sums.length); |
| 55 Expect.equals(1, sums.first); | 56 Expect.equals(1, sums.first); |
| 56 Expect.equals(55, sums.last); | 57 Expect.equals(55, sums.last); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 72 Expect.isTrue(i.moveNext()); | 73 Expect.isTrue(i.moveNext()); |
| 73 Expect.equals(e, i.current); | 74 Expect.equals(e, i.current); |
| 74 }); | 75 }); |
| 75 | 76 |
| 76 print(sync); | 77 print(sync); |
| 77 Expect.equals("sync", sync.single); | 78 Expect.equals("sync", sync.single); |
| 78 | 79 |
| 79 print(einsZwei()); | 80 print(einsZwei()); |
| 80 Expect.equals("(1, 2, 3, 5, [6])", einsZwei().toString()); | 81 Expect.equals("(1, 2, 3, 5, [6])", einsZwei().toString()); |
| 81 | 82 |
| 82 Expect.throws(() => dreiVier().toString()); | 83 Expect.throws(() => dreiVier().toString()); /// 01: continued |
| 83 } | 84 } |
| 84 } | 85 } |
| OLD | NEW |