Chromium Code Reviews| 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 })(); | |
|
sra1
2017/05/24 01:30:46
delete
eernst
2017/07/07 08:50:29
Done.
| |
| 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) => (typeAssertionsEnabled ? e is TypeError : e is ArgumentError), |
| 48 "string"); | |
| 41 Expect.throws(() { | 49 Expect.throws(() { |
| 42 l1.removeAt(1.5); | 50 l1.removeAt(1.5); |
| 43 }, (e) => (checkedMode ? e is TypeError : e is ArgumentError), "double"); | 51 }, (e) => (typeAssertionsEnabled ? e is TypeError : e is ArgumentError), |
| 52 "double"); | |
| 44 | 53 |
| 45 Expect.equals(2, l1.removeAt(2), "l1-remove2"); | 54 Expect.equals(2, l1.removeAt(2), "l1-remove2"); |
| 46 Expect.equals(1, l1[1], "l1-1[1]"); | 55 Expect.equals(1, l1[1], "l1-1[1]"); |
| 47 | 56 |
| 48 Expect.equals(3, l1[2], "l1-1[2]"); | 57 Expect.equals(3, l1[2], "l1-1[2]"); |
| 49 Expect.equals(4, l1[3], "l1-1[3]"); | 58 Expect.equals(4, l1[3], "l1-1[3]"); |
| 50 Expect.equals(4, l1.length, "length-1"); | 59 Expect.equals(4, l1.length, "length-1"); |
| 51 | 60 |
| 52 Expect.equals(0, l1.removeAt(0), "l1-remove0"); | 61 Expect.equals(0, l1.removeAt(0), "l1-remove0"); |
| 53 Expect.equals(1, l1[0], "l1-2[0]"); | 62 Expect.equals(1, l1[0], "l1-2[0]"); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 73 Expect.throws(() { | 82 Expect.throws(() { |
| 74 l3.removeAt(2); | 83 l3.removeAt(2); |
| 75 }, (e) => e is UnsupportedError, "unmodifiable"); | 84 }, (e) => e is UnsupportedError, "unmodifiable"); |
| 76 | 85 |
| 77 // Empty list is not special. | 86 // Empty list is not special. |
| 78 var l4 = []; | 87 var l4 = []; |
| 79 Expect.throws(() { | 88 Expect.throws(() { |
| 80 l4.removeAt(0); | 89 l4.removeAt(0); |
| 81 }, (e) => e is RangeError, "empty"); | 90 }, (e) => e is RangeError, "empty"); |
| 82 } | 91 } |
| OLD | NEW |