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

Side by Side Diff: frog/tests/leg_only/src/ForInTest.dart

Issue 9148021: Implement for-in. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698