| 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 void main() { |
| 6 // Normal modifiable list. |
| 7 var l1 = [0, 1, 2, 3, 4]; |
| 8 |
| 9 // Index must be integer and in range. |
| 10 Expect.throws(() { l1.removeAt(-1); }, |
| 11 (e) => e is IndexOutOfRangeException, |
| 12 "negative"); |
| 13 Expect.throws(() { l1.removeAt(5); }, |
| 14 (e) => e is IndexOutOfRangeException, |
| 15 "too large"); |
| 16 Expect.throws(() { l1.removeAt("1"); }, |
| 17 (e) => e is IllegalArgumentException, |
| 18 "string"); |
| 19 Expect.throws(() { l1.removeAt(1.5); }, |
| 20 (e) => e is IllegalArgumentException, |
| 21 "double"); |
| 22 |
| 23 Expect.equals(2, l1.removeAt(2), "l1-remove2"); |
| 24 Expect.equals(1, l1[1], "l1-1[1]"); |
| 25 |
| 26 Expect.equals(3, l1[2], "l1-1[2]"); |
| 27 Expect.equals(4, l1[3], "l1-1[3]"); |
| 28 Expect.equals(4, l1.length, "length-1"); |
| 29 |
| 30 Expect.equals(0, l1.removeAt(0), "l1-remove0"); |
| 31 Expect.equals(1, l1[0], "l1-2[0]"); |
| 32 Expect.equals(3, l1[1], "l1-2[1]"); |
| 33 Expect.equals(4, l1[2], "l1-2[2]"); |
| 34 Expect.equals(3, l1.length, "length-2"); |
| 35 |
| 36 // Fixed size list. |
| 37 var l2 = new List(5); |
| 38 for (var i = 0; i < 5; i++) l2[i] = i; |
| 39 Expect.throws(() { l2.removeAt(2); }, |
| 40 (e) => e is UnsupportedOperationException, |
| 41 "fixed-length"); |
| 42 |
| 43 // Unmodifiable list. |
| 44 var l3 = const [0, 1, 2, 3, 4]; |
| 45 Expect.throws(() { l3.removeAt(2); }, |
| 46 (e) => e is UnsupportedOperationException, |
| 47 "unmodifiable"); |
| 48 |
| 49 // Empty list is not special. |
| 50 var l4 = []; |
| 51 Expect.throws(() { l4.removeAt(0); }, |
| 52 (e) => e is IndexOutOfRangeException, |
| 53 "empty"); |
| 54 } |
| OLD | NEW |