mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:51:30 +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>
76 lines
2.2 KiB
Dart
76 lines
2.2 KiB
Dart
// Copyright (c) 2018, 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 "dart:typed_data";
|
|
import "package:expect/expect.dart";
|
|
|
|
void main() {
|
|
test([1, 2, 3, 4], [5, 6], 2, [1, 2, 5, 6]);
|
|
test([1, 2, 3, 4], [5, 6], 0, [5, 6, 3, 4]);
|
|
test([1, 2, 3, 4], [5, 6], 1, [1, 5, 6, 4]);
|
|
test([1, 2, 3, 4], [], 2, [1, 2, 3, 4]);
|
|
test([1, 2, 3, 4], [5, 6], 2, [1, 2, 5, 6]);
|
|
test([1, 2, 3, 4], [5, 6], 2, [1, 2, 5, 6]);
|
|
test([1, 2, 3, 4], [5, 6], 2, [1, 2, 5, 6]);
|
|
test([], [], 0, []);
|
|
test([1], [2], 0, [2]);
|
|
|
|
// Other (non-list) iterables.
|
|
test([1, 2, 3, 4], new Iterable.generate(2, (x) => x + 7), 1, [1, 7, 8, 4]);
|
|
test([1, 2, 3, 4], [9, 9, 5, 6].skip(2), 1, [1, 5, 6, 4]);
|
|
test([1, 2, 3, 4], [5, 6, 9, 9].take(2), 1, [1, 5, 6, 4]);
|
|
test([1, 2, 3, 4], [9, 5, 9, 6, 9, 9].where((x) => x != 9), 1, [1, 5, 6, 4]);
|
|
test([1, 2, 3, 4], new Set.from([5, 6]), 1, [1, 5, 6, 4]);
|
|
|
|
// Other types of lists.
|
|
test(new Uint8List(4), [5, 6], 1, [0, 5, 6, 0]);
|
|
test(new Uint8List(4), [-5, 6], 1, [0, 256 - 5, 6, 0]);
|
|
|
|
// Over-long iterables. Updates until end, then throws.
|
|
testThrows([], [1], 0);
|
|
testThrows([2], [1], 1);
|
|
testThrows([2], [1], 1);
|
|
testThrows([1, 2, 3, 4], [5, 6, 7, 8], 2, [1, 2, 5, 6]);
|
|
|
|
// Throwing iterable.
|
|
Expect.throws(() {
|
|
Iterable<int> throwingIterable() sync* {
|
|
yield 1;
|
|
throw "2";
|
|
}
|
|
|
|
List.writeIterable([1, 2, 3], 1, throwingIterable());
|
|
}, (e) => e == "2");
|
|
|
|
// Bad start index.
|
|
testThrows([1, 2], [1], -1);
|
|
testThrows([1, 2], [1], 2);
|
|
|
|
// Working at a supertype is practical and useful.
|
|
test<Object>(<int>[1, 2, 3, 4], <num>[5, 6], 1, [1, 5, 6, 4]);
|
|
|
|
var d = new D();
|
|
test<Object?>(<B?>[null], <C>[d], 0, [d]);
|
|
}
|
|
|
|
testThrows<T>(list, iterable, start, [expect]) {
|
|
Expect.throws(() {
|
|
List.writeIterable<T>(list, start, iterable);
|
|
});
|
|
if (expect != null) {
|
|
Expect.listEquals(expect, list);
|
|
}
|
|
}
|
|
|
|
test<T>(List<T> list, Iterable<T> iterable, int start, List expect) {
|
|
List.writeIterable<T>(list, start, iterable);
|
|
Expect.listEquals(expect, list);
|
|
}
|
|
|
|
class B {}
|
|
|
|
class C {}
|
|
|
|
class D implements B, C {}
|