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

Side by Side Diff: test/codegen/lib/convert/streamed_conversion_utf8_decode_test.dart

Issue 1965563003: Update dart:convert and dart:core Uri. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
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 "package:async_helper/async_helper.dart";
10
11 Stream<String> decode(List<int> bytes, int chunkSize) {
12 var controller;
13 controller = new StreamController(onListen: () {
14 int i = 0;
15 while (i < bytes.length) {
16 List nextChunk = [];
17 for (int j = 0; j < chunkSize; j++) {
18 if (i < bytes.length) {
19 nextChunk.add(bytes[i]);
20 i++;
21 }
22 }
23 controller.add(nextChunk);
24 }
25 controller.close();
26 });
27 return controller.stream.transform(UTF8.decoder);
28 }
29
30 testUnpaused(String expected, Stream stream) {
31 asyncStart();
32 stream.toList().then((list) {
33 StringBuffer buffer = new StringBuffer();
34 buffer.writeAll(list);
35 Expect.stringEquals(expected, buffer.toString());
36 asyncEnd();
37 });
38 }
39
40 testWithPauses(String expected, Stream stream) {
41 asyncStart();
42 StringBuffer buffer = new StringBuffer();
43 var sub;
44 sub = stream.listen((x) {
45 buffer.write(x);
46 sub.pause(new Future.delayed(Duration.ZERO));
47 }, onDone: () {
48 Expect.stringEquals(expected, buffer.toString());
49 asyncEnd();
50 });
51 }
52
53 main() {
54 for (var test in UNICODE_TESTS) {
55 var bytes = test[0];
56 var expected = test[1];
57 testUnpaused(expected, decode(bytes, 1));
58 testWithPauses(expected, decode(bytes, 1));
59 testUnpaused(expected, decode(bytes, 2));
60 testWithPauses(expected, decode(bytes, 2));
61 testUnpaused(expected, decode(bytes, 3));
62 testWithPauses(expected, decode(bytes, 3));
63 testUnpaused(expected, decode(bytes, 4));
64 testWithPauses(expected, decode(bytes, 4));
65 }
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698