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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « tests/corelib/iterable_take_test.dart ('k') | tests/corelib/iterable_to_list_test.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) 2012, 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 List<int> list1 = <int>[1, 2, 3];
7 List<int> list2 = const <int>[4, 5];
8 List<String> list3 = <String>[];
9 Set<int> set1 = new Set<int>();
10 set1..add(11)
11 ..add(12)
12 ..add(13);
13 Set set2 = new Set();
14
15 Iterable<int> takeWhileFalse = list1.takeWhile((x) => false);
16 Iterator<int> it = takeWhileFalse.iterator;
17 Expect.isNull(it.current);
18 Expect.isFalse(it.moveNext());
19 Expect.isNull(it.current);
20
21 Iterable<int> takeWhileOdd = list1.takeWhile((x) => x.isOdd);
22 it = takeWhileOdd.iterator;
23 Expect.isNull(it.current);
24 Expect.isTrue(it.moveNext());
25 Expect.equals(1, it.current);
26 Expect.isFalse(it.moveNext());
27 Expect.isNull(it.current);
28
29 Iterable<int> takeWhileLessThan3 = list1.takeWhile((x) => x < 3);
30 it = takeWhileLessThan3.iterator;
31 Expect.isNull(it.current);
32 Expect.isTrue(it.moveNext());
33 Expect.equals(1, it.current);
34 Expect.isTrue(it.moveNext());
35 Expect.equals(2, it.current);
36 Expect.isFalse(it.moveNext());
37 Expect.isNull(it.current);
38
39 Iterable<int> takeEverything = list1.takeWhile((x) => true);
40 it = takeEverything.iterator;
41 Expect.isNull(it.current);
42 Expect.isTrue(it.moveNext());
43 Expect.equals(1, it.current);
44 Expect.isTrue(it.moveNext());
45 Expect.equals(2, it.current);
46 Expect.isTrue(it.moveNext());
47 Expect.equals(3, it.current);
48 Expect.isFalse(it.moveNext());
49 Expect.isNull(it.current);
50
51 Iterable<int> takeWhileEven = list1.takeWhile((x) => x.isEven);
52 it = takeWhileFalse.iterator;
53 Expect.isNull(it.current);
54 Expect.isFalse(it.moveNext());
55 Expect.isNull(it.current);
56
57 takeWhileFalse = list2.takeWhile((x) => false);
58 it = takeWhileFalse.iterator;
59 Expect.isNull(it.current);
60 Expect.isFalse(it.moveNext());
61 Expect.isNull(it.current);
62
63 takeWhileEven = list2.takeWhile((x) => x.isEven);
64 it = takeWhileEven.iterator;
65 Expect.isNull(it.current);
66 Expect.isTrue(it.moveNext());
67 Expect.equals(4, it.current);
68 Expect.isFalse(it.moveNext());
69 Expect.isNull(it.current);
70
71 takeEverything = list2.takeWhile((x) => true);
72 it = takeEverything.iterator;
73 Expect.isNull(it.current);
74 Expect.isTrue(it.moveNext());
75 Expect.equals(4, it.current);
76 Expect.isTrue(it.moveNext());
77 Expect.equals(5, it.current);
78 Expect.isFalse(it.moveNext());
79 Expect.isNull(it.current);
80
81 Iterable<String> takeWhileFalse2 = list3.takeWhile((x) => false);
82 Iterator<String> it2 = takeWhileFalse2.iterator;
83 Expect.isNull(it2.current);
84 Expect.isFalse(it2.moveNext());
85 Expect.isNull(it2.current);
86
87 Iterable<String> takeEverything2 = list3.takeWhile((x) => true);
88 it2 = takeEverything2.iterator;
89 Expect.isNull(it2.current);
90 Expect.isFalse(it2.moveNext());
91 Expect.isNull(it2.current);
92
93 takeWhileFalse = set1.takeWhile((x) => false);
94 it = takeWhileFalse.iterator;
95 Expect.isNull(it.current);
96 Expect.isFalse(it.moveNext());
97 Expect.isNull(it.current);
98
99 takeEverything = set1.takeWhile((x) => true);
100 List<int> copied = takeEverything.toList();
101 Expect.equals(3, copied.length);
102 Expect.isTrue(set1.contains(copied[0]));
103 Expect.isTrue(set1.contains(copied[1]));
104 Expect.isTrue(set1.contains(copied[1]));
105 Expect.isTrue(copied[0] != copied[1]);
106 Expect.isTrue(copied[0] != copied[2]);
107 Expect.isTrue(copied[1] != copied[2]);
108 it = takeEverything.iterator;
109 Expect.isNull(it.current);
110 Expect.isTrue(it.moveNext());
111 Expect.isTrue(it.current != null);
112 Expect.isTrue(it.moveNext());
113 Expect.isTrue(it.current != null);
114 Expect.isTrue(it.moveNext());
115 Expect.isTrue(it.current != null);
116 Expect.isFalse(it.moveNext());
117 Expect.isNull(it.current);
118
119 takeWhileFalse = set2.takeWhile((x) => false);
120 it = takeWhileFalse.iterator;
121 Expect.isNull(it.current);
122 Expect.isFalse(it.moveNext());
123 Expect.isNull(it.current);
124
125 takeEverything = set2.takeWhile((x) => true);
126 it = takeEverything.iterator;
127 Expect.isNull(it.current);
128 Expect.isFalse(it.moveNext());
129 Expect.isNull(it.current);
130 }
OLDNEW
« no previous file with comments | « tests/corelib/iterable_take_test.dart ('k') | tests/corelib/iterable_to_list_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698