Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: tests/language/sync_generator1_test.dart

Issue 910923002: Make yield* throw an error if not yielding an Iterable (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 var e = start; 28 var e = start;
29 while (e <= end) yield e++; 29 while (e <= end) yield e++;
30 } 30 }
31 } 31 }
32 32
33 get sync sync* { // sync is a legal identifier. 33 get sync sync* { // sync is a legal identifier.
34 yield "sync"; 34 yield "sync";
35 } 35 }
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* {
46 yield* 3; // Throws type error: yielded object is not an iterable.
47 }
48
45 main() { 49 main() {
46 for (int i = 0; i < 10; i++) { 50 for (int i = 0; i < 10; i++) {
47 var sums = sum10(); 51 var sums = sum10();
48 print(sums); 52 print(sums);
49 Expect.isTrue(sums is Iterable); 53 Expect.isTrue(sums is Iterable);
50 Expect.equals(10, sums.length); 54 Expect.equals(10, sums.length);
51 Expect.equals(1, sums.first); 55 Expect.equals(1, sums.first);
52 Expect.equals(55, sums.last); 56 Expect.equals(55, sums.last);
53 var q = ""; 57 var q = "";
54 for (var n in sums.take(3)) { 58 for (var n in sums.take(3)) {
(...skipping 12 matching lines...) Expand all
67 elems2.forEach((e) { 71 elems2.forEach((e) {
68 Expect.isTrue(i.moveNext()); 72 Expect.isTrue(i.moveNext());
69 Expect.equals(e, i.current); 73 Expect.equals(e, i.current);
70 }); 74 });
71 75
72 print(sync); 76 print(sync);
73 Expect.equals("sync", sync.single); 77 Expect.equals("sync", sync.single);
74 78
75 print(einsZwei()); 79 print(einsZwei());
76 Expect.equals("(1, 2, 3, 5, [6])", einsZwei().toString()); 80 Expect.equals("(1, 2, 3, 5, [6])", einsZwei().toString());
81
82 Expect.throws(() => dreiVier().toString());
77 } 83 }
78 } 84 }
OLDNEW
« no previous file with comments | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698