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

Side by Side Diff: test/byte_collection_test.dart

Issue 2661603002: Add collectBytesCancelable function. (Closed)
Patch Set: Created 3 years, 10 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
« lib/src/byte_collector.dart ('K') | « lib/src/byte_collector.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 "dart:typed_data"; 6 import "dart:typed_data";
7 7
8 import "package:test/test.dart"; 8 import "package:test/test.dart";
9 import "package:async/async.dart" show byteCollector, collectBytes, Result; 9 import "package:async/async.dart" show collectBytes, collectBytesCancelable;
nweiz 2017/01/27 21:56:00 I don't think it's worth maintaining a "show" list
Lasse Reichstein Nielsen 2017/01/30 15:06:33 Done.
nweiz 2017/01/31 22:23:09 I think you missed this one.
Lasse Reichstein Nielsen 2017/02/01 12:05:43 ACK. Fixing.
10 10
11 void main() { 11 void main() {
12 group("collectBytes", () { 12 group("collectBytes", () {
13 test("simple list and overflow", () { 13 test("simple list and overflow", () {
14 var result = collectBytes(new Stream.fromIterable([ 14 var result = collectBytes(new Stream.fromIterable([
15 [0], 15 [0],
16 [1], 16 [1],
17 [2], 17 [2],
18 [256] 18 [256]
19 ])); 19 ]));
20 expect(result, completion([0, 1, 2, 0])); 20 expect(result, completion([0, 1, 2, 0]));
21 }); 21 });
22 22
23 test("no events", () { 23 test("no events", () {
24 var result = collectBytes(new Stream.fromIterable([])); 24 var result = collectBytes(new Stream.fromIterable([]));
25 expect(result, completion([])); 25 expect(result, completion([]));
26 }); 26 });
27 27
28 test("empty events", () { 28 test("empty events", () {
29 var result = collectBytes(new Stream.fromIterable([[], []])); 29 var result = collectBytes(new Stream.fromIterable([[], []]));
30 expect(result, completion([])); 30 expect(result, completion([]));
31 }); 31 });
32 32
33 test("error event", () { 33 test("error event", () {
34 var result = collectBytes(new Stream.fromIterable( 34 var result = collectBytes(new Stream.fromIterable(
35 new Iterable.generate(3, (n) => n == 2 ? throw "badness" : [n]))); 35 new Iterable.generate(3, (n) => n == 2 ? throw "badness" : [n])));
36 expect(result, throwsA("badness")); 36 expect(result, throwsA("badness"));
37 }); 37 });
38 }); 38 });
39
40 group("collectBytes", () {
41 test("simple list and overflow", () {
42 var result = collectBytesCancelable(new Stream.fromIterable([
43 [0],
44 [1],
45 [2],
46 [256]
47 ]));
48 expect(result.value, completion([0, 1, 2, 0]));
49 });
50
51 test("no events", () {
52 var result = collectBytesCancelable(new Stream.fromIterable([]));
53 expect(result.value, completion([]));
54 });
55
56 test("empty events", () {
57 var result = collectBytesCancelable(new Stream.fromIterable([[], []]));
58 expect(result.value, completion([]));
59 });
60
61 test("error event", () {
62 var result = collectBytesCancelable(new Stream.fromIterable(
63 new Iterable.generate(3, (n) => n == 2 ? throw "badness" : [n])));
64 expect(result.value, throwsA("badness"));
65 });
66
67 test("cancelled", () async {
68 var sc = new StreamController<List<int>>();
69 var result = collectBytesCancelable(sc.stream);
70 // Value never completes.
71 result.value.whenComplete(expectAsync0((){}, count: 0));
72
73 expect(sc.hasListener, isTrue);
74 sc.add([1, 2]);
75 await nextTimerTick();
76 expect(sc.hasListener, isTrue);
77 sc.add([3, 4]);
78 await nextTimerTick();
79 expect(sc.hasListener, isTrue);
80 result.cancel();
81 expect(sc.hasListener, isFalse); // Cancelled immediately.
82 var replacement = await result.valueOrCancellation();
83 expect(replacement, isNull);
84 await nextTimerTick();
85 sc.close();
86 await nextTimerTick();
87 });
88 });
39 } 89 }
90
91 Future nextTimerTick() => new Future((){});
OLDNEW
« lib/src/byte_collector.dart ('K') | « lib/src/byte_collector.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698