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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tests/lib_strong/async/stream_transformer_from_handlers_test.dart
diff --git a/tests/lib_strong/async/stream_transformer_from_handlers_test.dart b/tests/lib_strong/async/stream_transformer_from_handlers_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d9e56b800996b6dc0607ed2b1ee6311a28c4dc13
--- /dev/null
+++ b/tests/lib_strong/async/stream_transformer_from_handlers_test.dart
@@ -0,0 +1,67 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:expect/expect.dart';
+import 'package:async_helper/async_helper.dart';
+import 'dart:async';
+import 'event_helper.dart';
+
+
+get currentStackTrace {
+ try {
+ throw 0;
+ } catch (e, st) {
+ return st;
+ }
+}
+
+// In most cases the callback will be 'asyncEnd'. Errors are reported
+// asynchronously. We want to give them time to surface before reporting
+// asynchronous tests as done.
+void delayCycles(callback, int nbCycles) {
+ if (nbCycles == 0) {
+ callback();
+ return;
+ }
+ Timer.run(() {
+ delayCycles(callback, nbCycles - 1);
+ });
+}
+
+main() {
+ // Make sure the generic types are correct.
+ asyncStart();
+ var stackTrace = currentStackTrace;
+ var events = [];
+ var controller;
+ controller = new StreamController(onListen: () {
+ controller.add(499);
+ controller.addError(42, stackTrace);
+ controller.close();
+ });
+ controller.stream
+ .transform(
+ new StreamTransformer<int, String>.fromHandlers(
+ handleData: (int data, EventSink<String> sink) {
+ sink.add(data.toString());
+ },
+ handleError: (e, st, EventSink<String> sink) {
+ sink.add(e.toString());
+ sink.addError(e, st);
+ },
+ handleDone: (EventSink<String> sink) {
+ sink.add("done");
+ sink.close();
+ }))
+ .listen((data) => events.add(data),
+ onError: (e, st) {
+ events.add(e);
+ events.add(st);
+ },
+ onDone: () {
+ Expect.listEquals(["499", "42", 42, stackTrace, "done"],
+ events);
+ delayCycles(asyncEnd, 3);
+ });
+}
« 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