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

Side by Side Diff: tests/corelib/iterable_expand_test.dart

Issue 12188011: Added expand method to iterables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/svg/dartium/svg_dartium.dart ('k') | tools/dom/src/CssClassSet.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 main() {
6 test(expectation, iterable) {
7 Expect.listEquals(expectation, iterable.toList());
8 }
9
10 // Function not called on empty iterable.
11 test([], [].expand((x) { throw "not called"; }));
12
13 // Creating the iterable doesn't call the function.
14 [1].expand((x) { throw "not called"; });
15
16 test([1], [1].expand((x) => [x]));
17 test([1, 2, 3], [1, 2, 3].expand((x) => [x]));
18
19 test([], [1].expand((x) => []));
20 test([], [1, 2, 3].expand((x) => []));
21 test([2], [1, 2, 3].expand((x) => x == 2 ? [2] : []));
22
23 test([1, 1, 2, 2, 3, 3], [1, 2, 3].expand((x) => [x, x]));
24 test([1, 1, 2], [1, 2, 3].expand((x) => [x, x, x].skip(x)));
25
26 // if function throws, iteration is stopped.
27 Iterable iterable = [1, 2, 3].expand((x) {
28 if (x == 2) throw "FAIL";
29 return [x, x];
30 });
31 Iterator it = iterable.iterator;
32 Expect.isTrue(it.moveNext());
33 Expect.equals(1, it.current);
34 Expect.isTrue(it.moveNext());
35 Expect.equals(1, it.current);
36 Expect.throws(it.moveNext, (e) => e == "FAIL");
37 // After throwing, iteration is ended.
38 Expect.equals(null, it.current);
39 Expect.isFalse(it.moveNext());
40 }
OLDNEW
« no previous file with comments | « sdk/lib/svg/dartium/svg_dartium.dart ('k') | tools/dom/src/CssClassSet.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698