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

Unified Diff: tests/corelib/iterable_generate_test.dart

Issue 1992713002: Make Iterable.generate use ListIterable as base implementation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Reword skip docs Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/iterable_generate_test.dart
diff --git a/tests/corelib/iterable_generate_test.dart b/tests/corelib/iterable_generate_test.dart
index 851f14d4ea93e630c49e65d227eebef7f3f0b995..170dba91c62231fb1a853097c0bc509390f464a5 100644
--- a/tests/corelib/iterable_generate_test.dart
+++ b/tests/corelib/iterable_generate_test.dart
@@ -42,4 +42,32 @@ main() {
if (checkedMode) {
Expect.throws(() => new Iterable<String>.generate(5));
}
+
+ // Omitted generator function means `(int x) => x`, and the type parameters
+ // must then be compatible with `int`.
+ // Check that we catch invalid type parameters.
+
+ // Valid types:
+ Iterable<int> iter1 = new Iterable<int>.generate(5);
+ Expect.equals(2, iter1.elementAt(2));
+ Iterable<num> iter2 = new Iterable<num>.generate(5);
+ Expect.equals(2, iter2.elementAt(2));
+ Iterable<Object> iter3 = new Iterable<Object>.generate(5);
+ Expect.equals(2, iter3.elementAt(2));
+ Iterable<dynamic> iter4 = new Iterable<dynamic>.generate(5);
+ Expect.equals(2, iter4.elementAt(2));
+
+ // Invalid types:
+ Expect.throws(() => new Iterable<String>.generate(5));
+ Expect.throws(() => new Iterable<Null>.generate(5));
+ Expect.throws(() => new Iterable<bool>.generate(5));
+
+ // Regression: https://github.com/dart-lang/sdk/issues/26358
+ var count = 0;
+ var iter = new Iterable.generate(5, (v) { count++; return v; });
+ Expect.equals(0, count);
+ Expect.equals(2, iter.elementAt(2)); // Doesn't compute the earlier values.
+ Expect.equals(1, count);
+ Expect.equals(2, iter.skip(2).first); // Doesn't compute the skipped values.
+ Expect.equals(2, count);
}
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698