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 class ListIteratorsTest { | 5 class ListIteratorsTest { |
6 static void checkListIterator(List a) { | 6 static void checkListIterator(List a) { |
7 Iterator it = a.iterator; | 7 Iterator it = a.iterator; |
8 for (int i = 0; i < a.length; i++) { | 8 for (int i = 0; i < a.length; i++) { |
9 Expect.isTrue(it.moveNext()); | 9 Expect.isTrue(it.moveNext()); |
10 var elem = it.current; | 10 var elem = it.current; |
11 Expect.equals(a[i], elem); | 11 Expect.equals(a[i], elem); |
12 } | 12 } |
13 Expect.isFalse(it.moveNext()); | 13 Expect.isFalse(it.moveNext()); |
14 Expect.isNull(it.current); | 14 Expect.isNull(it.current); |
15 } | 15 } |
16 | 16 |
17 static testMain() { | 17 static testMain() { |
18 checkListIterator([]); | 18 checkListIterator([]); |
19 checkListIterator([1, 2]); | 19 checkListIterator([1, 2]); |
20 checkListIterator(new List(0)); | 20 checkListIterator(new List.fixedLength(0)); |
21 checkListIterator(new List(10)); | 21 checkListIterator(new List.fixedLength(10)); |
22 checkListIterator(new List()); | 22 checkListIterator(new List()); |
23 List g = new List(); | 23 List g = new List(); |
24 g.addAll([1, 2, 3]); | 24 g.addAll([1, 2, 3]); |
25 checkListIterator(g); | 25 checkListIterator(g); |
26 | 26 |
27 // This is mostly undefined behavior. | 27 // This is mostly undefined behavior. |
28 Iterator it = g.iterator; | 28 Iterator it = g.iterator; |
29 Expect.isTrue(it.moveNext()); | 29 Expect.isTrue(it.moveNext()); |
30 g.removeLast(); | 30 g.removeLast(); |
31 Expect.equals(1, it.current); | 31 Expect.equals(1, it.current); |
(...skipping 15 matching lines...) Expand all Loading... |
47 // Iterator must realize that g has no more elements. | 47 // Iterator must realize that g has no more elements. |
48 g.removeLast(); | 48 g.removeLast(); |
49 } | 49 } |
50 Expect.equals(10, sum); | 50 Expect.equals(10, sum); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 main() { | 54 main() { |
55 ListIteratorsTest.testMain(); | 55 ListIteratorsTest.testMain(); |
56 } | 56 } |
OLD | NEW |