[test] Remove use of List constructor in corelib tests

Change-Id: I00777f1db859d075f7dfda21a72e7982d155747e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142371
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Johnni Winther 2020-04-17 08:45:46 +00:00 committed by commit-bot@chromium.org
parent ae0eca8318
commit 29ac98ea46
4 changed files with 30 additions and 21 deletions

View file

@ -71,6 +71,7 @@ main() {
testCollection(new ListQueue(), N);
testCollection(new DoubleLinkedQueue(), N);
testList([]..length = N, N);
testList(new List.filled(0, null, growable: true)..length = N, N);
testList(new List.filled(N, null), N);
testString(N);
}

View file

@ -8,9 +8,10 @@ import "package:expect/expect.dart";
void main() {
// Growable lists. Initial length 0.
testConcurrentModification(new List());
testConcurrentModification(new List<int>().toList());
testConcurrentModification(new List<int?>(0).toList());
testConcurrentModification(<int>[].toList());
testConcurrentModification(
new List<int>.filled(0, null, growable: true).toList());
testConcurrentModification(new List<int?>.filled(0, null).toList());
testConcurrentModification(new List.filled(0, null, growable: true));
testConcurrentModification([]);
testConcurrentModification(new List.from(const []));

View file

@ -25,7 +25,10 @@ void testModifiableList(l1) {
// Index must be integer and in range.
Expect.throwsRangeError(() => l1.removeAt(-1), "negative");
Expect.throwsRangeError(() => l1.removeAt(5), "too large");
Expect.throwsArgumentError(() => l1.removeAt(null), "too large");
Expect.throws(() => l1.removeAt(null),
// With --null-safety a TypeError is thrown
// With --no-null-safety an ArgumentError is thrown
(e) => e is TypeError || e is ArgumentError, "is null");
Expect.equals(2, l1.removeAt(2), "l1-remove2");
Expect.equals(1, l1[1], "l1-1[1]");
@ -47,7 +50,7 @@ void main() {
testModifiableList(new MyList([0, 1, 2, 3, 4]));
// Fixed size list.
var l2 = new List(5);
var l2 = new List<int?>.filled(5, null);
for (var i = 0; i < 5; i++) l2[i] = i;
Expect.throwsUnsupportedError(() => l2.removeAt(2), "fixed-length");

View file

@ -22,17 +22,21 @@ void main() {
testTypedList(new Int32List(4).toList(growable: false));
// Fixed length lists, length 4.
testFixedLengthList(<T>() => new List<T?>(4));
testFixedLengthList(<T>() => new List<T?>(4).toList(growable: false));
testFixedLengthList(<T>() => (new List<T?>()..length = 4).toList(growable: false));
testFixedLengthList(<T>() => new List<T?>.filled(4, null));
testFixedLengthList(
<T>() => new List<T?>.filled(4, null).toList(growable: false));
testFixedLengthList(<T>() => (<T?>[]..length = 4).toList(growable: false));
testFixedLengthList(<T>() => (new List<T?>.filled(0, null, growable: true)
..length = 4)
.toList(growable: false));
// ListBase implementation of List.
testFixedLengthList(<T>() => new MyFixedList(new List<T?>(4)));
testFixedLengthList(<T>() => new MyFixedList<T?>(new List<T?>(4)).toList(growable: false));
testFixedLengthList(<T>() => new MyFixedList(new List<T?>.filled(4, null)));
testFixedLengthList(<T>() => new MyFixedList<T?>(new List<T?>.filled(4, null))
.toList(growable: false));
// Growable lists. Initial length 0.
testGrowableList(<T>() => new List());
testGrowableList(<T>() => new List<T?>().toList());
testGrowableList(<T>() => new List<T?>(0).toList());
testGrowableList(<T>() => <T?>[].toList());
testGrowableList(<T>() => new List<T?>.filled(0, null).toList());
testGrowableList(<T>() => new List<T?>.filled(0, null, growable: true));
testGrowableList(<T>() => []);
testGrowableList(<T>() => new List.from(const []));
@ -118,7 +122,7 @@ void testErrors() {
// Empty lists.
testRangeErrors([], "list");
testRangeErrors(new List(0), "fixed-list");
testRangeErrors(new List.filled(0, null), "fixed-list");
testRangeErrors(const [], "const-list");
testRangeErrors(new List.unmodifiable([]), "unmodifiable");
testRangeErrors(new Uint8List(0), "typed-list");
@ -126,7 +130,7 @@ void testErrors() {
testRangeErrors([1, 2, 3].sublist(1, 1), "sub-list");
// Non-empty lists.
testRangeErrors([1, 2, 3], "list");
testRangeErrors(new List(3), "fixed-list");
testRangeErrors(new List.filled(3, null), "fixed-list");
testRangeErrors(const [1, 2, 3], "const-list");
testRangeErrors(new List.unmodifiable([1, 2, 3]), "unmodifiable");
testRangeErrors(new Uint8List(3), "typed-list");
@ -279,8 +283,8 @@ void testUntypedListTests(List list) {
void testLengthInvariantOperations(List<int?> list) {
testTypedLengthInvariantOperations(list);
Expect.throwsTypeError(() => testUntypedListTests(list),
'List<int> cannot store non-ints');
Expect.throwsTypeError(
() => testUntypedListTests(list), 'List<int> cannot store non-ints');
// Argument errors on bad indices. List is still [0, 1, 2, 3].
@ -568,11 +572,11 @@ class MyFixedList<E> extends ListBase<E> {
void testListConstructor() {
// Is fixed-length.
Expect.throws(() => new List(0).add(4));
Expect.throws(() => new List(-2)); // Not negative. //# 01: ok
Expect.throws(() => new List<int?>.filled(0, null).add(4));
Expect.throws(() => new List.filled(-2, null)); // Not negative. //# 01: ok
// Not null.
Expect.throws(() => new List(null));
Expect.listEquals([4], new List()..add(4));
Expect.throws(() => new List.filled(null, null));
Expect.listEquals([4], <int>[]..add(4));
// Is fixed-length.
Expect.throws(() => new List.filled(0, 42).add(4));
// Not negative.