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

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: Made test work. 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
« no previous file with comments | « frog/leg/typechecker.dart ('k') | tests/corelib/corelib-leg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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([], []);
35 testIterator([], new MyIterable([]));
36 testIterator([1], [1]);
37 testIterator([1], new MyIterable([1]));
38 testIterator([1,2,3], [1,2,3]);
39 testIterator([1,2,3], new MyIterable([1,2,3]));
40 testIterator(["a","b","c"], ["a","b","c"]);
41 testIterator(["a","b","c"], new MyIterable(["a","b","c"]));
42 }
OLDNEW
« no previous file with comments | « frog/leg/typechecker.dart ('k') | tests/corelib/corelib-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698