OLD | NEW |
---|---|
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. |
11 testTypedList(new Uint8List(4)); | 11 testTypedList(new Uint8List(4)); |
12 testTypedList(new Int8List(4)); | 12 testTypedList(new Int8List(4)); |
13 testTypedList(new Uint16List(4)); | 13 testTypedList(new Uint16List(4)); |
14 testTypedList(new Int16List(4)); | 14 testTypedList(new Int16List(4)); |
15 testTypedList(new Uint32List(4)); | 15 testTypedList(new Uint32List(4)); |
16 testTypedList(new Int32List(4)); | 16 testTypedList(new Int32List(4)); |
17 // toList returns a List<int>. | |
floitsch
2013/05/22 16:26:29
unrelated change?
Lasse Reichstein Nielsen
2013/05/24 06:02:49
Completely.
| |
18 testTypedList(new Uint8List(4).toList(growable: false)); | |
19 testTypedList(new Int8List(4).toList(growable: false)); | |
20 testTypedList(new Uint16List(4).toList(growable: false)); | |
21 testTypedList(new Int16List(4).toList(growable: false)); | |
22 testTypedList(new Uint32List(4).toList(growable: false)); | |
23 testTypedList(new Int32List(4).toList(growable: false)); | |
17 | 24 |
18 // Fixed length lists, length 4. | 25 // Fixed length lists, length 4. |
19 testFixedLengthList(new List(4)); | 26 testFixedLengthList(new List(4)); |
20 testFixedLengthList(new List(4).toList(growable: false)); | 27 testFixedLengthList(new List(4).toList(growable: false)); |
21 testFixedLengthList((new List()..length = 4).toList(growable: false)); | 28 testFixedLengthList((new List()..length = 4).toList(growable: false)); |
22 // ListBase implementation of List. | 29 // ListBase implementation of List. |
23 testFixedLengthList(new MyFixedList(new List(4))); | 30 testFixedLengthList(new MyFixedList(new List(4))); |
24 testFixedLengthList(new MyFixedList(new List(4)).toList(growable: false)); | 31 testFixedLengthList(new MyFixedList(new List(4)).toList(growable: false)); |
25 | 32 |
26 testFixedLengthList(new Uint8List(4).toList(growable: false)); | |
27 testFixedLengthList(new Int8List(4).toList(growable: false)); | |
28 testFixedLengthList(new Uint16List(4).toList(growable: false)); | |
29 testFixedLengthList(new Int16List(4).toList(growable: false)); | |
30 testFixedLengthList(new Uint32List(4).toList(growable: false)); | |
31 testFixedLengthList(new Int32List(4).toList(growable: false)); | |
32 | 33 |
33 // Growable lists. Initial length 0. | 34 // Growable lists. Initial length 0. |
34 testGrowableList(new List()); | 35 testGrowableList(new List()); |
35 testGrowableList(new List().toList()); | 36 testGrowableList(new List().toList()); |
36 testGrowableList(new List(0).toList()); | 37 testGrowableList(new List(0).toList()); |
37 testGrowableList([]); | 38 testGrowableList([]); |
38 testGrowableList((const []).toList()); | 39 testGrowableList((const []).toList()); |
39 testGrowableList(new MyList([])); | 40 testGrowableList(new MyList([])); |
40 testGrowableList(new MyList([]).toList()); | 41 testGrowableList(new MyList([]).toList()); |
41 testGrowableList(new Uint8List(0).toList()); | 42 testGrowableList(new Uint8List(0).toList()); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 } | 470 } |
470 | 471 |
471 class MyFixedList<E> extends ListBase<E> { | 472 class MyFixedList<E> extends ListBase<E> { |
472 List<E> _source; | 473 List<E> _source; |
473 MyFixedList(this._source); | 474 MyFixedList(this._source); |
474 int get length => _source.length; | 475 int get length => _source.length; |
475 void set length(int length) { throw new UnsupportedError("Fixed length!"); } | 476 void set length(int length) { throw new UnsupportedError("Fixed length!"); } |
476 E operator[](int index) => _source[index]; | 477 E operator[](int index) => _source[index]; |
477 void operator[]=(int index, E value) { _source[index] = value; } | 478 void operator[]=(int index, E value) { _source[index] = value; } |
478 } | 479 } |
OLD | NEW |