| OLD | NEW |
| (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 "dart:async"; |
| 6 import "package:unittest/unittest.dart"; |
| 7 |
| 8 main() { |
| 9 test("stream iterator basic", () { |
| 10 StreamController c = new StreamController(); |
| 11 Stream s = c.stream; |
| 12 StreamIterator i = new StreamIterator(s); |
| 13 i.moveNext().then(expectAsync1((bool b) { |
| 14 expect(b, isTrue); |
| 15 expect(42, i.current); |
| 16 return i.moveNext(); |
| 17 })).then(expectAsync1((bool b) { |
| 18 expect(b, isTrue); |
| 19 expect(37, i.current); |
| 20 return i.moveNext(); |
| 21 })).then(expectAsync1((bool b) { |
| 22 expect(b, isFalse); |
| 23 })); |
| 24 c.add(42); |
| 25 c.add(37); |
| 26 c.close(); |
| 27 }); |
| 28 |
| 29 test("stream iterator prefilled", () { |
| 30 StreamController c = new StreamController(); |
| 31 c.add(42); |
| 32 c.add(37); |
| 33 c.close(); |
| 34 Stream s = c.stream; |
| 35 StreamIterator i = new StreamIterator(s); |
| 36 i.moveNext().then(expectAsync1((bool b) { |
| 37 expect(b, isTrue); |
| 38 expect(42, i.current); |
| 39 return i.moveNext(); |
| 40 })).then(expectAsync1((bool b) { |
| 41 expect(b, isTrue); |
| 42 expect(37, i.current); |
| 43 return i.moveNext(); |
| 44 })).then(expectAsync1((bool b) { |
| 45 expect(b, isFalse); |
| 46 })); |
| 47 }); |
| 48 |
| 49 test("stream iterator error", () { |
| 50 StreamController c = new StreamController(); |
| 51 Stream s = c.stream; |
| 52 StreamIterator i = new StreamIterator(s); |
| 53 i.moveNext().then(expectAsync1((bool b) { |
| 54 expect(b, isTrue); |
| 55 expect(42, i.current); |
| 56 return i.moveNext(); |
| 57 })).then((bool b) { |
| 58 Expect.fail("Result not expected"); |
| 59 }, onError: expectAsync1((e) { |
| 60 expect("BAD", e); |
| 61 return i.moveNext(); |
| 62 })).then(expectAsync1((bool b) { |
| 63 expect(b, isFalse); |
| 64 })); |
| 65 c.add(42); |
| 66 c.addError("BAD"); |
| 67 c.add(37); |
| 68 c.close(); |
| 69 }); |
| 70 |
| 71 test("stream iterator current/moveNext during move", () { |
| 72 StreamController c = new StreamController(); |
| 73 Stream s = c.stream; |
| 74 StreamIterator i = new StreamIterator(s); |
| 75 i.moveNext().then(expectAsync1((bool b) { |
| 76 expect(b, isTrue); |
| 77 expect(42, i.current); |
| 78 new Timer(const Duration(milliseconds:100), expectAsync0(() { |
| 79 expect(i.current, null); |
| 80 expect(() { i.moveNext(); }, throws); |
| 81 c.add(37); |
| 82 c.close(); |
| 83 })); |
| 84 return i.moveNext(); |
| 85 })).then(expectAsync1((bool b) { |
| 86 expect(b, isTrue); |
| 87 expect(37, i.current); |
| 88 return i.moveNext(); |
| 89 })).then(expectAsync1((bool b) { |
| 90 expect(b, isFalse); |
| 91 })); |
| 92 c.add(42); |
| 93 }); |
| 94 } |
| OLD | NEW |