| 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, [fillValue]) { |
| 9 List copy = list.toList(); |
| 10 if (?fillValue) { |
| 11 list.fillRange(start, end, fillValue); |
| 12 } else { |
| 13 list.fillRange(start, end, fillValue); |
| 14 } |
| 15 Expect.equals(copy.length, list.length); |
| 16 for (int i = 0; i < start; i++) { |
| 17 Expect.equals(copy[i], list[i]); |
| 18 } |
| 19 for (int i = start; i < end; i++) { |
| 20 Expect.equals(fillValue, list[i]); |
| 21 } |
| 22 for (int i = end; i < list.length; i++) { |
| 23 Expect.equals(copy[i], list[i]); |
| 24 } |
| 25 } |
| 26 |
| 27 class MyList extends ListBase { |
| 28 List list; |
| 29 MyList(this.list); |
| 30 get length => list.length; |
| 31 set length(value) { list.length = value; } |
| 32 operator [](index) => list[index]; |
| 33 operator []=(index, val) { list[index] = val; } |
| 34 toString() => list.toString(); |
| 35 } |
| 36 |
| 37 main() { |
| 38 test([1, 2, 3], 0, 1); |
| 39 test([1, 2, 3], 0, 1, 99); |
| 40 test([1, 2, 3], 1, 1); |
| 41 test([1, 2, 3], 1, 1, 499); |
| 42 test([1, 2, 3], 3, 3); |
| 43 test([1, 2, 3], 3, 3, 499); |
| 44 test([1, 2, 3].toList(growable: false), 0, 1); |
| 45 test([1, 2, 3].toList(growable: false), 0, 1, 99); |
| 46 test([1, 2, 3].toList(growable: false), 1, 1); |
| 47 test([1, 2, 3].toList(growable: false), 1, 1, 499); |
| 48 test([1, 2, 3].toList(growable: false), 3, 3); |
| 49 test([1, 2, 3].toList(growable: false), 3, 3, 499); |
| 50 test(new MyList([1, 2, 3]), 0, 1); |
| 51 test(new MyList([1, 2, 3]), 0, 1, 99); |
| 52 test(new MyList([1, 2, 3]), 1, 1); |
| 53 test(new MyList([1, 2, 3]), 1, 1, 499); |
| 54 test(new MyList([1, 2, 3]), 3, 3); |
| 55 test(new MyList([1, 2, 3]), 3, 3, 499); |
| 56 |
| 57 expectRE(() => test([1, 2, 3], -1, 0)); |
| 58 expectRE(() => test([1, 2, 3], 2, 1)); |
| 59 expectRE(() => test([1, 2, 3], 0, -1)); |
| 60 expectRE(() => test([1, 2, 3], 1, 4)); |
| 61 expectRE(() => test(new MyList([1, 2, 3]), -1, 0)); |
| 62 expectRE(() => test(new MyList([1, 2, 3]), 2, 1)); |
| 63 expectRE(() => test(new MyList([1, 2, 3]), 0, -1)); |
| 64 expectRE(() => test(new MyList([1, 2, 3]), 1, 4)); |
| 65 expectUE(() => test(const [1, 2, 3], 2, 3)); |
| 66 expectUE(() => test(const [1, 2, 3], -1, 0)); |
| 67 expectUE(() => test(const [1, 2, 3], 2, 1)); |
| 68 expectUE(() => test(const [1, 2, 3], 0, -1)); |
| 69 expectUE(() => test(const [1, 2, 3], 1, 4)); |
| 70 } |
| 71 |
| 72 void expectRE(Function f) { |
| 73 Expect.throws(f, (e) => e is RangeError); |
| 74 } |
| 75 |
| 76 void expectUE(Function f) { |
| 77 Expect.throws(f, (e) => e is UnsupportedError); |
| 78 } |
| OLD | NEW |