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

Unified Diff: test/byte_collection_test.dart

Issue 2661603002: Add collectBytesCancelable function. (Closed)
Patch Set: merge to head 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/byte_collection_test.dart
diff --git a/test/byte_collection_test.dart b/test/byte_collection_test.dart
index 8068542702822310fed3beedafbb27e196328226..74ab0435d5f1c393983490ab3164652ccbc8119d 100644
--- a/test/byte_collection_test.dart
+++ b/test/byte_collection_test.dart
@@ -6,7 +6,7 @@ import "dart:async";
import "dart:typed_data";
import "package:test/test.dart";
-import "package:async/async.dart" show byteCollector, collectBytes, Result;
+import "package:async/async.dart";
void main() {
group("collectBytes", () {
@@ -36,4 +36,56 @@ void main() {
expect(result, throwsA("badness"));
});
});
+
+ group("collectBytes", () {
+ test("simple list and overflow", () {
+ var result = collectBytesCancelable(new Stream.fromIterable([
+ [0],
+ [1],
+ [2],
+ [256]
+ ]));
+ expect(result.value, completion([0, 1, 2, 0]));
+ });
+
+ test("no events", () {
+ var result = collectBytesCancelable(new Stream.fromIterable([]));
+ expect(result.value, completion([]));
+ });
+
+ test("empty events", () {
+ var result = collectBytesCancelable(new Stream.fromIterable([[], []]));
+ expect(result.value, completion([]));
+ });
+
+ test("error event", () {
+ var result = collectBytesCancelable(new Stream.fromIterable(
+ new Iterable.generate(3, (n) => n == 2 ? throw "badness" : [n])));
+ expect(result.value, throwsA("badness"));
+ });
+
+ test("cancelled", () async {
+ var sc = new StreamController<List<int>>();
+ var result = collectBytesCancelable(sc.stream);
+ // Value never completes.
+ result.value.whenComplete(expectAsync0((){}, count: 0));
+
+ expect(sc.hasListener, isTrue);
+ sc.add([1, 2]);
+ await nextTimerTick();
+ expect(sc.hasListener, isTrue);
+ sc.add([3, 4]);
+ await nextTimerTick();
+ expect(sc.hasListener, isTrue);
+ result.cancel();
+ expect(sc.hasListener, isFalse); // Cancelled immediately.
+ var replacement = await result.valueOrCancellation();
+ expect(replacement, isNull);
+ await nextTimerTick();
+ sc.close();
+ await nextTimerTick();
+ });
+ });
}
+
+Future nextTimerTick() => new Future((){});
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698