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

Side by Side Diff: tests/lib/async/stream_controller_async_test.dart

Issue 14312010: Add Stream.forEach (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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/async/stream.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Test the basic StreamController and StreamController.singleSubscription. 5 // Test the basic StreamController and StreamController.singleSubscription.
6 library stream_controller_async_test; 6 library stream_controller_async_test;
7 7
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import 'dart:async'; 9 import 'dart:async';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 sink.add(3); // -"- 118 sink.add(3); // -"-
119 sink.add(4); // -"- 119 sink.add(4); // -"-
120 sink.add(5); // seen by stream 10 120 sink.add(5); // seen by stream 10
121 sink.close(); 121 sink.close();
122 }); 122 });
123 } 123 }
124 124
125 testExtraMethods() { 125 testExtraMethods() {
126 Events sentEvents = new Events()..add(7)..add(9)..add(13)..add(87)..close(); 126 Events sentEvents = new Events()..add(7)..add(9)..add(13)..add(87)..close();
127 127
128 test("forEach", () {
129 StreamController c = new StreamController();
130 Events actualEvents = new Events();
131 Future f = c.stream.forEach(actualEvents.add);
132 f.then(expectAsync1((_) {
133 actualEvents.close();
134 Expect.listEquals(sentEvents.events, actualEvents.events);
135 }));
136 sentEvents.replay(c);
137 });
138
139 test("forEachError", () {
140 Events sentEvents = new Events()..add(7)..error("bad")..add(87)..close();
141 StreamController c = new StreamController();
142 Events actualEvents = new Events();
143 Future f = c.stream.forEach(actualEvents.add);
144 f.catchError(expectAsync1((error) {
145 Expect.equals("bad", error);
146 Expect.listEquals((new Events()..add(7)).events, actualEvents.events);
147 }));
148 sentEvents.replay(c);
149 });
150
151 test("forEachError2", () {
152 Events sentEvents = new Events()..add(7)..add(9)..add(87)..close();
153 StreamController c = new StreamController();
154 Events actualEvents = new Events();
155 Future f = c.stream.forEach((x) {
156 if (x == 9) throw "bad";
157 actualEvents.add(x);
158 });
159 f.catchError(expectAsync1((error) {
160 Expect.equals("bad", error);
161 Expect.listEquals((new Events()..add(7)).events, actualEvents.events);
162 }));
163 sentEvents.replay(c);
164 });
165
128 test("firstWhere", () { 166 test("firstWhere", () {
129 StreamController c = new StreamController(); 167 StreamController c = new StreamController();
130 Future f = c.stream.firstWhere((x) => (x % 3) == 0); 168 Future f = c.stream.firstWhere((x) => (x % 3) == 0);
131 f.then(expectAsync1((v) { Expect.equals(9, v); })); 169 f.then(expectAsync1((v) { Expect.equals(9, v); }));
132 sentEvents.replay(c); 170 sentEvents.replay(c);
133 }); 171 });
134 172
135 test("firstWhere 2", () { 173 test("firstWhere 2", () {
136 StreamController c = new StreamController(); 174 StreamController c = new StreamController();
137 Future f = c.stream.firstWhere((x) => (x % 4) == 0); 175 Future f = c.stream.firstWhere((x) => (x % 4) == 0);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 Expect.listEquals(expectedEvents.events, actualEvents.events); 404 Expect.listEquals(expectedEvents.events, actualEvents.events);
367 })); 405 }));
368 actualEvents.resume(); 406 actualEvents.resume();
369 }); 407 });
370 } 408 }
371 409
372 class TestError { const TestError(); } 410 class TestError { const TestError(); }
373 411
374 testRethrow() { 412 testRethrow() {
375 TestError error = const TestError(); 413 TestError error = const TestError();
376 414
377 415
378 testStream(name, streamValueTransform) { 416 testStream(name, streamValueTransform) {
379 test("rethrow-$name-value", () { 417 test("rethrow-$name-value", () {
380 StreamController c = new StreamController(); 418 StreamController c = new StreamController();
381 Stream s = streamValueTransform(c.stream, (v) { throw error; }); 419 Stream s = streamValueTransform(c.stream, (v) { throw error; });
382 s.listen((_) { Expect.fail("unexpected value"); }, onError: expectAsync1( 420 s.listen((_) { Expect.fail("unexpected value"); }, onError: expectAsync1(
383 (e) { Expect.identical(error, e); })); 421 (e) { Expect.identical(error, e); }));
384 c.add(null); 422 c.add(null);
385 c.close(); 423 c.close();
386 }); 424 });
(...skipping 22 matching lines...) Expand all
409 c.close(); 447 c.close();
410 }); 448 });
411 } 449 }
412 450
413 testStream("where", (s, act) => s.where(act)); 451 testStream("where", (s, act) => s.where(act));
414 testStream("map", (s, act) => s.map(act)); 452 testStream("map", (s, act) => s.map(act));
415 testStream("expand", (s, act) => s.expand(act)); 453 testStream("expand", (s, act) => s.expand(act));
416 testStream("where", (s, act) => s.where(act)); 454 testStream("where", (s, act) => s.where(act));
417 testStreamError("handleError", (s, act) => s.handleError(act)); 455 testStreamError("handleError", (s, act) => s.handleError(act));
418 testStreamError("handleTest", (s, act) => s.handleError((v) {}, test: act)); 456 testStreamError("handleTest", (s, act) => s.handleError((v) {}, test: act));
457 testFuture("forEach", (s, act) => s.forEach(act));
419 testFuture("every", (s, act) => s.every(act)); 458 testFuture("every", (s, act) => s.every(act));
420 testFuture("any", (s, act) => s.any(act)); 459 testFuture("any", (s, act) => s.any(act));
421 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); 460 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b)));
422 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); 461 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b)));
423 } 462 }
424 463
425 main() { 464 main() {
426 testController(); 465 testController();
427 testSingleController(); 466 testSingleController();
428 testExtraMethods(); 467 testExtraMethods();
429 testPause(); 468 testPause();
430 testRethrow(); 469 testRethrow();
431 } 470 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698