| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, 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 import "dart:collection"; |
| 7 |
| 8 test(List list, int start, int end, Iterable iterable) { |
| 9 List copy = list.toList(); |
| 10 list.replaceRange(start, end, iterable); |
| 11 List iterableList = iterable.toList(); |
| 12 Expect.equals(copy.length + iterableList.length - (end - start), list.length); |
| 13 for (int i = 0; i < start; i++) { |
| 14 Expect.equals(copy[i], list[i]); |
| 15 } |
| 16 for (int i = 0; i < iterableList.length; i++) { |
| 17 Expect.equals(iterableList[i], list[i + start]); |
| 18 } |
| 19 int removedLength = end - start; |
| 20 for (int i = end; i < copy.length; i++) { |
| 21 Expect.equals(copy[i], list[i + iterableList.length - removedLength]); |
| 22 } |
| 23 } |
| 24 |
| 25 class MyList extends ListBase { |
| 26 List list; |
| 27 MyList(this.list); |
| 28 get length => list.length; |
| 29 set length(value) { list.length = value; } |
| 30 operator [](index) => list[index]; |
| 31 operator []=(index, val) { list[index] = val; } |
| 32 toString() => list.toString(); |
| 33 } |
| 34 |
| 35 main() { |
| 36 test([1, 2, 3], 0, 1, [4, 5]); |
| 37 test([1, 2, 3], 1, 1, [4, 5]); |
| 38 test([1, 2, 3], 2, 3, [4, 5]); |
| 39 test([1, 2, 3], 3, 3, [4, 5]); |
| 40 test([1, 2, 3], 0, 3, [4, 5]); |
| 41 test([1, 2, 3], 2, 3, [4]); |
| 42 test([1, 2, 3], 0, 3, []); |
| 43 test([1, 2, 3], 0, 1, [4, 5].map((x) => x)); |
| 44 test([1, 2, 3], 1, 1, [4, 5].map((x) => x)); |
| 45 test([1, 2, 3], 2, 3, [4, 5].map((x) => x)); |
| 46 test([1, 2, 3], 3, 3, [4, 5].map((x) => x)); |
| 47 test([1, 2, 3], 0, 3, [4, 5].map((x) => x)); |
| 48 test([1, 2, 3], 2, 3, [4].map((x) => x)); |
| 49 test([1, 2, 3], 0, 3, [].map((x) => x)); |
| 50 test([1, 2, 3], 0, 1, const [4, 5]); |
| 51 test([1, 2, 3], 1, 1, const [4, 5]); |
| 52 test([1, 2, 3], 2, 3, const [4, 5]); |
| 53 test([1, 2, 3], 3, 3, const [4, 5]); |
| 54 test([1, 2, 3], 0, 3, const [4, 5]); |
| 55 test([1, 2, 3], 2, 3, const [4]); |
| 56 test([1, 2, 3], 0, 3, const []); |
| 57 test([1, 2, 3], 0, 1, new Iterable.generate(2, (x) => x + 4)); |
| 58 test([1, 2, 3], 1, 1, new Iterable.generate(2, (x) => x + 4)); |
| 59 test([1, 2, 3], 2, 3, new Iterable.generate(2, (x) => x + 4)); |
| 60 test([1, 2, 3], 3, 3, new Iterable.generate(2, (x) => x + 4)); |
| 61 test([1, 2, 3], 0, 3, new Iterable.generate(2, (x) => x + 4)); |
| 62 test([1, 2, 3], 2, 3, new Iterable.generate(2, (x) => x + 4)); |
| 63 test(new MyList([1, 2, 3]), 0, 1, [4, 5]); |
| 64 test(new MyList([1, 2, 3]), 1, 1, [4, 5]); |
| 65 test(new MyList([1, 2, 3]), 2, 3, [4, 5]); |
| 66 test(new MyList([1, 2, 3]), 3, 3, [4, 5]); |
| 67 test(new MyList([1, 2, 3]), 0, 3, [4, 5]); |
| 68 test(new MyList([1, 2, 3]), 2, 3, [4]); |
| 69 test(new MyList([1, 2, 3]), 0, 3, []); |
| 70 test(new MyList([1, 2, 3]), 0, 1, [4, 5].map((x) => x)); |
| 71 test(new MyList([1, 2, 3]), 1, 1, [4, 5].map((x) => x)); |
| 72 test(new MyList([1, 2, 3]), 2, 3, [4, 5].map((x) => x)); |
| 73 test(new MyList([1, 2, 3]), 3, 3, [4, 5].map((x) => x)); |
| 74 test(new MyList([1, 2, 3]), 0, 3, [4, 5].map((x) => x)); |
| 75 test(new MyList([1, 2, 3]), 2, 3, [4].map((x) => x)); |
| 76 test(new MyList([1, 2, 3]), 0, 3, [].map((x) => x)); |
| 77 test(new MyList([1, 2, 3]), 0, 1, const [4, 5]); |
| 78 test(new MyList([1, 2, 3]), 1, 1, const [4, 5]); |
| 79 test(new MyList([1, 2, 3]), 2, 3, const [4, 5]); |
| 80 test(new MyList([1, 2, 3]), 3, 3, const [4, 5]); |
| 81 test(new MyList([1, 2, 3]), 0, 3, const [4, 5]); |
| 82 test(new MyList([1, 2, 3]), 2, 3, const [4]); |
| 83 test(new MyList([1, 2, 3]), 0, 3, const []); |
| 84 test(new MyList([1, 2, 3]), 0, 1, new Iterable.generate(2, (x) => x + 4)); |
| 85 test(new MyList([1, 2, 3]), 1, 1, new Iterable.generate(2, (x) => x + 4)); |
| 86 test(new MyList([1, 2, 3]), 2, 3, new Iterable.generate(2, (x) => x + 4)); |
| 87 test(new MyList([1, 2, 3]), 3, 3, new Iterable.generate(2, (x) => x + 4)); |
| 88 test(new MyList([1, 2, 3]), 0, 3, new Iterable.generate(2, (x) => x + 4)); |
| 89 test(new MyList([1, 2, 3]), 2, 3, new Iterable.generate(2, (x) => x + 4)); |
| 90 |
| 91 expectRE(() => test([1, 2, 3], -1, 0, [])); |
| 92 expectRE(() => test([1, 2, 3], 2, 1, [])); |
| 93 expectRE(() => test([1, 2, 3], 0, -1, [])); |
| 94 expectRE(() => test([1, 2, 3], 1, 4, [])); |
| 95 expectRE(() => test(new MyList([1, 2, 3]), -1, 0, [])); |
| 96 expectRE(() => test(new MyList([1, 2, 3]), 2, 1, [])); |
| 97 expectRE(() => test(new MyList([1, 2, 3]), 0, -1, [])); |
| 98 expectRE(() => test(new MyList([1, 2, 3]), 1, 4, [])); |
| 99 expectUE(() => test([1, 2, 3].toList(growable: false), 2, 3, [])); |
| 100 expectUE(() => test([1, 2, 3].toList(growable: false), -1, 0, [])); |
| 101 expectUE(() => test([1, 2, 3].toList(growable: false), 2, 1, [])); |
| 102 expectUE(() => test([1, 2, 3].toList(growable: false), 0, -1, [])); |
| 103 expectUE(() => test([1, 2, 3].toList(growable: false), 1, 4, [])); |
| 104 expectUE(() => test(const [1, 2, 3], 2, 3, [])); |
| 105 expectUE(() => test(const [1, 2, 3], -1, 0, [])); |
| 106 expectUE(() => test(const [1, 2, 3], 2, 1, [])); |
| 107 expectUE(() => test(const [1, 2, 3], 0, -1, [])); |
| 108 expectUE(() => test(const [1, 2, 3], 1, 4, [])); |
| 109 } |
| 110 |
| 111 void expectRE(Function f) { |
| 112 Expect.throws(f, (e) => e is RangeError); |
| 113 } |
| 114 |
| 115 void expectUE(Function f) { |
| 116 Expect.throws(f, (e) => e is UnsupportedError); |
| 117 } |
| OLD | NEW |