| 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 24 matching lines...) Expand all  Loading... | 
|  35   Iterable<String> st = new Iterable<String>.generate(5, (x) => "$x"); |  35   Iterable<String> st = new Iterable<String>.generate(5, (x) => "$x"); | 
|  36   Expect.isTrue(st is Iterable<String>); |  36   Expect.isTrue(st is Iterable<String>); | 
|  37   Expect.isTrue(st.iterator is Iterator<String>); |  37   Expect.isTrue(st.iterator is Iterator<String>); | 
|  38   Expect.isFalse(st is Iterable<int>); |  38   Expect.isFalse(st is Iterable<int>); | 
|  39   Expect.isFalse(st.iterator is Iterator<int>); |  39   Expect.isFalse(st.iterator is Iterator<int>); | 
|  40   test(["0","1","2","3","4"], st); |  40   test(["0","1","2","3","4"], st); | 
|  41  |  41  | 
|  42   if (checkedMode) { |  42   if (checkedMode) { | 
|  43     Expect.throws(() => new Iterable<String>.generate(5)); |  43     Expect.throws(() => new Iterable<String>.generate(5)); | 
|  44   } |  44   } | 
 |  45  | 
 |  46   // Omitted generator function means `(int x) => x`, and the type parameters | 
 |  47   // must then be compatible with `int`. | 
 |  48   // Check that we catch invalid type parameters. | 
 |  49  | 
 |  50   // Valid types: | 
 |  51   Iterable<int> iter1 = new Iterable<int>.generate(5); | 
 |  52   Expect.equals(2, iter1.elementAt(2)); | 
 |  53   Iterable<num> iter2 = new Iterable<num>.generate(5); | 
 |  54   Expect.equals(2, iter2.elementAt(2)); | 
 |  55   Iterable<Object> iter3 = new Iterable<Object>.generate(5); | 
 |  56   Expect.equals(2, iter3.elementAt(2)); | 
 |  57   Iterable<dynamic> iter4 = new Iterable<dynamic>.generate(5); | 
 |  58   Expect.equals(2, iter4.elementAt(2)); | 
 |  59  | 
 |  60   // Invalid types: | 
 |  61   Expect.throws(() => new Iterable<String>.generate(5)); | 
 |  62   Expect.throws(() => new Iterable<Null>.generate(5)); | 
 |  63   Expect.throws(() => new Iterable<bool>.generate(5)); | 
 |  64  | 
 |  65   // Regression: https://github.com/dart-lang/sdk/issues/26358 | 
 |  66   var count = 0; | 
 |  67   var iter = new Iterable.generate(5, (v) { count++; return v; }); | 
 |  68   Expect.equals(0, count); | 
 |  69   Expect.equals(2, iter.elementAt(2));  // Doesn't compute the earlier values. | 
 |  70   Expect.equals(1, count); | 
 |  71   Expect.equals(2, iter.skip(2).first);  // Doesn't compute the skipped values. | 
 |  72   Expect.equals(2, count); | 
|  45 } |  73 } | 
| OLD | NEW |