@@ -9,7 +9,7 @@ import 'package:expect/expect.dart';
9
9
@NoInline ()
10
10
confuse (x) => x;
11
11
12
- void testListFunctions (list, first, last, toElementType) {
12
+ void testListFunctions/*<T>*/ (list, first, last, /*=T*/ toElementType ( dynamic x) ) {
13
13
assert (list.length > 0 );
14
14
15
15
var reversed = list.reversed;
@@ -20,16 +20,21 @@ void testListFunctions(list, first, last, toElementType) {
20
20
index-- ;
21
21
}
22
22
23
+ var zero = toElementType (0 );
24
+ var one = toElementType (1 );
25
+ var two = toElementType (2 );
23
26
// Typed lists are fixed length.
24
- Expect .throws (() => list.add (0 ), (e) => e is UnsupportedError );
25
- Expect .throws (() => list.addAll ([1 , 2 ]), (e) => e is UnsupportedError );
27
+ Expect .throws (() => list.add (zero ), (e) => e is UnsupportedError );
28
+ Expect .throws (() => list.addAll ([one, two ]), (e) => e is UnsupportedError );
26
29
Expect .throws (() => list.clear (), (e) => e is UnsupportedError );
27
- Expect .throws (() => list.insert (0 , 0 ), (e) => e is UnsupportedError );
28
- Expect .throws (() => list.insertAll (0 , [1 , 2 ]), (e) => e is UnsupportedError );
29
- Expect .throws (() => list.remove (0 ), (e) => e is UnsupportedError );
30
+ Expect .throws (() => list.insert (0 , zero), (e) => e is UnsupportedError );
31
+ Expect .throws (() => list.insertAll (0 , [one, two]),
32
+ (e) => e is UnsupportedError );
33
+ Expect .throws (() => list.remove (zero), (e) => e is UnsupportedError );
30
34
Expect .throws (() => list.removeAt (0 ), (e) => e is UnsupportedError );
31
35
Expect .throws (() => list.removeLast (), (e) => e is UnsupportedError );
32
- Expect .throws (() => list.removeRange (0 , 1 ), (e) => e is UnsupportedError );
36
+ Expect .throws (() => list.removeRange (0 , 1 ),
37
+ (e) => e is UnsupportedError );
33
38
Expect .throws (() => list.removeWhere ((x) => true ),
34
39
(e) => e is UnsupportedError );
35
40
Expect .throws (() => list.replaceRange (0 , 1 , []),
@@ -123,21 +128,24 @@ void testListFunctions(list, first, last, toElementType) {
123
128
(e) => e is RangeError );
124
129
}
125
130
126
- void emptyChecks (list) {
131
+ void emptyChecks/*<T>*/ (list, /*=T*/ toElementType ( dynamic c) ) {
127
132
assert (list.length == 0 );
128
133
129
134
Expect .isTrue (list.isEmpty);
130
135
131
136
var reversed = list.reversed;
132
137
Expect .listEquals (list, reversed.toList ().reversed.toList ());
133
138
139
+ var zero = toElementType (0 );
140
+ var one = toElementType (1 );
141
+ var two = toElementType (2 );
134
142
// Typed lists are fixed length. Even when they are empty.
135
- Expect .throws (() => list.add (0 ), (e) => e is UnsupportedError );
136
- Expect .throws (() => list.addAll ([1 , 2 ]), (e) => e is UnsupportedError );
143
+ Expect .throws (() => list.add (zero ), (e) => e is UnsupportedError );
144
+ Expect .throws (() => list.addAll ([one, two ]), (e) => e is UnsupportedError );
137
145
Expect .throws (() => list.clear (), (e) => e is UnsupportedError );
138
- Expect .throws (() => list.insert (0 , 0 ), (e) => e is UnsupportedError );
139
- Expect .throws (() => list.insertAll (0 , [1 , 2 ]), (e) => e is UnsupportedError );
140
- Expect .throws (() => list.remove (0 ), (e) => e is UnsupportedError );
146
+ Expect .throws (() => list.insert (0 , zero ), (e) => e is UnsupportedError );
147
+ Expect .throws (() => list.insertAll (0 , [one, two ]), (e) => e is UnsupportedError );
148
+ Expect .throws (() => list.remove (zero ), (e) => e is UnsupportedError );
141
149
Expect .throws (() => list.removeAt (0 ), (e) => e is UnsupportedError );
142
150
Expect .throws (() => list.removeLast (), (e) => e is UnsupportedError );
143
151
Expect .throws (() => list.removeRange (0 , 1 ), (e) => e is UnsupportedError );
@@ -174,8 +182,8 @@ void emptyChecks(list) {
174
182
}
175
183
176
184
main () {
177
- toDouble (x) => x.toDouble ();
178
- toInt (x) => x.toInt ();
185
+ double toDouble (x) => x.toDouble ();
186
+ int toInt (x) => x.toInt ();
179
187
180
188
testListFunctions (new Float32List .fromList ([1.5 , 6.3 , 9.5 ]),
181
189
1.5 , 9.5 , toDouble);
@@ -188,12 +196,12 @@ main() {
188
196
testListFunctions (new Uint16List .fromList ([3 , 5 , 9 ]), 3 , 9 , toInt);
189
197
testListFunctions (new Uint32List .fromList ([3 , 5 , 9 ]), 3 , 9 , toInt);
190
198
191
- emptyChecks (new Float32List (0 ));
192
- emptyChecks (new Float64List (0 ));
193
- emptyChecks (new Int8List (0 ));
194
- emptyChecks (new Int16List (0 ));
195
- emptyChecks (new Int32List (0 ));
196
- emptyChecks (new Uint8List (0 ));
197
- emptyChecks (new Uint16List (0 ));
198
- emptyChecks (new Uint32List (0 ));
199
+ emptyChecks (new Float32List (0 ), toDouble );
200
+ emptyChecks (new Float64List (0 ), toDouble );
201
+ emptyChecks (new Int8List (0 ), toInt );
202
+ emptyChecks (new Int16List (0 ), toInt );
203
+ emptyChecks (new Int32List (0 ), toInt );
204
+ emptyChecks (new Uint8List (0 ), toInt );
205
+ emptyChecks (new Uint16List (0 ), toInt );
206
+ emptyChecks (new Uint32List (0 ), toInt );
199
207
}
0 commit comments