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

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

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made tests run (mostly) Created 7 years, 7 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
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 library timer_test;
6
7 import 'dart:async';
8 import '../../../pkg/unittest/lib/unittest.dart';
9
10 main() {
11 // Test that the stream generates the integers 0..9.
12 testTenStream(String name, Stream<int> stream,
13 action(int count, StreamIterator iter)) {
14 test(name, () {
15 Function onDone = expectAsync0((){});
16 StreamIterator<int> iter = new StreamIterator<int>(stream);
17
18 void testNext(int expectedNext) {
19 if (expectedNext < 10) {
20 iter.moveNext().then((v) {
21 expect(v, isTrue);
22 expect(iter.current, equals(expectedNext));
23 testNext(expectedNext + 1); // May change "current".
24 action(expectedNext, iter);
25 });
26 } else {
27 iter.moveNext().then((v) {
28 expect(v, isFalse);
29 onDone();
30 });
31 }
32 }
33 testNext(0);
34 });
35 }
36
37 testTenStream("fromIterable",
38 new Stream.fromIterable(new Iterable.generate(10, (x) => x)),
39 (count, iter) {});
40
41 testTenStream("periodic",
42 new Stream.periodic(const Duration(milliseconds: 5), (x) => x),
43 (count, iter) { if (count == 9) iter.cancel(); });
44
45 StreamController<int> c = new StreamController<int>();
46 c.add(0);
47 testTenStream("controller", c.stream,
48 (count, iter) {
49 if (count < 9) {
50 c.add(count + 1);
51 } else {
52 c.close();
53 }
54 });
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698