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