Chromium Code Reviews| 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 import "package:expect/expect.dart"; | |
| 6 | |
| 7 Iterable<int> foo1() sync* { | |
| 8 yield 1; | |
| 9 } | |
| 10 | |
| 11 Iterable<int> foo2(p) sync* { | |
| 12 bool t = false; | |
| 13 yield null; | |
| 14 while (true) { | |
| 15 a: for (int i = 0; i < p; i++) { | |
| 16 if (!t) { | |
| 17 for (int j = 0; j < 3; j++) { | |
| 18 yield -1; | |
| 19 t = true; | |
| 20 break a; | |
| 21 } | |
| 22 } | |
| 23 yield i; | |
| 24 } | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 // p will be shared between all Iterators from the Iterable returned by foo3. | |
| 29 // On the other hand each iterator will have its own i. | |
| 30 Iterable<int> foo3(int p) sync* { | |
| 31 int i = 0; | |
| 32 i++; | |
| 33 p++; | |
| 34 yield p + i; | |
| 35 } | |
| 36 | |
| 37 main() { | |
| 38 Expect.listEquals([1], foo1().toList()); | |
| 39 Expect.listEquals([null, -1, 0, 1, 2, 3, 0, 1, 2, 3], foo2(4).take(10).toList( )); | |
|
floitsch
2015/02/02 22:00:12
long line.
sigurdm
2015/02/03 16:59:33
Done.
| |
| 40 Iterable t = foo3(0); | |
| 41 Iterator i1 = t.iterator; | |
|
floitsch
2015/02/02 22:00:12
it1
sigurdm
2015/02/03 16:59:33
Done.
| |
| 42 Iterator i2 = t.iterator; | |
|
floitsch
2015/02/02 22:00:12
it2
sigurdm
2015/02/03 16:59:33
Done.
| |
| 43 i1.moveNext(); | |
| 44 i2.moveNext(); | |
| 45 Expect.equals(2, i1.current); | |
| 46 Expect.equals(3, i2.current); | |
|
floitsch
2015/02/02 22:00:12
Expect.isFalse(i1.moveNext());
Expect.isFalse(i2.m
sigurdm
2015/02/03 16:59:33
Done.
| |
| 47 } | |
| OLD | NEW |