| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 import "dart:collection"; | |
| 7 | |
| 8 class MyList extends ListBase { | |
| 9 List list; | |
| 10 MyList(this.list); | |
| 11 get length => list.length; | |
| 12 set length(value) { | |
| 13 list.length = value; | |
| 14 } | |
| 15 | |
| 16 operator [](index) => list[index]; | |
| 17 operator []=(index, val) { | |
| 18 list[index] = val; | |
| 19 } | |
| 20 | |
| 21 toString() => list.toString(); | |
| 22 } | |
| 23 | |
| 24 void testWithoutModification(List list) { | |
| 25 var seen = []; | |
| 26 list.forEach(seen.add); | |
| 27 | |
| 28 Expect.listEquals(list, seen); | |
| 29 } | |
| 30 | |
| 31 void testWithModification(List list) { | |
| 32 if (list.isEmpty) return; | |
| 33 Expect.throws(() => list.forEach((_) => list.add(0)), | |
| 34 (e) => e is ConcurrentModificationError); | |
| 35 } | |
| 36 | |
| 37 main() { | |
| 38 List fixedLengthList = new List(10); | |
| 39 for (int i = 0; i < 10; i++) fixedLengthList[i] = i + 1; | |
| 40 | |
| 41 List growableList = new List(); | |
| 42 growableList.length = 10; | |
| 43 for (int i = 0; i < 10; i++) growableList[i] = i + 1; | |
| 44 | |
| 45 var growableLists = [ | |
| 46 [], | |
| 47 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], | |
| 48 new MyList([1, 2, 3, 4, 5]), | |
| 49 growableList, | |
| 50 ]; | |
| 51 var fixedLengthLists = [ | |
| 52 const [], | |
| 53 fixedLengthList, | |
| 54 const [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], | |
| 55 new MyList(const [1, 2]), | |
| 56 ]; | |
| 57 | |
| 58 for (var list in growableLists) { | |
| 59 print(list); | |
| 60 testWithoutModification(list); | |
| 61 testWithModification(list); | |
| 62 } | |
| 63 | |
| 64 for (var list in fixedLengthLists) { | |
| 65 testWithoutModification(list); | |
| 66 } | |
| 67 } | |
| OLD | NEW |