| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 class MyList extends ListBase { | 8 class MyList extends ListBase { |
| 9 List list; | 9 List list; |
| 10 MyList(this.list); | 10 MyList(this.list); |
| 11 | 11 |
| 12 get length => list.length; | 12 get length => list.length; |
| 13 set length(val) { | 13 set length(val) { |
| 14 list.length = val; | 14 list.length = val; |
| 15 } | 15 } |
| 16 | 16 |
| 17 operator [](index) => list[index]; | 17 operator [](index) => list[index]; |
| 18 operator []=(index, val) => list[index] = val; | 18 operator []=(index, val) => list[index] = val; |
| 19 | 19 |
| 20 String toString() => "[" + join(", ") + "]"; | 20 String toString() => "[" + join(", ") + "]"; |
| 21 } | 21 } |
| 22 | 22 |
| 23 final bool isCheckedMode = (() { |
| 24 try { |
| 25 var i = 42; |
| 26 String s = i; |
| 27 } on TypeError catch (e) { |
| 28 return true; |
| 29 } |
| 30 return false; |
| 31 })(); |
| 32 |
| 23 // l1 must be a modifiable list with 5 elements from 0 to 4. | 33 // l1 must be a modifiable list with 5 elements from 0 to 4. |
| 24 void testModifiableList(l1) { | 34 void testModifiableList(l1) { |
| 25 bool checkedMode = false; | |
| 26 assert(checkedMode = true); | |
| 27 | |
| 28 // Index must be integer and in range. | 35 // Index must be integer and in range. |
| 29 Expect.throws(() { | 36 Expect.throws(() { |
| 30 l1.removeAt(-1); | 37 l1.removeAt(-1); |
| 31 }, (e) => e is RangeError, "negative"); | 38 }, (e) => e is RangeError, "negative"); |
| 32 Expect.throws(() { | 39 Expect.throws(() { |
| 33 l1.removeAt(5); | 40 l1.removeAt(5); |
| 34 }, (e) => e is RangeError, "too large"); | 41 }, (e) => e is RangeError, "too large"); |
| 35 Expect.throws(() { | 42 Expect.throws(() { |
| 36 l1.removeAt(null); | 43 l1.removeAt(null); |
| 37 }, (e) => e is ArgumentError, "too large"); | 44 }, (e) => e is ArgumentError, "too large"); |
| 38 Expect.throws(() { | 45 Expect.throws(() { |
| 39 l1.removeAt("1"); | 46 l1.removeAt("1"); |
| 40 }, (e) => (checkedMode ? e is TypeError : e is ArgumentError), "string"); | 47 }, (e) => (isCheckedMode ? e is TypeError : e is ArgumentError), "string"); |
| 41 Expect.throws(() { | 48 Expect.throws(() { |
| 42 l1.removeAt(1.5); | 49 l1.removeAt(1.5); |
| 43 }, (e) => (checkedMode ? e is TypeError : e is ArgumentError), "double"); | 50 }, (e) => (isCheckedMode ? e is TypeError : e is ArgumentError), "double"); |
| 44 | 51 |
| 45 Expect.equals(2, l1.removeAt(2), "l1-remove2"); | 52 Expect.equals(2, l1.removeAt(2), "l1-remove2"); |
| 46 Expect.equals(1, l1[1], "l1-1[1]"); | 53 Expect.equals(1, l1[1], "l1-1[1]"); |
| 47 | 54 |
| 48 Expect.equals(3, l1[2], "l1-1[2]"); | 55 Expect.equals(3, l1[2], "l1-1[2]"); |
| 49 Expect.equals(4, l1[3], "l1-1[3]"); | 56 Expect.equals(4, l1[3], "l1-1[3]"); |
| 50 Expect.equals(4, l1.length, "length-1"); | 57 Expect.equals(4, l1.length, "length-1"); |
| 51 | 58 |
| 52 Expect.equals(0, l1.removeAt(0), "l1-remove0"); | 59 Expect.equals(0, l1.removeAt(0), "l1-remove0"); |
| 53 Expect.equals(1, l1[0], "l1-2[0]"); | 60 Expect.equals(1, l1[0], "l1-2[0]"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 73 Expect.throws(() { | 80 Expect.throws(() { |
| 74 l3.removeAt(2); | 81 l3.removeAt(2); |
| 75 }, (e) => e is UnsupportedError, "unmodifiable"); | 82 }, (e) => e is UnsupportedError, "unmodifiable"); |
| 76 | 83 |
| 77 // Empty list is not special. | 84 // Empty list is not special. |
| 78 var l4 = []; | 85 var l4 = []; |
| 79 Expect.throws(() { | 86 Expect.throws(() { |
| 80 l4.removeAt(0); | 87 l4.removeAt(0); |
| 81 }, (e) => e is RangeError, "empty"); | 88 }, (e) => e is RangeError, "empty"); |
| 82 } | 89 } |
| OLD | NEW |