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

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

Issue 11953103: Add public-facing method and class that allows intercepting stream events. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments 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 | « tests/lib/async/stream_controller_test.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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import '../../../pkg/unittest/lib/unittest.dart';
7 import 'event_helper.dart';
8
9 void handleData(int data, StreamSink<int> sink) {
10 sink.signalError(new AsyncError("$data"));
11 sink.add(data + 1);
12 }
13 void handleError(AsyncError e, StreamSink<int> sink) {
14 String value = e.error;
15 int data = int.parse(value);
16 sink.add(data);
17 sink.signalError(new AsyncError("${data + 1}"));
18 }
19
20 void handleDone(StreamSink<int> sink) {
21 sink.add(99);
22 sink.close();
23 }
24
25 class EventTransformer extends StreamEventTransformer<int,int> {
26 void handleData(int data, StreamSink<int> sink) {
27 sink.signalError(new AsyncError("$data"));
28 sink.add(data + 1);
29 }
30 void handleError(AsyncError e, StreamSink<int> sink) {
31 String value = e.error;
32 int data = int.parse(value);
33 sink.add(data);
34 sink.signalError(new AsyncError("${data + 1}"));
35 }
36
37 void handleDone(StreamSink<int> sink) {
38 sink.add(99);
39 sink.close();
40 }
41 }
42
43 main() {
44 {
45 StreamController c = new StreamController();
46 Events expected = new Events()..error("0")..add(1)
47 ..error("1")..add(2)
48 ..add(3)..error("4")
49 ..add(99)..close();
50 Events input = new Events()..add(0)..add(1)..error("3")..close();
51 Events actual = new Events.capture(
52 c.stream.transformEvents(new EventTransformer()));
53 actual.onDone(() {
54 Expect.listEquals(expected.events, actual.events);
55 });
56 input.replay(c);
57 }
58
59 {
60 StreamController c = new StreamController();
61 Events expected = new Events()..error("0")..add(1)
62 ..error("1")..add(2)
63 ..add(3)..error("4")
64 ..add(99)..close();
65 Events input = new Events()..add(0)..add(1)..error("3")..close();
66 Events actual = new Events.capture(
67 c.stream.transformEvents(new StreamEventTransformer.from(
68 handleData: handleData,
69 handleError: handleError,
70 handleDone: handleDone
71 )));
72 actual.onDone(() {
73 Expect.listEquals(expected.events, actual.events);
74 });
75 input.replay(c);
76 }
77 }
OLDNEW
« no previous file with comments | « tests/lib/async/stream_controller_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698