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

Side by Side Diff: tests/compiler/dart2js_extra/for_in_test.dart

Issue 11230011: Make hasNext a getter instead of a method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove unused variable. Created 8 years, 2 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
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 // Test foreach (aka. for-in) functionality. 5 // Test foreach (aka. for-in) functionality.
6 6
7 testIterator(List expect, Iterable input) { 7 testIterator(List expect, Iterable input) {
8 int i = 0; 8 int i = 0;
9 for (var value in input) { 9 for (var value in input) {
10 Expect.isTrue(i < expect.length); 10 Expect.isTrue(i < expect.length);
(...skipping 17 matching lines...) Expand all
28 MyIterable(List<T> values) : this.values = values; 28 MyIterable(List<T> values) : this.values = values;
29 Iterator iterator() { 29 Iterator iterator() {
30 return new MyListIterator(values); 30 return new MyListIterator(values);
31 } 31 }
32 } 32 }
33 33
34 class MyListIterator<T> implements Iterator<T> { 34 class MyListIterator<T> implements Iterator<T> {
35 final List<T> values; 35 final List<T> values;
36 int index; 36 int index;
37 MyListIterator(List<T> values) : this.values = values, index = 0; 37 MyListIterator(List<T> values) : this.values = values, index = 0;
38 bool hasNext() => index < values.length; 38 bool get hasNext => index < values.length;
39 T next() => values[index++]; 39 T next() => values[index++];
40 } 40 }
41 41
42 void main() { 42 void main() {
43 testIterator([], []); 43 testIterator([], []);
44 testIterator([], new MyIterable([])); 44 testIterator([], new MyIterable([]));
45 testIterator([1], [1]); 45 testIterator([1], [1]);
46 testIterator([1], new MyIterable([1])); 46 testIterator([1], new MyIterable([1]));
47 testIterator([1,2,3], [1,2,3]); 47 testIterator([1,2,3], [1,2,3]);
48 testIterator([1,2,3], new MyIterable([1,2,3])); 48 testIterator([1,2,3], new MyIterable([1,2,3]));
(...skipping 22 matching lines...) Expand all
71 71
72 // Using the same variable (showing that the expression is evaluated 72 // Using the same variable (showing that the expression is evaluated
73 // in the outer scope). 73 // in the outer scope).
74 int result = 0; 74 int result = 0;
75 var x = [1,2,3]; 75 var x = [1,2,3];
76 for (var x in x) { 76 for (var x in x) {
77 result += x; 77 result += x;
78 } 78 }
79 Expect.equals(6, result); 79 Expect.equals(6, result);
80 } 80 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/pretty_parameter_test.dart ('k') | tests/corelib/list_iterators_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698