OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 main() { | |
6 var list = []; | |
7 list.setRange(0, 0, const []); | |
8 list.setRange(0, 0, []); | |
9 list.setRange(0, 0, const [], 1); | |
10 list.setRange(0, 0, [], 1); | |
11 Expect.equals(0, list.length); | |
12 expectIOORE(() { list.setRange(0, 1, []); }); | |
13 expectIOORE(() { list.setRange(0, 1, [], 1); }); | |
14 expectIOORE(() { list.setRange(0, 1, [1], 0); }); | |
15 | |
16 list.add(1); | |
17 list.setRange(0, 0, [], 0); | |
18 Expect.equals(1, list.length); | |
19 Expect.equals(1, list[0]); | |
20 list.setRange(0, 0, const [], 0); | |
21 Expect.equals(1, list.length); | |
22 Expect.equals(1, list[0]); | |
23 | |
24 expectIOORE(() { list.setRange(0, 2, [1, 2]); }); | |
25 Expect.equals(1, list.length); | |
26 Expect.equals(1, list[0]); | |
27 | |
28 expectIOORE(() { list.setRange(0, 1, [1, 2], 2); }); | |
29 Expect.equals(1, list.length); | |
30 Expect.equals(1, list[0]); | |
31 | |
32 list.setRange(0, 1, [2], 0); | |
33 Expect.equals(1, list.length); | |
34 Expect.equals(2, list[0]); | |
35 | |
36 list.setRange(0, 1, const [3], 0); | |
37 Expect.equals(1, list.length); | |
38 Expect.equals(3, list[0]); | |
39 | |
40 list.addAll([4, 5, 6]); | |
41 Expect.equals(4, list.length); | |
42 list.setRange(0, 4, [1, 2, 3, 4]); | |
43 Expect.listEquals([1, 2, 3, 4], list); | |
44 | |
45 list.setRange(2, 2, [5, 6, 7, 8]); | |
46 Expect.listEquals([1, 2, 5, 6], list); | |
47 | |
48 expectIOORE(() { list.setRange(4, 1, [5, 6, 7, 8]); }); | |
49 Expect.listEquals([1, 2, 5, 6], list); | |
50 | |
51 list.setRange(1, 2, [9, 10, 11, 12]); | |
52 Expect.listEquals([1, 9, 10, 6], list); | |
53 | |
54 testNegativeIndices(); | |
55 | |
56 testNonExtendableList(); | |
57 } | |
58 | |
59 void expectIOORE(Function f) { | |
60 Expect.throws(f, (e) => e is IndexOutOfRangeException); | |
61 } | |
62 | |
63 void testNegativeIndices() { | |
64 var list = [1, 2]; | |
65 expectIOORE(() { list.setRange(-1, 1, [1]); }); | |
66 expectIOORE(() { list.setRange(0, 1, [1], -1); }); | |
67 | |
68 // A negative length throws an IllegalArgumentException. | |
69 Expect.throws(() { list.setRange(0, -1, [1]); }, | |
70 (e) => e is IllegalArgumentException); | |
71 | |
72 Expect.throws(() { list.setRange(-1, -1, [1], -1); }, | |
73 (e) => e is IllegalArgumentException); | |
74 Expect.listEquals([1, 2], list); | |
75 | |
76 // A zero length prevails, and does not throw an exception. | |
77 list.setRange(-1, 0, [1]); | |
78 Expect.listEquals([1, 2], list); | |
79 | |
80 list.setRange(0, 0, [1], -1); | |
81 Expect.listEquals([1, 2], list); | |
82 } | |
83 | |
84 void testNonExtendableList() { | |
85 var list = new List<int>(6); | |
86 Expect.listEquals([null, null, null, null, null, null], list); | |
87 list.setRange(0, 3, [1, 2, 3, 4]); | |
88 list.setRange(3, 3, [1, 2, 3, 4]); | |
89 Expect.listEquals([1, 2, 3, 1, 2, 3], list); | |
90 } | |
OLD | NEW |