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

Side by Side Diff: tests/lib/convert/streamed_conversion_json_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, 5 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 'json_unicode_tests.dart';
9 import '../../async_helper.dart';
10
11 final JSON_UTF8 = JSON.fuse(UTF8);
12
13
14 Stream<List<int>> encode(Object o) {
15 var controller;
16 controller = new StreamController(onListen: () {
17 controller.add(o);
18 controller.close();
19 });
20 return controller.stream.transform(JSON_UTF8.encoder);
21 }
22
23 void testUnpaused(List<int> expected, Stream stream) {
24 asyncStart();
25 stream.toList().then((list) {
26 var combined = [];
27 list.forEach(combined.addAll);
28 Expect.listEquals(expected, combined);
29 asyncEnd();
30 });
31 }
32
33 void testWithPauses(List<int> expected, Stream stream) {
34 asyncStart();
35 var accumulated = [];
36 var sub;
37 sub = stream.listen((x) {
38 accumulated.addAll(x);
39 sub.pause(new Future.delayed(Duration.ZERO));
40 }, onDone: () {
41 Expect.listEquals(expected, accumulated);
42 asyncEnd();
43 });
44 }
45
46 void main() {
47 for (var test in JSON_UNICODE_TESTS) {
48 var expected = test[0];
49 var object = test[1];
50 testUnpaused(expected, encode(object));
51 testWithPauses(expected, encode(object));
52 }
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698