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 import "package:expect/expect.dart"; | |
6 | |
7 main() { | |
8 var list = []; | |
9 list.removeRange(0, 0); | |
10 Expect.equals(0, list.length); | |
11 expectIOORE(() { | |
12 list.removeRange(0, 1); | |
13 }); | |
14 | |
15 list.add(1); | |
16 list.removeRange(0, 0); | |
17 Expect.equals(1, list.length); | |
18 Expect.equals(1, list[0]); | |
19 | |
20 expectIOORE(() { | |
21 list.removeRange(0, 2); | |
22 }); | |
23 Expect.equals(1, list.length); | |
24 Expect.equals(1, list[0]); | |
25 | |
26 list.removeRange(0, 1); | |
27 Expect.equals(0, list.length); | |
28 | |
29 list.addAll([3, 4, 5, 6]); | |
30 Expect.equals(4, list.length); | |
31 list.removeRange(0, 4); | |
32 Expect.listEquals([], list); | |
33 | |
34 list.addAll([3, 4, 5, 6]); | |
35 list.removeRange(2, 4); | |
36 Expect.listEquals([3, 4], list); | |
37 list.addAll([5, 6]); | |
38 | |
39 expectIOORE(() { | |
40 list.removeRange(4, 5); | |
41 }); | |
42 Expect.listEquals([3, 4, 5, 6], list); | |
43 | |
44 list.removeRange(1, 3); | |
45 Expect.listEquals([3, 6], list); | |
46 | |
47 testNegativeIndices(); | |
48 } | |
49 | |
50 void expectIOORE(Function f) { | |
51 Expect.throws(f, (e) => e is RangeError); | |
52 } | |
53 | |
54 void testNegativeIndices() { | |
55 var list = [1, 2]; | |
56 expectIOORE(() { | |
57 list.removeRange(-1, 1); | |
58 }); | |
59 Expect.listEquals([1, 2], list); | |
60 | |
61 // A negative length throws an ArgumentError. | |
62 expectIOORE(() { | |
63 list.removeRange(0, -1); | |
64 }); | |
65 Expect.listEquals([1, 2], list); | |
66 | |
67 expectIOORE(() { | |
68 list.removeRange(-1, -1); | |
69 }); | |
70 Expect.listEquals([1, 2], list); | |
71 | |
72 expectIOORE(() { | |
73 list.removeRange(-1, 0); | |
74 }); | |
75 | |
76 expectIOORE(() { | |
77 list.removeRange(4, 4); | |
78 }); | |
79 Expect.listEquals([1, 2], list); | |
80 } | |
OLD | NEW |