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