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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: frog/tests/leg_only/src/ForInTest.dart
diff --git a/frog/tests/leg_only/src/ForInTest.dart b/frog/tests/leg_only/src/ForInTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..591f8876176b7b68db7f6addb1332be1b5b4abf2
--- /dev/null
+++ b/frog/tests/leg_only/src/ForInTest.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test foreach (aka. for-in) functionality.
+
+testIterator(List expect, Iterable input) {
+ int i = 0;
+ for (var value in input) {
+ Expect.isTrue(i < expect.length);
+ Expect.equals(expect[i], value);
+ i += 1;
+ }
+ Expect.equals(expect.length, i);
+}
+
+class MyIterable<T> /* implements Iterable<T> */ {
+ final List<T> values;
+ MyIterable(List<T> values) : this.values = values;
+ Iterator iterator() {
+ return new MyListIterator(values);
+ }
+}
+
+class MyListIterator<T> /* implements Iterator<T> */ {
+ final List<T> values;
+ int index;
+ MyListIterator(List<T> values) : this.values = values, index = 0;
+ bool hasNext() => index < values.length;
+ T next() => values[index++];
+}
+
+void main() {
+ testIterator([1,2,3], [1,2,3]);
+ testIterator([1,2,3], new MyIterable([1,2,3]));
+ // 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.
+ // non-number values.
+ // testStringIterator(["a","b","c"], new MyIterable(["a","b","c"]));
+ // testStringIterator(["a","b","c"], ["a","b","c"]);
+}

Powered by Google App Engine
This is Rietveld 408576698