| OLD | NEW |
| (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 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 } |
| OLD | NEW |