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

Side by Side Diff: tests/corelib_strong/list_for_each_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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"; 5 import "package:expect/expect.dart";
6 import "dart:collection"; 6 import "dart:collection";
7 7
8 class MyList extends ListBase { 8 class MyList extends ListBase {
9 List list; 9 List list;
10 MyList(this.list); 10 MyList(this.list);
11 get length => list.length; 11 get length => list.length;
12 set length(value) { list.length = value; } 12 set length(value) {
13 list.length = value;
14 }
15
13 operator [](index) => list[index]; 16 operator [](index) => list[index];
14 operator []=(index, val) { list[index] = val; } 17 operator []=(index, val) {
18 list[index] = val;
19 }
20
15 toString() => list.toString(); 21 toString() => list.toString();
16 } 22 }
17 23
18 void testWithoutModification(List list) { 24 void testWithoutModification(List list) {
19 var seen = []; 25 var seen = [];
20 list.forEach(seen.add); 26 list.forEach(seen.add);
21 27
22 Expect.listEquals(list, seen); 28 Expect.listEquals(list, seen);
23 } 29 }
24 30
25 void testWithModification(List list) { 31 void testWithModification(List list) {
26 if (list.isEmpty) return; 32 if (list.isEmpty) return;
27 Expect.throws(() => list.forEach((_) => list.add(0)), 33 Expect.throws(() => list.forEach((_) => list.add(0)),
28 (e) => e is ConcurrentModificationError); 34 (e) => e is ConcurrentModificationError);
29 } 35 }
30 36
31 main() { 37 main() {
32 List fixedLengthList = new List(10); 38 List fixedLengthList = new List(10);
33 for (int i = 0; i < 10; i++) fixedLengthList[i] = i + 1; 39 for (int i = 0; i < 10; i++) fixedLengthList[i] = i + 1;
34 40
35 List growableList = new List(); 41 List growableList = new List();
36 growableList.length = 10; 42 growableList.length = 10;
37 for (int i = 0; i < 10; i++) growableList[i] = i + 1; 43 for (int i = 0; i < 10; i++) growableList[i] = i + 1;
38 44
(...skipping 13 matching lines...) Expand all
52 for (var list in growableLists) { 58 for (var list in growableLists) {
53 print(list); 59 print(list);
54 testWithoutModification(list); 60 testWithoutModification(list);
55 testWithModification(list); 61 testWithModification(list);
56 } 62 }
57 63
58 for (var list in fixedLengthLists) { 64 for (var list in fixedLengthLists) {
59 testWithoutModification(list); 65 testWithoutModification(list);
60 } 66 }
61 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698