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

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

Issue 50733002: Update List constructor documentation. Say that null is not a length. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests. Created 7 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 | Annotate | Revision Log
« sdk/lib/core/list.dart ('K') | « sdk/lib/core/list.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 26 matching lines...) Expand all
37 testGrowableList((const []).toList()); 37 testGrowableList((const []).toList());
38 testGrowableList(new MyList([])); 38 testGrowableList(new MyList([]));
39 testGrowableList(new MyList([]).toList()); 39 testGrowableList(new MyList([]).toList());
40 40
41 testTypedGrowableList(new Uint8List(0).toList()); 41 testTypedGrowableList(new Uint8List(0).toList());
42 testTypedGrowableList(new Int8List(0).toList()); 42 testTypedGrowableList(new Int8List(0).toList());
43 testTypedGrowableList(new Uint16List(0).toList()); 43 testTypedGrowableList(new Uint16List(0).toList());
44 testTypedGrowableList(new Int16List(0).toList()); 44 testTypedGrowableList(new Int16List(0).toList());
45 testTypedGrowableList(new Uint32List(0).toList()); 45 testTypedGrowableList(new Uint32List(0).toList());
46 testTypedGrowableList(new Int32List(0).toList()); 46 testTypedGrowableList(new Int32List(0).toList());
47
48 testListConstructor();
47 } 49 }
48 50
49 void testLength(int length, List list) { 51 void testLength(int length, List list) {
50 Expect.equals(length, list.length); 52 Expect.equals(length, list.length);
51 (length == 0 ? Expect.isTrue : Expect.isFalse)(list.isEmpty); 53 (length == 0 ? Expect.isTrue : Expect.isFalse)(list.isEmpty);
52 (length != 0 ? Expect.isTrue : Expect.isFalse)(list.isNotEmpty); 54 (length != 0 ? Expect.isTrue : Expect.isFalse)(list.isNotEmpty);
53 } 55 }
54 56
55 void testTypedLengthInvariantOperations(List list) { 57 void testTypedLengthInvariantOperations(List list) {
56 // length 58 // length
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 487 }
486 488
487 class MyFixedList<E> extends ListBase<E> { 489 class MyFixedList<E> extends ListBase<E> {
488 List<E> _source; 490 List<E> _source;
489 MyFixedList(this._source); 491 MyFixedList(this._source);
490 int get length => _source.length; 492 int get length => _source.length;
491 void set length(int length) { throw new UnsupportedError("Fixed length!"); } 493 void set length(int length) { throw new UnsupportedError("Fixed length!"); }
492 E operator[](int index) => _source[index]; 494 E operator[](int index) => _source[index];
493 void operator[]=(int index, E value) { _source[index] = value; } 495 void operator[]=(int index, E value) { _source[index] = value; }
494 } 496 }
497
498 void testListConstructor() {
499 Expect.throws(() { new List(0).add(4); }); // Is fixed-length.
500 Expect.throws(() { new List(-2); }); // Not negative.
501 Expect.throws(() { new List(null); }); // Not null.
502 Expect.listEquals([4], new List()..add(4));
503 Expect.throws(() { new List.filled(0, 42).add(4); }); // Is fixed-length.
504 Expect.throws(() { new List.filled(-2, 42); }); // Not negative.
505 Expect.throws(() { new List.filled(null, 42); }); // Not null.
506 }
OLDNEW
« sdk/lib/core/list.dart ('K') | « sdk/lib/core/list.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698