mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:11:19 +00:00
02a8b015ad
Change-Id: I1783f624c7ce7d3b962c301c27ac0f4422d7c28f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126824 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
98 lines
3.8 KiB
Dart
98 lines
3.8 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<int> list, int index, Iterable<int> iterable) {
|
|
List copy = list.toList();
|
|
list.setAll(index, iterable);
|
|
Expect.equals(copy.length, list.length);
|
|
for (int i = 0; i < index; i++) {
|
|
Expect.equals(copy[i], list[i]);
|
|
}
|
|
List iterableList = iterable.toList();
|
|
for (int i = 0; i < iterableList.length; i++) {
|
|
Expect.equals(iterableList[i], list[i + index]);
|
|
}
|
|
for (int i = index + iterableList.length; i < copy.length; i++) {
|
|
Expect.equals(copy[i], list[i]);
|
|
}
|
|
}
|
|
|
|
class MyList<T> extends ListBase<T> {
|
|
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, [4, 5]);
|
|
test([1, 2, 3], 1, [4, 5]);
|
|
test([1, 2, 3], 2, [4]);
|
|
test([1, 2, 3], 3, []);
|
|
test([1, 2, 3], 0, [4, 5].map((x) => x));
|
|
test([1, 2, 3], 1, [4, 5].map((x) => x));
|
|
test([1, 2, 3], 2, [4].map((x) => x));
|
|
test([1, 2, 3], 3, [].map((x) => x));
|
|
test([1, 2, 3], 0, const [4, 5]);
|
|
test([1, 2, 3], 1, const [4, 5]);
|
|
test([1, 2, 3], 2, const [4]);
|
|
test([1, 2, 3], 3, const []);
|
|
test([1, 2, 3], 0, new Iterable.generate(2, (x) => x + 4));
|
|
test([1, 2, 3], 1, new Iterable.generate(2, (x) => x + 4));
|
|
test([1, 2, 3], 2, new Iterable.generate(1, (x) => x + 4));
|
|
test([1, 2, 3], 3, new Iterable.generate(0, (x) => x + 4));
|
|
test([1, 2, 3].toList(growable: false), 0, [4, 5]);
|
|
test([1, 2, 3].toList(growable: false), 1, [4, 5]);
|
|
test([1, 2, 3].toList(growable: false), 2, [4]);
|
|
test([1, 2, 3].toList(growable: false), 3, []);
|
|
test([1, 2, 3].toList(growable: false), 0, [4, 5].map((x) => x));
|
|
test([1, 2, 3].toList(growable: false), 1, [4, 5].map((x) => x));
|
|
test([1, 2, 3].toList(growable: false), 2, [4].map((x) => x));
|
|
test([1, 2, 3].toList(growable: false), 3, [].map((x) => x));
|
|
test([1, 2, 3].toList(growable: false), 0, const [4, 5]);
|
|
test([1, 2, 3].toList(growable: false), 1, const [4, 5]);
|
|
test([1, 2, 3].toList(growable: false), 2, const [4]);
|
|
test([1, 2, 3].toList(growable: false), 3, const []);
|
|
test([1, 2, 3].toList(growable: false), 0,
|
|
new Iterable.generate(2, (x) => x + 4));
|
|
test([1, 2, 3].toList(growable: false), 1,
|
|
new Iterable.generate(2, (x) => x + 4));
|
|
test([1, 2, 3].toList(growable: false), 2,
|
|
new Iterable.generate(1, (x) => x + 4));
|
|
test([1, 2, 3].toList(growable: false), 3,
|
|
new Iterable.generate(0, (x) => x + 4));
|
|
test(new MyList([1, 2, 3]), 0, [4, 5]);
|
|
test(new MyList([1, 2, 3]), 1, [4, 5]);
|
|
test(new MyList([1, 2, 3]), 2, [4]);
|
|
test(new MyList([1, 2, 3]), 3, []);
|
|
test(new MyList([1, 2, 3]), 0, [4, 5].map((x) => x));
|
|
test(new MyList([1, 2, 3]), 1, [4, 5].map((x) => x));
|
|
test(new MyList([1, 2, 3]), 2, [4].map((x) => x));
|
|
test(new MyList([1, 2, 3]), 3, [].map((x) => x));
|
|
|
|
Expect.throwsRangeError(() => test([1, 2, 3], -1, [4, 5]));
|
|
Expect.throwsRangeError(
|
|
() => test([1, 2, 3].toList(growable: false), -1, [4, 5]));
|
|
Expect.throwsRangeError(() => test([1, 2, 3], 1, [4, 5, 6]));
|
|
Expect.throwsRangeError(
|
|
() => test([1, 2, 3].toList(growable: false), 1, [4, 5, 6]));
|
|
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), -1, [4, 5]));
|
|
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 1, [4, 5, 6]));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 0, [4, 5]));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], -1, [4, 5]));
|
|
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 1, [4, 5, 6]));
|
|
}
|