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

Unified Diff: packages/quiver/test/async/stream_router_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « packages/quiver/test/async/metronome_test.dart ('k') | packages/quiver/test/cache/map_cache_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/quiver/test/async/stream_router_test.dart
diff --git a/packages/quiver/test/async/stream_router_test.dart b/packages/quiver/test/async/stream_router_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5356c6756cbdd64678a097b58bc54411b930fc98
--- /dev/null
+++ b/packages/quiver/test/async/stream_router_test.dart
@@ -0,0 +1,78 @@
+// Copyright 2013 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+library quiver.async.stream_router_test;
+
+import 'dart:async';
+
+import 'package:test/test.dart';
+import 'package:quiver/async.dart';
+
+main() {
+ group('StreamRouter', () {
+ test('should route an event to the correct stream', () {
+ var controller = new StreamController<String>();
+ new StreamRouter<String>(controller.stream)
+ ..route((e) => e == 'foo').listen((e) {
+ expect(e, 'foo');
+ })
+ ..route((e) => e == 'bar').listen((e) {
+ fail('wrong stream');
+ })
+ ..route((e) => e == 'foo').listen((e) {
+ fail('wrong stream');
+ })
+ ..defaultStream.listen((e) {
+ fail('wrong stream');
+ });
+ controller.add('foo');
+ return controller.close();
+ });
+
+ test('should send events that match no predicate to defaultStream', () {
+ var controller = new StreamController<String>();
+ new StreamRouter<String>(controller.stream)
+ ..route((e) => e == 'foo').listen((e) {
+ fail('wrong stream');
+ })
+ ..route((e) => e == 'bar').listen((e) {
+ fail('wrong stream');
+ })
+ ..defaultStream.listen((e) {
+ expect(e, 'baz');
+ });
+ controller.add('baz');
+ return controller.close();
+ });
+
+ test('should close child streams', () {
+ var controller = new StreamController<int>(sync: true);
+ var router = new StreamRouter<int>(controller.stream);
+ // toList() will only complete when the child streams are closed
+ var future = Future
+ .wait([
+ router.route((e) => e % 2 == 0).toList(),
+ router.route((e) => e % 2 == 1).toList(),
+ ])
+ .then((l) {
+ expect(l, [[4], [5]]);
+ });
+ controller
+ ..add(4)
+ ..add(5);
+ router.close();
+ return future;
+ });
+ });
+}
« no previous file with comments | « packages/quiver/test/async/metronome_test.dart ('k') | packages/quiver/test/cache/map_cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698