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 test(List list, int start, int end, Iterable iterable) { | |
9 List copy = list.toList(); | |
10 list.replaceRange(start, end, iterable); | |
11 List iterableList = iterable.toList(); | |
12 Expect.equals(copy.length + iterableList.length - (end - start), list.length); | |
13 for (int i = 0; i < start; i++) { | |
14 Expect.equals(copy[i], list[i]); | |
15 } | |
16 for (int i = 0; i < iterableList.length; i++) { | |
17 Expect.equals(iterableList[i], list[i + start]); | |
18 } | |
19 int removedLength = end - start; | |
20 for (int i = end; i < copy.length; i++) { | |
21 Expect.equals(copy[i], list[i + iterableList.length - removedLength]); | |
22 } | |
23 } | |
24 | |
25 class MyList extends ListBase { | |
26 List list; | |
27 MyList(this.list); | |
28 get length => list.length; | |
29 set length(value) { | |
30 list.length = value; | |
31 } | |
32 | |
33 operator [](index) => list[index]; | |
34 operator []=(index, val) { | |
35 list[index] = val; | |
36 } | |
37 | |
38 toString() => list.toString(); | |
39 } | |
40 | |
41 main() { | |
42 test([1, 2, 3], 0, 1, [4, 5]); | |
43 test([1, 2, 3], 1, 1, [4, 5]); | |
44 test([1, 2, 3], 2, 3, [4, 5]); | |
45 test([1, 2, 3], 3, 3, [4, 5]); | |
46 test([1, 2, 3], 0, 3, [4, 5]); | |
47 test([1, 2, 3], 2, 3, [4]); | |
48 test([1, 2, 3], 0, 3, []); | |
49 test([1, 2, 3], 0, 1, [4, 5].map((x) => x)); | |
50 test([1, 2, 3], 1, 1, [4, 5].map((x) => x)); | |
51 test([1, 2, 3], 2, 3, [4, 5].map((x) => x)); | |
52 test([1, 2, 3], 3, 3, [4, 5].map((x) => x)); | |
53 test([1, 2, 3], 0, 3, [4, 5].map((x) => x)); | |
54 test([1, 2, 3], 2, 3, [4].map((x) => x)); | |
55 test([1, 2, 3], 0, 3, [].map((x) => x)); | |
56 test([1, 2, 3], 0, 1, const [4, 5]); | |
57 test([1, 2, 3], 1, 1, const [4, 5]); | |
58 test([1, 2, 3], 2, 3, const [4, 5]); | |
59 test([1, 2, 3], 3, 3, const [4, 5]); | |
60 test([1, 2, 3], 0, 3, const [4, 5]); | |
61 test([1, 2, 3], 2, 3, const [4]); | |
62 test([1, 2, 3], 0, 3, const []); | |
63 test([1, 2, 3], 0, 1, new Iterable.generate(2, (x) => x + 4)); | |
64 test([1, 2, 3], 1, 1, new Iterable.generate(2, (x) => x + 4)); | |
65 test([1, 2, 3], 2, 3, new Iterable.generate(2, (x) => x + 4)); | |
66 test([1, 2, 3], 3, 3, new Iterable.generate(2, (x) => x + 4)); | |
67 test([1, 2, 3], 0, 3, new Iterable.generate(2, (x) => x + 4)); | |
68 test([1, 2, 3], 2, 3, new Iterable.generate(2, (x) => x + 4)); | |
69 test(new MyList([1, 2, 3]), 0, 1, [4, 5]); | |
70 test(new MyList([1, 2, 3]), 1, 1, [4, 5]); | |
71 test(new MyList([1, 2, 3]), 2, 3, [4, 5]); | |
72 test(new MyList([1, 2, 3]), 3, 3, [4, 5]); | |
73 test(new MyList([1, 2, 3]), 0, 3, [4, 5]); | |
74 test(new MyList([1, 2, 3]), 2, 3, [4]); | |
75 test(new MyList([1, 2, 3]), 0, 3, []); | |
76 test(new MyList([1, 2, 3]), 0, 1, [4, 5].map((x) => x)); | |
77 test(new MyList([1, 2, 3]), 1, 1, [4, 5].map((x) => x)); | |
78 test(new MyList([1, 2, 3]), 2, 3, [4, 5].map((x) => x)); | |
79 test(new MyList([1, 2, 3]), 3, 3, [4, 5].map((x) => x)); | |
80 test(new MyList([1, 2, 3]), 0, 3, [4, 5].map((x) => x)); | |
81 test(new MyList([1, 2, 3]), 2, 3, [4].map((x) => x)); | |
82 test(new MyList([1, 2, 3]), 0, 3, [].map((x) => x)); | |
83 test(new MyList([1, 2, 3]), 0, 1, const [4, 5]); | |
84 test(new MyList([1, 2, 3]), 1, 1, const [4, 5]); | |
85 test(new MyList([1, 2, 3]), 2, 3, const [4, 5]); | |
86 test(new MyList([1, 2, 3]), 3, 3, const [4, 5]); | |
87 test(new MyList([1, 2, 3]), 0, 3, const [4, 5]); | |
88 test(new MyList([1, 2, 3]), 2, 3, const [4]); | |
89 test(new MyList([1, 2, 3]), 0, 3, const []); | |
90 test(new MyList([1, 2, 3]), 0, 1, new Iterable.generate(2, (x) => x + 4)); | |
91 test(new MyList([1, 2, 3]), 1, 1, new Iterable.generate(2, (x) => x + 4)); | |
92 test(new MyList([1, 2, 3]), 2, 3, new Iterable.generate(2, (x) => x + 4)); | |
93 test(new MyList([1, 2, 3]), 3, 3, new Iterable.generate(2, (x) => x + 4)); | |
94 test(new MyList([1, 2, 3]), 0, 3, new Iterable.generate(2, (x) => x + 4)); | |
95 test(new MyList([1, 2, 3]), 2, 3, new Iterable.generate(2, (x) => x + 4)); | |
96 | |
97 expectRE(() => test([1, 2, 3], -1, 0, [])); | |
98 expectRE(() => test([1, 2, 3], 2, 1, [])); | |
99 expectRE(() => test([1, 2, 3], 0, -1, [])); | |
100 expectRE(() => test([1, 2, 3], 1, 4, [])); | |
101 expectRE(() => test(new MyList([1, 2, 3]), -1, 0, [])); | |
102 expectRE(() => test(new MyList([1, 2, 3]), 2, 1, [])); | |
103 expectRE(() => test(new MyList([1, 2, 3]), 0, -1, [])); | |
104 expectRE(() => test(new MyList([1, 2, 3]), 1, 4, [])); | |
105 expectUE(() => test([1, 2, 3].toList(growable: false), 2, 3, [])); | |
106 expectUE(() => test([1, 2, 3].toList(growable: false), -1, 0, [])); | |
107 expectUE(() => test([1, 2, 3].toList(growable: false), 2, 1, [])); | |
108 expectUE(() => test([1, 2, 3].toList(growable: false), 0, -1, [])); | |
109 expectUE(() => test([1, 2, 3].toList(growable: false), 1, 4, [])); | |
110 expectUE(() => test(const [1, 2, 3], 2, 3, [])); | |
111 expectUE(() => test(const [1, 2, 3], -1, 0, [])); | |
112 expectUE(() => test(const [1, 2, 3], 2, 1, [])); | |
113 expectUE(() => test(const [1, 2, 3], 0, -1, [])); | |
114 expectUE(() => test(const [1, 2, 3], 1, 4, [])); | |
115 } | |
116 | |
117 void expectRE(Function f) { | |
118 Expect.throws(f, (e) => e is RangeError); | |
119 } | |
120 | |
121 void expectUE(Function f) { | |
122 Expect.throws(f, (e) => e is UnsupportedError); | |
123 } | |
OLD | NEW |