OLD | NEW |
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 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 main() { | 8 main() { |
9 bool checkedMode = false; | 9 bool checkedMode = false; |
10 assert((checkedMode = true)); | 10 assert((checkedMode = true)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 Expect.equals(2, iter1.elementAt(2)); | 52 Expect.equals(2, iter1.elementAt(2)); |
53 Iterable<num> iter2 = new Iterable<num>.generate(5); | 53 Iterable<num> iter2 = new Iterable<num>.generate(5); |
54 Expect.equals(2, iter2.elementAt(2)); | 54 Expect.equals(2, iter2.elementAt(2)); |
55 Iterable<Object> iter3 = new Iterable<Object>.generate(5); | 55 Iterable<Object> iter3 = new Iterable<Object>.generate(5); |
56 Expect.equals(2, iter3.elementAt(2)); | 56 Expect.equals(2, iter3.elementAt(2)); |
57 Iterable<dynamic> iter4 = new Iterable<dynamic>.generate(5); | 57 Iterable<dynamic> iter4 = new Iterable<dynamic>.generate(5); |
58 Expect.equals(2, iter4.elementAt(2)); | 58 Expect.equals(2, iter4.elementAt(2)); |
59 | 59 |
60 // Invalid types: | 60 // Invalid types: |
61 Expect.throws(() => new Iterable<String>.generate(5)); | 61 Expect.throws(() => new Iterable<String>.generate(5)); |
62 if (checkedMode) { // /// 01:
ok | 62 if (checkedMode) { // //# 01:
ok |
63 Expect.throws(() => new Iterable<Null>.generate(5).elementAt(2)); /// 01: co
ntinued | 63 Expect.throws(() => new Iterable<Null>.generate(5).elementAt(2)); //# 01: co
ntinued |
64 } else { // /// 01:
continued | 64 } else { // //# 01:
continued |
65 Iterable<dynamic> iter5 = new Iterable<Null>.generate(5); // /// 01:
continued | 65 Iterable<dynamic> iter5 = new Iterable<Null>.generate(5); // //# 01:
continued |
66 Expect.equals(2, iter5.elementAt(2)); // /// 01:
continued | 66 Expect.equals(2, iter5.elementAt(2)); // //# 01:
continued |
67 } // /// 01:
continued | 67 } // //# 01:
continued |
68 Expect.throws(() => new Iterable<bool>.generate(5)); | 68 Expect.throws(() => new Iterable<bool>.generate(5)); |
69 | 69 |
70 // Regression: https://github.com/dart-lang/sdk/issues/26358 | 70 // Regression: https://github.com/dart-lang/sdk/issues/26358 |
71 var count = 0; | 71 var count = 0; |
72 var iter = new Iterable.generate(5, (v) { count++; return v; }); | 72 var iter = new Iterable.generate(5, (v) { count++; return v; }); |
73 Expect.equals(0, count); | 73 Expect.equals(0, count); |
74 Expect.equals(2, iter.elementAt(2)); // Doesn't compute the earlier values. | 74 Expect.equals(2, iter.elementAt(2)); // Doesn't compute the earlier values. |
75 Expect.equals(1, count); | 75 Expect.equals(1, count); |
76 Expect.equals(2, iter.skip(2).first); // Doesn't compute the skipped values. | 76 Expect.equals(2, iter.skip(2).first); // Doesn't compute the skipped values. |
77 Expect.equals(2, count); | 77 Expect.equals(2, count); |
78 } | 78 } |
OLD | NEW |