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

Side by Side Diff: tests/lib_strong/async/stream_transformer_from_handlers_test.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 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
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 import 'package:expect/expect.dart';
6 import 'package:async_helper/async_helper.dart';
7 import 'dart:async';
8 import 'event_helper.dart';
9
10
11 get currentStackTrace {
12 try {
13 throw 0;
14 } catch (e, st) {
15 return st;
16 }
17 }
18
19 // In most cases the callback will be 'asyncEnd'. Errors are reported
20 // asynchronously. We want to give them time to surface before reporting
21 // asynchronous tests as done.
22 void delayCycles(callback, int nbCycles) {
23 if (nbCycles == 0) {
24 callback();
25 return;
26 }
27 Timer.run(() {
28 delayCycles(callback, nbCycles - 1);
29 });
30 }
31
32 main() {
33 // Make sure the generic types are correct.
34 asyncStart();
35 var stackTrace = currentStackTrace;
36 var events = [];
37 var controller;
38 controller = new StreamController(onListen: () {
39 controller.add(499);
40 controller.addError(42, stackTrace);
41 controller.close();
42 });
43 controller.stream
44 .transform(
45 new StreamTransformer<int, String>.fromHandlers(
46 handleData: (int data, EventSink<String> sink) {
47 sink.add(data.toString());
48 },
49 handleError: (e, st, EventSink<String> sink) {
50 sink.add(e.toString());
51 sink.addError(e, st);
52 },
53 handleDone: (EventSink<String> sink) {
54 sink.add("done");
55 sink.close();
56 }))
57 .listen((data) => events.add(data),
58 onError: (e, st) {
59 events.add(e);
60 events.add(st);
61 },
62 onDone: () {
63 Expect.listEquals(["499", "42", 42, stackTrace, "done"],
64 events);
65 delayCycles(asyncEnd, 3);
66 });
67 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/stream_transformation_broadcast_test.dart ('k') | tests/lib_strong/async/stream_transformer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698