| 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 | 6 |
| 7 main() { | 7 main() { |
| 8 var list = []; | 8 var list = []; |
| 9 list.setRange(0, 0, const []); | 9 list.setRange(0, 0, const []); |
| 10 list.setRange(0, 0, []); | 10 list.setRange(0, 0, []); |
| 11 list.setRange(0, 0, const [], 1); | 11 list.setRange(0, 0, const [], 1); |
| 12 list.setRange(0, 0, [], 1); | 12 list.setRange(0, 0, [], 1); |
| 13 Expect.equals(0, list.length); | 13 Expect.equals(0, list.length); |
| 14 expectIOORE(() { list.setRange(0, 1, []); }); | 14 expectIOORE(() { |
| 15 expectIOORE(() { list.setRange(0, 1, [], 1); }); | 15 list.setRange(0, 1, []); |
| 16 expectIOORE(() { list.setRange(0, 1, [1], 0); }); | 16 }); |
| 17 expectIOORE(() { |
| 18 list.setRange(0, 1, [], 1); |
| 19 }); |
| 20 expectIOORE(() { |
| 21 list.setRange(0, 1, [1], 0); |
| 22 }); |
| 17 | 23 |
| 18 list.add(1); | 24 list.add(1); |
| 19 list.setRange(0, 0, [], 0); | 25 list.setRange(0, 0, [], 0); |
| 20 Expect.equals(1, list.length); | 26 Expect.equals(1, list.length); |
| 21 Expect.equals(1, list[0]); | 27 Expect.equals(1, list[0]); |
| 22 list.setRange(0, 0, const [], 0); | 28 list.setRange(0, 0, const [], 0); |
| 23 Expect.equals(1, list.length); | 29 Expect.equals(1, list.length); |
| 24 Expect.equals(1, list[0]); | 30 Expect.equals(1, list[0]); |
| 25 | 31 |
| 26 expectIOORE(() { list.setRange(0, 2, [1, 2]); }); | 32 expectIOORE(() { |
| 33 list.setRange(0, 2, [1, 2]); |
| 34 }); |
| 27 Expect.equals(1, list.length); | 35 Expect.equals(1, list.length); |
| 28 Expect.equals(1, list[0]); | 36 Expect.equals(1, list[0]); |
| 29 | 37 |
| 30 expectSE(() { list.setRange(0, 1, [1, 2], 2); }); | 38 expectSE(() { |
| 39 list.setRange(0, 1, [1, 2], 2); |
| 40 }); |
| 31 Expect.equals(1, list.length); | 41 Expect.equals(1, list.length); |
| 32 Expect.equals(1, list[0]); | 42 Expect.equals(1, list[0]); |
| 33 | 43 |
| 34 list.setRange(0, 1, [2], 0); | 44 list.setRange(0, 1, [2], 0); |
| 35 Expect.equals(1, list.length); | 45 Expect.equals(1, list.length); |
| 36 Expect.equals(2, list[0]); | 46 Expect.equals(2, list[0]); |
| 37 | 47 |
| 38 list.setRange(0, 1, const [3], 0); | 48 list.setRange(0, 1, const [3], 0); |
| 39 Expect.equals(1, list.length); | 49 Expect.equals(1, list.length); |
| 40 Expect.equals(3, list[0]); | 50 Expect.equals(3, list[0]); |
| 41 | 51 |
| 42 list.addAll([4, 5, 6]); | 52 list.addAll([4, 5, 6]); |
| 43 Expect.equals(4, list.length); | 53 Expect.equals(4, list.length); |
| 44 list.setRange(0, 4, [1, 2, 3, 4]); | 54 list.setRange(0, 4, [1, 2, 3, 4]); |
| 45 Expect.listEquals([1, 2, 3, 4], list); | 55 Expect.listEquals([1, 2, 3, 4], list); |
| 46 | 56 |
| 47 list.setRange(2, 4, [5, 6, 7, 8]); | 57 list.setRange(2, 4, [5, 6, 7, 8]); |
| 48 Expect.listEquals([1, 2, 5, 6], list); | 58 Expect.listEquals([1, 2, 5, 6], list); |
| 49 | 59 |
| 50 expectIOORE(() { list.setRange(4, 5, [5, 6, 7, 8]); }); | 60 expectIOORE(() { |
| 61 list.setRange(4, 5, [5, 6, 7, 8]); |
| 62 }); |
| 51 Expect.listEquals([1, 2, 5, 6], list); | 63 Expect.listEquals([1, 2, 5, 6], list); |
| 52 | 64 |
| 53 list.setRange(1, 3, [9, 10, 11, 12]); | 65 list.setRange(1, 3, [9, 10, 11, 12]); |
| 54 Expect.listEquals([1, 9, 10, 6], list); | 66 Expect.listEquals([1, 9, 10, 6], list); |
| 55 | 67 |
| 56 testNegativeIndices(); | 68 testNegativeIndices(); |
| 57 | 69 |
| 58 testNonExtendableList(); | 70 testNonExtendableList(); |
| 59 } | 71 } |
| 60 | 72 |
| 61 void expectIOORE(Function f) { | 73 void expectIOORE(Function f) { |
| 62 Expect.throws(f, (e) => e is RangeError); | 74 Expect.throws(f, (e) => e is RangeError); |
| 63 } | 75 } |
| 64 | 76 |
| 65 void expectSE(Function f) { | 77 void expectSE(Function f) { |
| 66 Expect.throws(f, (e) => e is StateError); | 78 Expect.throws(f, (e) => e is StateError); |
| 67 } | 79 } |
| 68 | 80 |
| 69 void expectAE(Function f) { | 81 void expectAE(Function f) { |
| 70 Expect.throws(f, (e) => e is ArgumentError); | 82 Expect.throws(f, (e) => e is ArgumentError); |
| 71 } | 83 } |
| 72 | 84 |
| 73 void testNegativeIndices() { | 85 void testNegativeIndices() { |
| 74 var list = [1, 2]; | 86 var list = [1, 2]; |
| 75 expectIOORE(() { list.setRange(-1, 1, [1]); }); | 87 expectIOORE(() { |
| 76 expectAE(() { list.setRange(0, 1, [1], -1); }); | 88 list.setRange(-1, 1, [1]); |
| 89 }); |
| 90 expectAE(() { |
| 91 list.setRange(0, 1, [1], -1); |
| 92 }); |
| 77 | 93 |
| 78 // A negative length throws an ArgumentError. | 94 // A negative length throws an ArgumentError. |
| 79 expectIOORE(() { list.setRange(2, 1, [1]); }); | 95 expectIOORE(() { |
| 96 list.setRange(2, 1, [1]); |
| 97 }); |
| 80 | 98 |
| 81 expectAE(() { list.setRange(-1, -2, [1], -1); }); | 99 expectAE(() { |
| 100 list.setRange(-1, -2, [1], -1); |
| 101 }); |
| 82 Expect.listEquals([1, 2], list); | 102 Expect.listEquals([1, 2], list); |
| 83 | 103 |
| 84 expectIOORE(() { list.setRange(-1, -1, [1]); }); | 104 expectIOORE(() { |
| 105 list.setRange(-1, -1, [1]); |
| 106 }); |
| 85 Expect.listEquals([1, 2], list); | 107 Expect.listEquals([1, 2], list); |
| 86 | 108 |
| 87 // The skipCount is only used if the length is not 0. | 109 // The skipCount is only used if the length is not 0. |
| 88 list.setRange(0, 0, [1], -1); | 110 list.setRange(0, 0, [1], -1); |
| 89 Expect.listEquals([1, 2], list); | 111 Expect.listEquals([1, 2], list); |
| 90 } | 112 } |
| 91 | 113 |
| 92 void testNonExtendableList() { | 114 void testNonExtendableList() { |
| 93 var list = new List<int>(6); | 115 var list = new List<int>(6); |
| 94 Expect.listEquals([null, null, null, null, null, null], list); | 116 Expect.listEquals([null, null, null, null, null, null], list); |
| 95 list.setRange(0, 3, [1, 2, 3, 4]); | 117 list.setRange(0, 3, [1, 2, 3, 4]); |
| 96 list.setRange(3, 6, [1, 2, 3, 4]); | 118 list.setRange(3, 6, [1, 2, 3, 4]); |
| 97 Expect.listEquals([1, 2, 3, 1, 2, 3], list); | 119 Expect.listEquals([1, 2, 3, 1, 2, 3], list); |
| 98 } | 120 } |
| OLD | NEW |