Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: tests/corelib_2/list_test.dart

Issue 3009623002: fix list_test for strong mode, and fix DDC List constructors (Closed)
Patch Set: update status, one additional fix Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/corelib_2/list_test.dart
diff --git a/tests/corelib_2/list_test.dart b/tests/corelib_2/list_test.dart
index 0323c1de89dafea2cfaaed3e26a917b21e4e4433..dcc646a8d6b93a300520b87e40c4f121cc9b74b0 100644
--- a/tests/corelib_2/list_test.dart
+++ b/tests/corelib_2/list_test.dart
@@ -22,22 +22,22 @@ void main() {
testTypedList(new Int32List(4).toList(growable: false));
// Fixed length lists, length 4.
- testFixedLengthList(new List(4));
- testFixedLengthList(new List(4).toList(growable: false));
- testFixedLengthList((new List()..length = 4).toList(growable: false));
+ testFixedLengthList(<T>() => new List(4));
+ testFixedLengthList(<T>() => new List<T>(4).toList(growable: false));
+ testFixedLengthList(<T>() => (new List<T>()..length = 4).toList(growable: false));
// ListBase implementation of List.
- testFixedLengthList(new MyFixedList(new List(4)));
- testFixedLengthList(new MyFixedList(new List(4)).toList(growable: false));
+ testFixedLengthList(<T>() => new MyFixedList(new List(4)));
+ testFixedLengthList(<T>() => new MyFixedList<T>(new List(4)).toList(growable: false));
// Growable lists. Initial length 0.
- testGrowableList(new List());
- testGrowableList(new List().toList());
- testGrowableList(new List(0).toList());
- testGrowableList(new List.filled(0, null, growable: true));
- testGrowableList([]);
- testGrowableList((const []).toList());
- testGrowableList(new MyList([]));
- testGrowableList(new MyList([]).toList());
+ testGrowableList(<T>() => new List());
+ testGrowableList(<T>() => new List<T>().toList());
+ testGrowableList(<T>() => new List<T>(0).toList());
+ testGrowableList(<T>() => new List.filled(0, null, growable: true));
+ testGrowableList(<T>() => []);
+ testGrowableList(<T>() => new List.from(const []));
+ testGrowableList(<T>() => new MyList([]));
+ testGrowableList(<T>() => new MyList<T>([]).toList());
testTypedGrowableList(new Uint8List(0).toList());
testTypedGrowableList(new Int8List(0).toList());
@@ -140,7 +140,7 @@ void testLength(int length, List list) {
(length != 0 ? Expect.isTrue : Expect.isFalse)(list.isNotEmpty);
}
-void testTypedLengthInvariantOperations(List list) {
+void testTypedLengthInvariantOperations(List<int> list) {
// length
Expect.equals(list.length, 4);
// operators [], []=.
@@ -257,8 +257,7 @@ void testTypedLengthInvariantOperations(List list) {
// so it's moved to the method below for now.
}
-void testLengthInvariantOperations(List list) {
- testTypedLengthInvariantOperations(list);
+void testUntypedListTests(List list) {
// Tests that need untyped lists.
list.setAll(0, [0, 1, 2, 3]);
Expect.equals(-1, list.indexOf(100));
@@ -275,6 +274,14 @@ void testLengthInvariantOperations(List list) {
list[3] = 3;
Expect.equals(-1, list.indexOf(100));
Expect.equals(-1, list.lastIndexOf(100));
+}
+
+void testLengthInvariantOperations(List<int> list) {
+ testTypedLengthInvariantOperations(list);
+
+ Expect.throws(() {
+ testUntypedListTests(list);
+ }, (e) => e is TypeError, 'List<int> cannot store non-ints');
// Argument errors on bad indices. List is still [0, 1, 2, 3].
testArgumentError(action()) {
@@ -311,21 +318,22 @@ void testLengthInvariantOperations(List list) {
testArgumentError(() => list.fillRange(4, 2));
}
-void testTypedList(List list) {
+void testTypedList(List<int> list) {
testTypedLengthInvariantOperations(list);
testCannotChangeLength(list);
}
-void testFixedLengthList(List list) {
- testLengthInvariantOperations(list);
- testCannotChangeLength(list);
+void testFixedLengthList(List<T> Function<T>() createList) {
+ testLengthInvariantOperations(createList());
+ testCannotChangeLength(createList());
+ testUntypedListTests(createList());
}
-void testCannotChangeLength(List list) {
+void testCannotChangeLength(List<int> list) {
isUnsupported(action()) {
Expect.throws(action, (e) => e is UnsupportedError);
}
-
+ list.setAll(0, [0, 1, 2, 3]);
isUnsupported(() => list.add(0));
isUnsupported(() => list.addAll([0]));
isUnsupported(() => list.removeLast());
@@ -338,7 +346,7 @@ void testCannotChangeLength(List list) {
isUnsupported(() => list.replaceRange(0, 1, []));
}
-void testTypedGrowableList(List list) {
+void testTypedGrowableList(List<int> list) {
testLength(0, list);
// set length.
list.length = 4;
@@ -349,18 +357,24 @@ void testTypedGrowableList(List list) {
testGrowableListOperations(list);
}
-void testGrowableList(List list) {
+void testGrowableList(List<T> Function<T>() createList) {
+ List<int> list = createList();
testLength(0, list);
- // set length.
list.length = 4;
testLength(4, list);
testLengthInvariantOperations(list);
-
testGrowableListOperations(list);
+
+ List listDynamic = createList();
+ testLength(0, listDynamic);
+ listDynamic.length = 4;
+ testLength(4, listDynamic);
+
+ testUntypedListTests(listDynamic);
}
-void testGrowableListOperations(List list) {
+void testGrowableListOperations(List<int> list) {
// add, removeLast.
list.clear();
testLength(0, list);
@@ -475,51 +489,6 @@ void testGrowableListOperations(List list) {
list.replaceRange(6, 8, []);
Expect.listEquals([1, 2, 6, 6, 5, 0, 2, 3, 2, 1], list);
- // Operations that change the length cause ConcurrentModificationError.
- void testConcurrentModification(action()) {
- testIterator(int when) {
- list.length = 4;
- list.setAll(0, [0, 1, 2, 3]);
- Expect.throws(() {
- for (var element in list) {
- if (element == when) action();
- }
- }, (e) => e is ConcurrentModificationError);
- }
-
- testForEach(int when) {
- list.length = 4;
- list.setAll(0, [0, 1, 2, 3]);
- Expect.throws(() {
- list.forEach((var element) {
- if (element == when) action();
- });
- }, (e) => e is ConcurrentModificationError);
- }
-
- // Test the change at different points of the iteration.
- testIterator(0);
- testIterator(1);
- testIterator(3);
- testForEach(0);
- testForEach(1);
- testForEach(3);
- }
-
- testConcurrentModification(() => list.add(5));
- testConcurrentModification(() => list.addAll([5, 6]));
- testConcurrentModification(() => list.removeLast());
- for (int i = 0; i < 4; i++) {
- testConcurrentModification(() => list.remove(i));
- testConcurrentModification(() => list.removeAt(i));
- testConcurrentModification(() => list.removeWhere((x) => x == i));
- testConcurrentModification(() => list.retainWhere((x) => x != i));
- testConcurrentModification(() => list.insert(i, 5));
- testConcurrentModification(() => list.insertAll(i, [5, 6]));
- testConcurrentModification(() => list.removeRange(i, i + 1));
- testConcurrentModification(() => list.replaceRange(i, i + 1, [5, 6]));
- }
-
// Any operation that doesn't change the length should be safe for iteration.
testSafeConcurrentModification(action()) {
list.length = 4;

Powered by Google App Engine
This is Rietveld 408576698