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

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

Issue 1024843002: Change ListIterator to only check for concurrent modification at each iteration (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changelog. Created 5 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/corelib/json_map_test.dart ('k') | no next file » | 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 import "dart:collection"; 5 import "dart:collection";
6 import "dart:typed_data"; 6 import "dart:typed_data";
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 8
9 void main() { 9 void main() {
10 // Typed lists - fixed length and can only contain integers. 10 // Typed lists - fixed length and can only contain integers.
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 list.replaceRange(2, 3, [5, 5, 5]); 370 list.replaceRange(2, 3, [5, 5, 5]);
371 Expect.listEquals([1, 2, 5, 5, 5, 0, 0, 7, 2, 3, 2, 1], list); 371 Expect.listEquals([1, 2, 5, 5, 5, 0, 0, 7, 2, 3, 2, 1], list);
372 372
373 list.replaceRange(2, 4, [6, 6]); 373 list.replaceRange(2, 4, [6, 6]);
374 Expect.listEquals([1, 2, 6, 6, 5, 0, 0, 7, 2, 3, 2, 1], list); 374 Expect.listEquals([1, 2, 6, 6, 5, 0, 0, 7, 2, 3, 2, 1], list);
375 375
376 list.replaceRange(6, 8, []); 376 list.replaceRange(6, 8, []);
377 Expect.listEquals([1, 2, 6, 6, 5, 0, 2, 3, 2, 1], list); 377 Expect.listEquals([1, 2, 6, 6, 5, 0, 2, 3, 2, 1], list);
378 378
379 // Operations that change the length cause ConcurrentModificationError. 379 // Operations that change the length may cause ConcurrentModificationError.
380 // Reducing the length may cause a RangeError before the
381 // ConcurrentModificationError in production mode.
382 bool checkedMode = false;
383 assert((checkedMode = true));
384
380 void testConcurrentModification(action()) { 385 void testConcurrentModification(action()) {
381 testIterator(int when) { 386 testIterator(int when) {
382 list.length = 4; 387 list.length = 4;
383 list.setAll(0, [0, 1, 2, 3]); 388 list.setAll(0, [0, 1, 2, 3]);
384 Expect.throws(() { 389 Expect.throws(() {
385 for (var element in list) { 390 for (var element in list) {
386 if (element == when) action(); 391 if (element == when) {
392 when = -1; // Prevent triggering more than once.
393 action();
394 }
387 } 395 }
388 }, (e) => e is ConcurrentModificationError); 396 }, (e) => !checkedMode || e is ConcurrentModificationError);
389 } 397 }
390 testForEach(int when) { 398 testForEach(int when) {
391 list.length = 4; 399 list.length = 4;
392 list.setAll(0, [0, 1, 2, 3]); 400 list.setAll(0, [0, 1, 2, 3]);
393 Expect.throws(() { 401 Expect.throws(() {
394 list.forEach((var element) { 402 list.forEach((var element) {
395 if (element == when) action(); 403 if (element == when) {
404 when = -1;
405 action();
406 }
396 }); 407 });
397 }, (e) => e is ConcurrentModificationError); 408 }, (e) => e is ConcurrentModificationError);
398 } 409 }
399 // Test the change at different points of the iteration. 410 // Test the change at different points of the iteration.
400 testIterator(0); 411 testIterator(0);
401 testIterator(1); 412 testIterator(1);
402 testIterator(3); 413 testIterator(3);
403 testForEach(0); 414 testForEach(0);
404 testForEach(1); 415 testForEach(1);
405 testForEach(3); 416 testForEach(3);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 508
498 void testListConstructor() { 509 void testListConstructor() {
499 Expect.throws(() { new List(0).add(4); }); // Is fixed-length. 510 Expect.throws(() { new List(0).add(4); }); // Is fixed-length.
500 Expect.throws(() { new List(-2); }); // Not negative. /// 01: ok 511 Expect.throws(() { new List(-2); }); // Not negative. /// 01: ok
501 Expect.throws(() { new List(null); }); // Not null. 512 Expect.throws(() { new List(null); }); // Not null.
502 Expect.listEquals([4], new List()..add(4)); 513 Expect.listEquals([4], new List()..add(4));
503 Expect.throws(() { new List.filled(0, 42).add(4); }); // Is fixed-length. 514 Expect.throws(() { new List.filled(0, 42).add(4); }); // Is fixed-length.
504 Expect.throws(() { new List.filled(-2, 42); }); // Not negative. 515 Expect.throws(() { new List.filled(-2, 42); }); // Not negative.
505 Expect.throws(() { new List.filled(null, 42); }); // Not null. 516 Expect.throws(() { new List.filled(null, 42); }); // Not null.
506 } 517 }
OLDNEW
« no previous file with comments | « tests/corelib/json_map_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698