OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 import "package:expect/expect.dart"; |
| 6 |
5 // Test foreach (aka. for-in) functionality. | 7 // Test foreach (aka. for-in) functionality. |
6 | 8 |
7 testIterator(List expect, Iterable input) { | 9 testIterator(List expect, Iterable input) { |
8 int i = 0; | 10 int i = 0; |
9 for (var value in input) { | 11 for (var value in input) { |
10 Expect.isTrue(i < expect.length); | 12 Expect.isTrue(i < expect.length); |
11 Expect.equals(expect[i], value); | 13 Expect.equals(expect[i], value); |
12 i += 1; | 14 i += 1; |
13 } | 15 } |
14 Expect.equals(expect.length, i); | 16 Expect.equals(expect.length, i); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 74 |
73 // Using the same variable (showing that the expression is evaluated | 75 // Using the same variable (showing that the expression is evaluated |
74 // in the outer scope). | 76 // in the outer scope). |
75 int result = 0; | 77 int result = 0; |
76 var x = [1,2,3]; | 78 var x = [1,2,3]; |
77 for (var x in x) { | 79 for (var x in x) { |
78 result += x; | 80 result += x; |
79 } | 81 } |
80 Expect.equals(6, result); | 82 Expect.equals(6, result); |
81 } | 83 } |
OLD | NEW |