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

Side by Side Diff: tests/corelib/list_iterators_test.dart

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 7 years, 9 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 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 Expect.isNull(it.current); 8 Expect.isNull(it.current);
9 for (int i = 0; i < a.length; i++) { 9 for (int i = 0; i < a.length; i++) {
10 Expect.isTrue(it.moveNext()); 10 Expect.isTrue(it.moveNext());
11 var elem = it.current; 11 var elem = it.current;
12 Expect.equals(a[i], elem); 12 Expect.equals(a[i], elem);
13 } 13 }
14 Expect.isFalse(it.moveNext()); 14 Expect.isFalse(it.moveNext());
15 Expect.isNull(it.current); 15 Expect.isNull(it.current);
16 } 16 }
17 17
18 static testMain() { 18 static testMain() {
19 checkListIterator([]); 19 checkListIterator([]);
20 checkListIterator([1, 2]); 20 checkListIterator([1, 2]);
21 checkListIterator(new List.fixedLength(0)); 21 checkListIterator(new List(0));
22 checkListIterator(new List.fixedLength(10)); 22 checkListIterator(new List(10));
23 checkListIterator(new List()); 23 checkListIterator(new List());
24 List g = new List(); 24 List g = new List();
25 g.addAll([1, 2, 3]); 25 g.addAll([1, 2, 3]);
26 checkListIterator(g); 26 checkListIterator(g);
27 27
28 // This is mostly undefined behavior. 28 // This is mostly undefined behavior.
29 Iterator it = g.iterator; 29 Iterator it = g.iterator;
30 Expect.isTrue(it.moveNext()); 30 Expect.isTrue(it.moveNext());
31 Expect.equals(1, it.current); 31 Expect.equals(1, it.current);
32 Expect.isTrue(it.moveNext()); 32 Expect.isTrue(it.moveNext());
33 g[1] = 49; 33 g[1] = 49;
34 // The iterator keeps the last value. 34 // The iterator keeps the last value.
35 Expect.equals(2, it.current); 35 Expect.equals(2, it.current);
36 Expect.isTrue(it.moveNext()); 36 Expect.isTrue(it.moveNext());
37 g.removeLast(); 37 g.removeLast();
38 // The iterator keeps the last value. 38 // The iterator keeps the last value.
39 Expect.equals(3, it.current); 39 Expect.equals(3, it.current);
40 Expect.throws(it.moveNext, (e) => e is ConcurrentModificationError); 40 Expect.throws(it.moveNext, (e) => e is ConcurrentModificationError);
41 // No progress when throwing. 41 // No progress when throwing.
42 Expect.equals(3, it.current); 42 Expect.equals(3, it.current);
43 } 43 }
44 } 44 }
45 45
46 main() { 46 main() {
47 ListIteratorsTest.testMain(); 47 ListIteratorsTest.testMain();
48 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698