OLD | NEW |
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 test(List list, int index, Iterable iterable) { | 8 test(List list, int index, Iterable iterable) { |
9 List copy = list.toList(); | 9 List copy = list.toList(); |
10 list.setAll(index, iterable); | 10 list.setAll(index, iterable); |
11 Expect.equals(copy.length, list.length); | 11 Expect.equals(copy.length, list.length); |
12 for (int i = 0; i < index; i++) { | 12 for (int i = 0; i < index; i++) { |
13 Expect.equals(copy[i], list[i]); | 13 Expect.equals(copy[i], list[i]); |
14 } | 14 } |
15 List iterableList = iterable.toList(); | 15 List iterableList = iterable.toList(); |
16 for (int i = 0; i < iterableList.length; i++) { | 16 for (int i = 0; i < iterableList.length; i++) { |
17 Expect.equals(iterableList[i], list[i + index]); | 17 Expect.equals(iterableList[i], list[i + index]); |
18 } | 18 } |
19 for (int i = index + iterableList.length; i < copy.length; i++) { | 19 for (int i = index + iterableList.length; i < copy.length; i++) { |
20 Expect.equals(copy[i], list[i]); | 20 Expect.equals(copy[i], list[i]); |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 class MyList extends ListBase { | 24 class MyList extends ListBase { |
25 List list; | 25 List list; |
26 MyList(this.list); | 26 MyList(this.list); |
27 get length => list.length; | 27 get length => list.length; |
28 set length(value) { list.length = value; } | 28 set length(value) { |
| 29 list.length = value; |
| 30 } |
| 31 |
29 operator [](index) => list[index]; | 32 operator [](index) => list[index]; |
30 operator []=(index, val) { list[index] = val; } | 33 operator []=(index, val) { |
| 34 list[index] = val; |
| 35 } |
| 36 |
31 toString() => list.toString(); | 37 toString() => list.toString(); |
32 } | 38 } |
33 | 39 |
34 main() { | 40 main() { |
35 test([1, 2, 3], 0, [4, 5]); | 41 test([1, 2, 3], 0, [4, 5]); |
36 test([1, 2, 3], 1, [4, 5]); | 42 test([1, 2, 3], 1, [4, 5]); |
37 test([1, 2, 3], 2, [4]); | 43 test([1, 2, 3], 2, [4]); |
38 test([1, 2, 3], 3, []); | 44 test([1, 2, 3], 3, []); |
39 test([1, 2, 3], 0, [4, 5].map((x) => x)); | 45 test([1, 2, 3], 0, [4, 5].map((x) => x)); |
40 test([1, 2, 3], 1, [4, 5].map((x) => x)); | 46 test([1, 2, 3], 1, [4, 5].map((x) => x)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 expectUE(() => test(const [1, 2, 3], 1, [4, 5, 6])); | 94 expectUE(() => test(const [1, 2, 3], 1, [4, 5, 6])); |
89 } | 95 } |
90 | 96 |
91 void expectRE(Function f) { | 97 void expectRE(Function f) { |
92 Expect.throws(f, (e) => e is RangeError); | 98 Expect.throws(f, (e) => e is RangeError); |
93 } | 99 } |
94 | 100 |
95 void expectUE(Function f) { | 101 void expectUE(Function f) { |
96 Expect.throws(f, (e) => e is UnsupportedError); | 102 Expect.throws(f, (e) => e is UnsupportedError); |
97 } | 103 } |
OLD | NEW |