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