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

Side by Side Diff: tests/corelib_2/iterable_generate_test.dart

Issue 3000543002: Migrate test block 11 to Dart 2.0. (Closed)
Patch Set: Removed checkedMode check. Created 3 years, 4 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 main() { 7 main() {
8 void test(expectedList, generatedIterable) { 8 void test(expectedList, generatedIterable) {
9 Expect.equals(expectedList.length, generatedIterable.length); 9 Expect.equals(expectedList.length, generatedIterable.length);
10 Expect.listEquals(expectedList, generatedIterable.toList()); 10 Expect.listEquals(expectedList, generatedIterable.toList());
(...skipping 19 matching lines...) Expand all
30 Expect.isTrue(it.iterator is! Iterator<String>); 30 Expect.isTrue(it.iterator is! Iterator<String>);
31 test([0, 1, 2, 3, 4], it); 31 test([0, 1, 2, 3, 4], it);
32 32
33 Iterable<String> st = new Iterable<String>.generate(5, (x) => "$x"); 33 Iterable<String> st = new Iterable<String>.generate(5, (x) => "$x");
34 Expect.isTrue(st is Iterable<String>); 34 Expect.isTrue(st is Iterable<String>);
35 Expect.isTrue(st.iterator is Iterator<String>); 35 Expect.isTrue(st.iterator is Iterator<String>);
36 Expect.isFalse(st is Iterable<int>); 36 Expect.isFalse(st is Iterable<int>);
37 Expect.isFalse(st.iterator is Iterator<int>); 37 Expect.isFalse(st.iterator is Iterator<int>);
38 test(["0", "1", "2", "3", "4"], st); 38 test(["0", "1", "2", "3", "4"], st);
39 39
40 if (typeAssertionsEnabled) { 40 Expect.throws(() => new Iterable<String>.generate(5));
41 Expect.throws(() => new Iterable<String>.generate(5));
42 }
43 41
44 // Omitted generator function means `(int x) => x`, and the type parameters 42 // Omitted generator function means `(int x) => x`, and the type parameters
45 // must then be compatible with `int`. 43 // must then be compatible with `int`.
46 // Check that we catch invalid type parameters. 44 // Check that we catch invalid type parameters.
47 45
48 // Valid types: 46 // Valid types:
49 Iterable<int> iter1 = new Iterable<int>.generate(5); 47 Iterable<int> iter1 = new Iterable<int>.generate(5);
50 Expect.equals(2, iter1.elementAt(2)); 48 Expect.equals(2, iter1.elementAt(2));
51 Iterable<num> iter2 = new Iterable<num>.generate(5); 49 Iterable<num> iter2 = new Iterable<num>.generate(5);
52 Expect.equals(2, iter2.elementAt(2)); 50 Expect.equals(2, iter2.elementAt(2));
53 Iterable<Object> iter3 = new Iterable<Object>.generate(5); 51 Iterable<Object> iter3 = new Iterable<Object>.generate(5);
54 Expect.equals(2, iter3.elementAt(2)); 52 Expect.equals(2, iter3.elementAt(2));
55 Iterable<dynamic> iter4 = new Iterable<dynamic>.generate(5); 53 Iterable<dynamic> iter4 = new Iterable<dynamic>.generate(5);
56 Expect.equals(2, iter4.elementAt(2)); 54 Expect.equals(2, iter4.elementAt(2));
57 55
58 // Invalid types: 56 // Invalid types:
59 Expect.throws(() => new Iterable<String>.generate(5)); 57 Expect.throws(() => new Iterable<String>.generate(5));
60 if (typeAssertionsEnabled) { // //# 01: ok 58 Expect.throws(() => new Iterable<Null>.generate(5).elementAt(2)); //# 01: ok
61 Expect.throws(() => new Iterable<Null>.generate(5).elementAt(2)); //# 01: continued
62 } else { // //# 01: continued
63 Iterable<dynamic> iter5 = new Iterable<Null>.generate(5); // //# 01: continued
64 Expect.equals(2, iter5.elementAt(2)); // //# 01: continued
65 } // //# 01: continued
66 Expect.throws(() => new Iterable<bool>.generate(5)); 59 Expect.throws(() => new Iterable<bool>.generate(5));
67 60
68 // Regression: https://github.com/dart-lang/sdk/issues/26358 61 // Regression: https://github.com/dart-lang/sdk/issues/26358
69 var count = 0; 62 var count = 0;
70 var iter = new Iterable.generate(5, (v) { 63 var iter = new Iterable.generate(5, (v) {
71 count++; 64 count++;
72 return v; 65 return v;
73 }); 66 });
74 Expect.equals(0, count); 67 Expect.equals(0, count);
75 Expect.equals(2, iter.elementAt(2)); // Doesn't compute the earlier values. 68 Expect.equals(2, iter.elementAt(2)); // Doesn't compute the earlier values.
76 Expect.equals(1, count); 69 Expect.equals(1, count);
77 Expect.equals(2, iter.skip(2).first); // Doesn't compute the skipped values. 70 Expect.equals(2, iter.skip(2).first); // Doesn't compute the skipped values.
78 Expect.equals(2, count); 71 Expect.equals(2, count);
79 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698