| Index: tests/standalone/io/string_decoder_test.dart
|
| diff --git a/tests/standalone/io/string_decoder_test.dart b/tests/standalone/io/string_decoder_test.dart
|
| index 879cf8c0c57ec98b0355acc6b96e6b0939db36e9..6a81f957820a8b0245331ee3107a3e867bbfecea 100644
|
| --- a/tests/standalone/io/string_decoder_test.dart
|
| +++ b/tests/standalone/io/string_decoder_test.dart
|
| @@ -2,49 +2,60 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| +import "dart:async";
|
| import "dart:io";
|
|
|
| void test() {
|
| // Code point U+10FFFF is the largest code point supported by Dart.
|
| - //var decoder = _StringDecoders.decoder(Encoding.UTF_8);
|
| - ListInputStream lis = new ListInputStream();
|
| - lis.write([0xf0, 0x90, 0x80, 0x80]); // U+10000
|
| - lis.write([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
|
| - lis.write([0xf4, 0x90, 0x80, 0x80]); // U+110000
|
| - lis.write([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
|
| - lis.write([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
|
| - lis.markEndOfStream();
|
| + var controller = new StreamController();
|
| + controller.add([0xf0, 0x90, 0x80, 0x80]); // U+10000
|
| + controller.add([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
|
| + controller.add([0xf4, 0x90, 0x80, 0x80]); // U+110000
|
| + controller.add([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
|
| + controller.add([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
|
| + controller.close();
|
|
|
| - var sis = new StringInputStream(lis);
|
| - sis.onData = () {
|
| - var decoded = sis.read();
|
| - Expect.equals(7, decoded.length);
|
| + var decoder = new StringDecoder(Encoding.UTF_8, '?'.charCodeAt(0));
|
| + var stream = controller.stream.transform(decoder);
|
| + stream.reduce(
|
| + new StringBuffer(),
|
| + (b, e) {
|
| + b.add(e);
|
| + return b;
|
| + })
|
| + .then((b) => b.toString())
|
| + .then((decoded) {
|
| + Expect.equals(7, decoded.length);
|
|
|
| - var replacementChar = '?'.charCodeAt(0);
|
| - Expect.equals(0xd800, decoded.charCodeAt(0));
|
| - Expect.equals(0xdc00, decoded.charCodeAt(1));
|
| - Expect.equals(0xdbff, decoded.charCodeAt(2));
|
| - Expect.equals(0xdfff, decoded.charCodeAt(3));
|
| - Expect.equals(replacementChar, decoded.charCodeAt(4));
|
| - Expect.equals(replacementChar, decoded.charCodeAt(5));
|
| - Expect.equals(replacementChar, decoded.charCodeAt(6));
|
| - };
|
| + var replacementChar = '?'.charCodeAt(0);
|
| + Expect.equals(0xd800, decoded.charCodeAt(0));
|
| + Expect.equals(0xdc00, decoded.charCodeAt(1));
|
| + Expect.equals(0xdbff, decoded.charCodeAt(2));
|
| + Expect.equals(0xdfff, decoded.charCodeAt(3));
|
| + Expect.equals(replacementChar, decoded.charCodeAt(4));
|
| + Expect.equals(replacementChar, decoded.charCodeAt(5));
|
| + Expect.equals(replacementChar, decoded.charCodeAt(6));
|
| + });
|
| }
|
|
|
| void testInvalid() {
|
| - void invalid(var bytes) {
|
| - ListInputStream lis = new ListInputStream();
|
| - lis.write(bytes);
|
| - lis.markEndOfStream();
|
| - var sis = new StringInputStream(lis);
|
| - sis.onData = () { throw "onData not expected"; };
|
| - sis.onError = (e) { Expect.isTrue(e is DecoderException); };
|
| - sis.onClosed = () { throw "onClosed not expected"; };
|
| + void invalid(var bytes, var outputLength) {
|
| + var controller = new StreamController();
|
| + controller.add(bytes);
|
| + controller.close();
|
| + controller.stream.transform(new StringDecoder()).listen((string) {
|
| + Expect.equals(outputLength, string.length);
|
| + for (var i = 0; i < outputLength; i++) {
|
| + Expect.equals(0xFFFD, string.charCodeAt(i));
|
| + }
|
| + });
|
| }
|
|
|
| - invalid([0x80]);
|
| - invalid([0xff]);
|
| - invalid([0xf0, 0xc0]);
|
| + invalid([0x80], 1);
|
| + invalid([0xff], 1);
|
| + invalid([0xf0, 0xc0], 1);
|
| + invalid([0xc0, 0x80], 1);
|
| + invalid([0xfd, 0x80, 0x80], 3); // Unfinished encoding.
|
| }
|
|
|
| void main() {
|
|
|