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 // TODO(jmesserly): this is a copy of the language test of the same name, | 5 // TODO(jmesserly): this is a copy of the language test of the same name, |
6 // we can remove this copy when we're running against those tests. | 6 // we can remove this copy when we're running against those tests. |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 Iterable<int> foo1() sync* { | 9 Iterable<int> foo1() sync* { |
10 yield 1; | 10 yield 1; |
11 } | 11 } |
12 | 12 |
13 Iterable<int> foo2(p) sync* { | 13 Iterable<int> foo2(p) sync* { |
14 bool t = false; | 14 bool t = false; |
15 yield null; | 15 yield null; |
16 while (true) { | 16 while (true) { |
17 a: for (int i = 0; i < p; i++) { | 17 a: |
| 18 for (int i = 0; i < p; i++) { |
18 if (!t) { | 19 if (!t) { |
19 for (int j = 0; j < 3; j++) { | 20 for (int j = 0; j < 3; j++) { |
20 yield -1; | 21 yield -1; |
21 t = true; | 22 t = true; |
22 break a; | 23 break a; |
23 } | 24 } |
24 } | 25 } |
25 yield i; | 26 yield i; |
26 } | 27 } |
27 } | 28 } |
28 } | 29 } |
29 | 30 |
30 // p is copied to all Iterators from the Iterable returned by foo3. | 31 // p is copied to all Iterators from the Iterable returned by foo3. |
31 // Also each iterator will have its own i. | 32 // Also each iterator will have its own i. |
32 Iterable<int> foo3(int p) sync* { | 33 Iterable<int> foo3(int p) sync* { |
33 int i = 0; | 34 int i = 0; |
34 i++; | 35 i++; |
35 p++; | 36 p++; |
36 yield p + i; | 37 yield p + i; |
37 } | 38 } |
38 | 39 |
39 main() { | 40 main() { |
40 Expect.listEquals([1], foo1().toList()); | 41 Expect.listEquals([1], foo1().toList()); |
41 Expect.listEquals([null, -1, 0, 1, 2, 3, 0, 1, 2, 3], | 42 Expect.listEquals( |
42 foo2(4).take(10).toList()); | 43 [null, -1, 0, 1, 2, 3, 0, 1, 2, 3], foo2(4).take(10).toList()); |
43 Iterable t = foo3(0); | 44 Iterable t = foo3(0); |
44 Iterator it1 = t.iterator; | 45 Iterator it1 = t.iterator; |
45 Iterator it2 = t.iterator; //# copyParameters: ok | 46 Iterator it2 = t.iterator; //# copyParameters: ok |
46 it1.moveNext(); | 47 it1.moveNext(); |
47 it2.moveNext(); //# copyParameters: continued | 48 it2.moveNext(); //# copyParameters: continued |
48 Expect.equals(2, it1.current); | 49 Expect.equals(2, it1.current); |
49 // TODO(sigurdm): Check up on the spec here. | 50 // TODO(sigurdm): Check up on the spec here. |
50 Expect.equals(2, it2.current); // //# copyParameters: continued | 51 Expect.equals(2, it2.current); // //# copyParameters: continued |
51 Expect.isFalse(it1.moveNext()); | 52 Expect.isFalse(it1.moveNext()); |
52 // Test that two `moveNext()` calls are fine. | 53 // Test that two `moveNext()` calls are fine. |
53 Expect.isFalse(it1.moveNext()); | 54 Expect.isFalse(it1.moveNext()); |
54 Expect.isFalse(it2.moveNext()); //# copyParameters: continued | 55 Expect.isFalse(it2.moveNext()); //# copyParameters: continued |
55 Expect.isFalse(it2.moveNext()); //# copyParameters: continued | 56 Expect.isFalse(it2.moveNext()); //# copyParameters: continued |
56 } | 57 } |
OLD | NEW |