| OLD | NEW |
| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 f.then(expectAsync1((v) { Expect.equals(13, v);})); | 288 f.then(expectAsync1((v) { Expect.equals(13, v);})); |
| 289 sentEvents.replay(c); | 289 sentEvents.replay(c); |
| 290 }); | 290 }); |
| 291 | 291 |
| 292 test("elementAt 2", () { | 292 test("elementAt 2", () { |
| 293 StreamController c = new StreamController(); | 293 StreamController c = new StreamController(); |
| 294 Future f = c.stream.elementAt(20); | 294 Future f = c.stream.elementAt(20); |
| 295 f.catchError(expectAsync1((error) { Expect.isTrue(error is StateError); })); | 295 f.catchError(expectAsync1((error) { Expect.isTrue(error is StateError); })); |
| 296 sentEvents.replay(c); | 296 sentEvents.replay(c); |
| 297 }); | 297 }); |
| 298 |
| 299 test("drain", () { |
| 300 StreamController c = new StreamController(); |
| 301 Future f = c.stream.drain(); |
| 302 f.then(expectAsync1((v) { Expect.equals(null, v);})); |
| 303 sentEvents.replay(c); |
| 304 }); |
| 305 |
| 306 test("drain error", () { |
| 307 StreamController c = new StreamController(); |
| 308 Future f = c.stream.drain(); |
| 309 f.catchError(expectAsync1((error) { Expect.equals("error", error); })); |
| 310 Events errorEvents = new Events()..error("error")..error("error2")..close(); |
| 311 errorEvents.replay(c); |
| 312 }); |
| 313 |
| 298 } | 314 } |
| 299 | 315 |
| 300 testPause() { | 316 testPause() { |
| 301 test("pause event-unpause", () { | 317 test("pause event-unpause", () { |
| 302 StreamController c = new StreamController(); | 318 StreamController c = new StreamController(); |
| 303 Events actualEvents = new Events.capture(c.stream); | 319 Events actualEvents = new Events.capture(c.stream); |
| 304 Events expectedEvents = new Events(); | 320 Events expectedEvents = new Events(); |
| 305 expectedEvents.add(42); | 321 expectedEvents.add(42); |
| 306 c.add(42); | 322 c.add(42); |
| 307 Expect.listEquals(expectedEvents.events, actualEvents.events); | 323 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 testStream("map", (s, act) => s.map(act)); | 468 testStream("map", (s, act) => s.map(act)); |
| 453 testStream("expand", (s, act) => s.expand(act)); | 469 testStream("expand", (s, act) => s.expand(act)); |
| 454 testStream("where", (s, act) => s.where(act)); | 470 testStream("where", (s, act) => s.where(act)); |
| 455 testStreamError("handleError", (s, act) => s.handleError(act)); | 471 testStreamError("handleError", (s, act) => s.handleError(act)); |
| 456 testStreamError("handleTest", (s, act) => s.handleError((v) {}, test: act)); | 472 testStreamError("handleTest", (s, act) => s.handleError((v) {}, test: act)); |
| 457 testFuture("forEach", (s, act) => s.forEach(act)); | 473 testFuture("forEach", (s, act) => s.forEach(act)); |
| 458 testFuture("every", (s, act) => s.every(act)); | 474 testFuture("every", (s, act) => s.every(act)); |
| 459 testFuture("any", (s, act) => s.any(act)); | 475 testFuture("any", (s, act) => s.any(act)); |
| 460 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); | 476 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); |
| 461 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); | 477 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); |
| 478 testFuture("drain", (s, act) => s.drain().then(act)); |
| 462 } | 479 } |
| 463 | 480 |
| 464 main() { | 481 main() { |
| 465 testController(); | 482 testController(); |
| 466 testSingleController(); | 483 testSingleController(); |
| 467 testExtraMethods(); | 484 testExtraMethods(); |
| 468 testPause(); | 485 testPause(); |
| 469 testRethrow(); | 486 testRethrow(); |
| 470 } | 487 } |
| OLD | NEW |