| 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.insertAll(index, iterable); |
| 11 List iterableList = iterable.toList(); |
| 12 Expect.equals(copy.length + iterableList.length, list.length); |
| 13 for (int i = 0; i < index; 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 + index]); |
| 18 } |
| 19 for (int i = index + iterableList.length; i < copy.length; i++) { |
| 20 Expect.equals(copy[i], list[i + iterableList.length]); |
| 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, 5]); |
| 38 test([1, 2, 3], 3, [4, 5]); |
| 39 test([1, 2, 3], 2, [4]); |
| 40 test([1, 2, 3], 3, []); |
| 41 test([1, 2, 3], 0, [4, 5].map((x) => x)); |
| 42 test([1, 2, 3], 1, [4, 5].map((x) => x)); |
| 43 test([1, 2, 3], 2, [4, 5].map((x) => x)); |
| 44 test([1, 2, 3], 3, [4, 5].map((x) => x)); |
| 45 test([1, 2, 3], 2, [4].map((x) => x)); |
| 46 test([1, 2, 3], 3, [].map((x) => x)); |
| 47 test([1, 2, 3], 0, const [4, 5]); |
| 48 test([1, 2, 3], 1, const [4, 5]); |
| 49 test([1, 2, 3], 2, const [4, 5]); |
| 50 test([1, 2, 3], 3, const [4 ,5]); |
| 51 test([1, 2, 3], 2, const [4]); |
| 52 test([1, 2, 3], 3, const []); |
| 53 test([1, 2, 3], 0, new Iterable.generate(2, (x) => x + 4)); |
| 54 test([1, 2, 3], 1, new Iterable.generate(2, (x) => x + 4)); |
| 55 test([1, 2, 3], 2, new Iterable.generate(2, (x) => x + 4)); |
| 56 test([1, 2, 3], 3, new Iterable.generate(2, (x) => x + 4)); |
| 57 test([1, 2, 3], 2, new Iterable.generate(1, (x) => x + 4)); |
| 58 test([1, 2, 3], 3, new Iterable.generate(0, (x) => x + 4)); |
| 59 test(new MyList([1, 2, 3]), 0, [4, 5]); |
| 60 test(new MyList([1, 2, 3]), 1, [4, 5]); |
| 61 test(new MyList([1, 2, 3]), 2, [4]); |
| 62 test(new MyList([1, 2, 3]), 3, []); |
| 63 test(new MyList([1, 2, 3]), 2, [4, 5]); |
| 64 test(new MyList([1, 2, 3]), 3, [4, 5]); |
| 65 test(new MyList([1, 2, 3]), 0, [4, 5].map((x) => x)); |
| 66 test(new MyList([1, 2, 3]), 1, [4, 5].map((x) => x)); |
| 67 test(new MyList([1, 2, 3]), 2, [4, 5].map((x) => x)); |
| 68 test(new MyList([1, 2, 3]), 3, [4, 5].map((x) => x)); |
| 69 test(new MyList([1, 2, 3]), 2, [4].map((x) => x)); |
| 70 test(new MyList([1, 2, 3]), 3, [].map((x) => x)); |
| 71 |
| 72 expectRE(() => test([1, 2, 3], -1, [4, 5])); |
| 73 expectUE(() => test([1, 2, 3].toList(growable: false), -1, [4, 5])); |
| 74 expectRE(() => test(new MyList([1, 2, 3]), -1, [4, 5])); |
| 75 expectUE(() => test([1, 2, 3].toList(growable: false), 0, [4, 5])); |
| 76 } |
| 77 |
| 78 void expectRE(Function f) { |
| 79 Expect.throws(f, (e) => e is RangeError); |
| 80 } |
| 81 |
| 82 void expectUE(Function f) { |
| 83 Expect.throws(f, (e) => e is UnsupportedError); |
| 84 } |
| OLD | NEW |