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

Unified Diff: frog/tests/leg_only/src/ForInTest.dart

Issue 9139014: Allow for-in to use a previously declared identifier as variable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add more tests 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
index e3fad995ca5e8a83acf6a4b3117789647499b5bc..8104d925e39943722da667a64a63af36c8d5edc6 100644
--- a/frog/tests/leg_only/src/ForInTest.dart
+++ b/frog/tests/leg_only/src/ForInTest.dart
@@ -12,6 +12,15 @@ testIterator(List expect, Iterable input) {
i += 1;
}
Expect.equals(expect.length, i);
+
+ i = 0;
+ var value2;
+ for (value2 in input) {
+ Expect.isTrue(i < expect.length);
+ Expect.equals(expect[i], value2);
+ i += 1;
+ }
+ Expect.equals(expect.length, i);
}
class MyIterable<T> /* implements Iterable<T> */ {
@@ -39,4 +48,33 @@ void main() {
testIterator([1,2,3], new MyIterable([1,2,3]));
testIterator(["a","b","c"], ["a","b","c"]);
testIterator(["a","b","c"], new MyIterable(["a","b","c"]));
+
+ // Several nested for-in's.
+ for (var x in [[["a"]]]) {
+ for (var y in x) {
+ for (var z in y) {
+ Expect.equals("a", z);
+ }
+ }
+ }
+
+ // Simultaneous iteration of the same iterable.
+ for (var iterable in [[1,2,3], new MyIterable([1,2,3])]) {
+ int result = 0;
+ for (var x in iterable) {
+ for (var y in iterable) {
+ result += x * y;
+ }
+ }
+ Expect.equals(36, result);
+ }
+
+ // Using the same variable (showing that the expression is evaluated
+ // in the outer scope).
+ int result = 0;
+ var x = [1,2,3];
+ for (var x in x) {
+ result += x;
+ }
+ Expect.equals(6, result);
}

Powered by Google App Engine
This is Rietveld 408576698