mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:43:32 +00:00
96cea64fa6
Change-Id: I0a63a6864c568491ad5e20b6eb490760e620a889 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130200 Commit-Queue: Mark Zhou <markzipan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
73 lines
2.5 KiB
Dart
73 lines
2.5 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import "package:expect/expect.dart";
|
|
import "dart:collection";
|
|
|
|
test(List list, int start, int end, [fillValue = 42]) {
|
|
List copy = list.toList();
|
|
list.fillRange(start, end, fillValue);
|
|
Expect.equals(copy.length, list.length);
|
|
for (int i = 0; i < start; i++) {
|
|
Expect.equals(copy[i], list[i]);
|
|
}
|
|
for (int i = start; i < end; i++) {
|
|
Expect.equals(fillValue, list[i]);
|
|
}
|
|
for (int i = end; i < list.length; i++) {
|
|
Expect.equals(copy[i], list[i]);
|
|
}
|
|
}
|
|
|
|
class MyList extends ListBase {
|
|
List list;
|
|
MyList(this.list);
|
|
get length => list.length;
|
|
set length(value) {
|
|
list.length = value;
|
|
}
|
|
|
|
operator [](index) => list[index];
|
|
operator []=(index, val) {
|
|
list[index] = val;
|
|
}
|
|
|
|
toString() => list.toString();
|
|
}
|
|
|
|
main() {
|
|
test([1, 2, 3], 0, 1);
|
|
test([1, 2, 3], 0, 1, 99);
|
|
test([1, 2, 3], 1, 1);
|
|
test([1, 2, 3], 1, 1, 499);
|
|
test([1, 2, 3], 3, 3);
|
|
test([1, 2, 3], 3, 3, 499);
|
|
test([1, 2, 3].toList(growable: false), 0, 1);
|
|
test([1, 2, 3].toList(growable: false), 0, 1, 99);
|
|
test([1, 2, 3].toList(growable: false), 1, 1);
|
|
test([1, 2, 3].toList(growable: false), 1, 1, 499);
|
|
test([1, 2, 3].toList(growable: false), 3, 3);
|
|
test([1, 2, 3].toList(growable: false), 3, 3, 499);
|
|
test(new MyList([1, 2, 3]), 0, 1);
|
|
test(new MyList([1, 2, 3]), 0, 1, 99);
|
|
test(new MyList([1, 2, 3]), 1, 1);
|
|
test(new MyList([1, 2, 3]), 1, 1, 499);
|
|
test(new MyList([1, 2, 3]), 3, 3);
|
|
test(new MyList([1, 2, 3]), 3, 3, 499);
|
|
|
|
Expect.throwsRangeError(() => test([1, 2, 3], -1, 0));
|
|
Expect.throwsRangeError(() => test([1, 2, 3], 2, 1));
|
|
Expect.throwsRangeError(() => test([1, 2, 3], 0, -1));
|
|
Expect.throwsRangeError(() => test([1, 2, 3], 1, 4));
|
|
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), -1, 0));
|
|
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 2, 1));
|
|
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 0, -1));
|
|
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 1, 4));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 2, 3));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], -1, 0));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 2, 1));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 0, -1));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 1, 4));
|
|
}
|