Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, 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 // Test foreach (aka. for-in) functionality. | |
| 6 | |
| 7 testIterator(List expect, Iterable input) { | |
| 8 int i = 0; | |
| 9 for (var value in input) { | |
| 10 Expect.isTrue(i < expect.length); | |
| 11 Expect.equals(expect[i], value); | |
| 12 i += 1; | |
| 13 } | |
| 14 Expect.equals(expect.length, i); | |
| 15 } | |
| 16 | |
| 17 class MyIterable<T> /* implements Iterable<T> */ { | |
| 18 final List<T> values; | |
| 19 MyIterable(List<T> values) : this.values = values; | |
| 20 Iterator iterator() { | |
| 21 return new MyListIterator(values); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 class MyListIterator<T> /* implements Iterator<T> */ { | |
| 26 final List<T> values; | |
| 27 int index; | |
| 28 MyListIterator(List<T> values) : this.values = values, index = 0; | |
| 29 bool hasNext() => index < values.length; | |
| 30 T next() => values[index++]; | |
| 31 } | |
| 32 | |
| 33 void main() { | |
| 34 testIterator([1,2,3], [1,2,3]); | |
| 35 testIterator([1,2,3], new MyIterable([1,2,3])); | |
| 36 // Enable when we donno longer generate code that bail out on | |
|
ngeoffray
2012/01/11 10:09:22
As discussed, please re-enable them now :)
Lasse Reichstein
2012/01/11 10:26:00
Done.
| |
| 37 // non-number values. | |
| 38 // testStringIterator(["a","b","c"], new MyIterable(["a","b","c"])); | |
| 39 // testStringIterator(["a","b","c"], ["a","b","c"]); | |
| 40 } | |
| OLD | NEW |