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

Side by Side Diff: tests/lib/convert/streamed_conversion_utf8_encode_test.dart

Issue 20374003: Add transformer support to Converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Upload Created 7 years, 4 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) 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 "package:expect/expect.dart";
6 import 'dart:async';
7 import 'dart:convert';
8 import 'unicode_tests.dart';
9 import '../../async_helper.dart';
10
11 Stream<List<int>> encode(String string, int chunkSize) {
12 var controller;
13 controller = new StreamController(onListen: () {
14 int i = 0;
15 while (i < string.length) {
16 if (i + chunkSize <= string.length) {
17 controller.add(string.substring(i, i + chunkSize));
18 } else {
19 controller.add(string.substring(i));
20 }
21 i += chunkSize;
22 }
23 controller.close();
24 });
25 return controller.stream.transform(UTF8.encoder);
26 }
27
28 void testUnpaused(List<int> expected, Stream stream) {
29 asyncStart();
30 stream.toList().then((list) {
31 var combined = [];
32 // Flatten the list.
33 list.forEach(combined.addAll);
34 Expect.listEquals(expected, combined);
35 asyncEnd();
36 });
37 }
38
39 void testWithPauses(List<int> expected, Stream stream) {
40 asyncStart();
41 var combined = [];
42 var sub;
43 sub = stream.listen((x) {
44 combined.addAll(x);
45 sub.pause(new Future.delayed(Duration.ZERO));
46 }, onDone: () {
47 Expect.listEquals(expected, combined);
48 asyncEnd();
49 });
50 }
51
52 main() {
53 for (var test in UNICODE_TESTS) {
54 var expected = test[0];
55 var string = test[1];
56 testUnpaused(expected, encode(string, 1));
57 testWithPauses(expected, encode(string, 1));
58 testUnpaused(expected, encode(string, 2));
59 testWithPauses(expected, encode(string, 2));
60 }
61 }
OLDNEW
« no previous file with comments | « tests/lib/convert/streamed_conversion_utf8_decode_test.dart ('k') | tests/lib/convert/unicode_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698