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

Side by Side Diff: tests/corelib/growable_list_test.dart

Issue 2467113003: Make EfficientLength extend Iterable. (Closed)
Patch Set: Reverted, prepare to reland. Make new test not break web-testing framework. Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/internal/iterable.dart ('k') | tests/language/efficient_length_warning_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Sanity check on the growing behavior of a growable list. 5 // Sanity check on the growing behavior of a growable list.
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 8
9 void main() { 9 void main() {
10 testConstructor(); 10 testConstructor();
(...skipping 16 matching lines...) Expand all
27 this.callbackIndex, this.callback); 27 this.callbackIndex, this.callback);
28 Iterator<int> get iterator => new CallbackIterator(this); 28 Iterator<int> get iterator => new CallbackIterator(this);
29 } 29 }
30 30
31 class TestIterable extends TestIterableBase { 31 class TestIterable extends TestIterableBase {
32 TestIterable(count, [callbackIndex = -1, callback]) 32 TestIterable(count, [callbackIndex = -1, callback])
33 : super(-1, count, callbackIndex, callback); 33 : super(-1, count, callbackIndex, callback);
34 int get length => throw "SHOULD NOT BE CALLED"; 34 int get length => throw "SHOULD NOT BE CALLED";
35 } 35 }
36 36
37 // Implement Set for private EfficientLength interface. 37 // Implement Set for private EfficientLengthIterable interface.
38 class EfficientTestIterable extends TestIterableBase 38 class EfficientTestIterable extends TestIterableBase
39 implements Set<int> { 39 implements Set<int> {
40 EfficientTestIterable(length, count, [callbackIndex = -1, callback]) 40 EfficientTestIterable(length, count, [callbackIndex = -1, callback])
41 : super(length, count, callbackIndex, callback); 41 : super(length, count, callbackIndex, callback);
42 // Avoid warnings because we don't actually implement Set. 42 // Avoid warnings because we don't actually implement Set.
43 noSuchMethod(i) => super.noSuchMethod(i); 43 noSuchMethod(i) => super.noSuchMethod(i);
44 } 44 }
45 45
46 class CallbackIterator implements Iterator<int> { 46 class CallbackIterator implements Iterator<int> {
47 TestIterableBase _iterable; 47 TestIterableBase _iterable;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 Expect.throws(() => new List<int>(0x1000000000000000000000000000000), 97 Expect.throws(() => new List<int>(0x1000000000000000000000000000000),
98 (e) => e is ArgumentError, "bignum"); 98 (e) => e is ArgumentError, "bignum");
99 Expect.throws(() => new List<int>(null), (e) => e is ArgumentError, "null"); 99 Expect.throws(() => new List<int>(null), (e) => e is ArgumentError, "null");
100 testThrowsOrTypeError(() => new List([] as Object), // Cast to avoid warning. 100 testThrowsOrTypeError(() => new List([] as Object), // Cast to avoid warning.
101 (e) => e is ArgumentError, 'list'); 101 (e) => e is ArgumentError, 'list');
102 testThrowsOrTypeError(() => new List([42] as Object), 102 testThrowsOrTypeError(() => new List([42] as Object),
103 (e) => e is ArgumentError, "list2"); 103 (e) => e is ArgumentError, "list2");
104 } 104 }
105 105
106 void testConcurrentModification() { 106 void testConcurrentModification() {
107 // Without EfficientLength interface 107 // Without EfficientLengthIterable interface
108 { 108 {
109 // Change length of list after 200 additions. 109 // Change length of list after 200 additions.
110 var l = []; 110 var l = [];
111 var ci = new TestIterable(257, 200, () { 111 var ci = new TestIterable(257, 200, () {
112 l.add("X"); 112 l.add("X");
113 }); 113 });
114 Expect.throws(() { 114 Expect.throws(() {
115 l.addAll(ci); 115 l.addAll(ci);
116 }, (e) => e is ConcurrentModificationError, "cm1"); 116 }, (e) => e is ConcurrentModificationError, "cm1");
117 } 117 }
118 118
119 { 119 {
120 // Change length of list after 200 additions. 120 // Change length of list after 200 additions.
121 var l = []; 121 var l = [];
122 var ci = new TestIterable(257, 200, () { 122 var ci = new TestIterable(257, 200, () {
123 l.length = 0; 123 l.length = 0;
124 }); 124 });
125 Expect.throws(() { 125 Expect.throws(() {
126 l.addAll(ci); 126 l.addAll(ci);
127 }, (e) => e is ConcurrentModificationError, "cm2"); 127 }, (e) => e is ConcurrentModificationError, "cm2");
128 } 128 }
129 129
130 // With EfficientLength interface (uses length). 130 // With EfficientLengthIterable interface (uses length).
131 { 131 {
132 // Change length of list after 20 additions. 132 // Change length of list after 20 additions.
133 var l = []; 133 var l = [];
134 var ci = new EfficientTestIterable(257, 257, 20, () { 134 var ci = new EfficientTestIterable(257, 257, 20, () {
135 l.add("X"); 135 l.add("X");
136 }); 136 });
137 Expect.throws(() { 137 Expect.throws(() {
138 l.addAll(ci); 138 l.addAll(ci);
139 }, (e) => e is ConcurrentModificationError, "cm3"); 139 }, (e) => e is ConcurrentModificationError, "cm3");
140 } 140 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 { 175 {
176 // Adding to yourself. 176 // Adding to yourself.
177 var l = [1, 2, 3]; 177 var l = [1, 2, 3];
178 Expect.throws(() { l.addAll(l); }, 178 Expect.throws(() { l.addAll(l); },
179 (e) => e is ConcurrentModificationError, "cm8"); 179 (e) => e is ConcurrentModificationError, "cm8");
180 } 180 }
181 } 181 }
182 182
OLDNEW
« no previous file with comments | « sdk/lib/internal/iterable.dart ('k') | tests/language/efficient_length_warning_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698