OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 void main() { | 5 void main() { |
6 // Normal modifiable list. | 6 // Normal modifiable list. |
7 var l1 = [0, 1, 2, 3, 4]; | 7 var l1 = [0, 1, 2, 3, 4]; |
8 | 8 |
| 9 bool checkedMode = false; |
| 10 assert(checkedMode = true); |
| 11 |
9 // Index must be integer and in range. | 12 // Index must be integer and in range. |
10 Expect.throws(() { l1.removeAt(-1); }, | 13 Expect.throws(() { l1.removeAt(-1); }, |
11 (e) => e is IndexOutOfRangeException, | 14 (e) => e is IndexOutOfRangeException, |
12 "negative"); | 15 "negative"); |
13 Expect.throws(() { l1.removeAt(5); }, | 16 Expect.throws(() { l1.removeAt(5); }, |
14 (e) => e is IndexOutOfRangeException, | 17 (e) => e is IndexOutOfRangeException, |
15 "too large"); | 18 "too large"); |
| 19 Expect.throws(() { l1.removeAt(null); }, |
| 20 (e) => e is IllegalArgumentException, |
| 21 "too large"); |
16 Expect.throws(() { l1.removeAt("1"); }, | 22 Expect.throws(() { l1.removeAt("1"); }, |
17 (e) => e is IllegalArgumentException, | 23 (e) => (checkedMode ? e is TypeError |
| 24 : e is IllegalArgumentException), |
18 "string"); | 25 "string"); |
19 Expect.throws(() { l1.removeAt(1.5); }, | 26 Expect.throws(() { l1.removeAt(1.5); }, |
20 (e) => e is IllegalArgumentException, | 27 (e) => (checkedMode ? e is TypeError |
| 28 : e is IllegalArgumentException), |
21 "double"); | 29 "double"); |
22 | 30 |
23 Expect.equals(2, l1.removeAt(2), "l1-remove2"); | 31 Expect.equals(2, l1.removeAt(2), "l1-remove2"); |
24 Expect.equals(1, l1[1], "l1-1[1]"); | 32 Expect.equals(1, l1[1], "l1-1[1]"); |
25 | 33 |
26 Expect.equals(3, l1[2], "l1-1[2]"); | 34 Expect.equals(3, l1[2], "l1-1[2]"); |
27 Expect.equals(4, l1[3], "l1-1[3]"); | 35 Expect.equals(4, l1[3], "l1-1[3]"); |
28 Expect.equals(4, l1.length, "length-1"); | 36 Expect.equals(4, l1.length, "length-1"); |
29 | 37 |
30 Expect.equals(0, l1.removeAt(0), "l1-remove0"); | 38 Expect.equals(0, l1.removeAt(0), "l1-remove0"); |
(...skipping 14 matching lines...) Expand all Loading... |
45 Expect.throws(() { l3.removeAt(2); }, | 53 Expect.throws(() { l3.removeAt(2); }, |
46 (e) => e is UnsupportedOperationException, | 54 (e) => e is UnsupportedOperationException, |
47 "unmodifiable"); | 55 "unmodifiable"); |
48 | 56 |
49 // Empty list is not special. | 57 // Empty list is not special. |
50 var l4 = []; | 58 var l4 = []; |
51 Expect.throws(() { l4.removeAt(0); }, | 59 Expect.throws(() { l4.removeAt(0); }, |
52 (e) => e is IndexOutOfRangeException, | 60 (e) => e is IndexOutOfRangeException, |
53 "empty"); | 61 "empty"); |
54 } | 62 } |
OLD | NEW |