| Index: tests/lib/convert/chunked_conversion_utf86_test.dart
|
| diff --git a/tests/lib/convert/utf82_test.dart b/tests/lib/convert/chunked_conversion_utf86_test.dart
|
| similarity index 77%
|
| copy from tests/lib/convert/utf82_test.dart
|
| copy to tests/lib/convert/chunked_conversion_utf86_test.dart
|
| index b52f240ccdabc98b5a1f2b75c9ab6d4c92aa1fb7..916e7ab87457604efe35cd86a34cd18105d9f7cb 100644
|
| --- a/tests/lib/convert/utf82_test.dart
|
| +++ b/tests/lib/convert/chunked_conversion_utf86_test.dart
|
| @@ -2,29 +2,30 @@
|
| // 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.
|
|
|
| -library utf8_test;
|
| import "package:expect/expect.dart";
|
| import 'dart:convert';
|
|
|
| -String decode(List<int> bytes) => new Utf8Decoder().convert(bytes);
|
| -String decodeAllowMalformed(List<int> bytes) {
|
| - return new Utf8Decoder(allowMalformed: true).convert(bytes);
|
| -}
|
| -
|
| -String decode2(List<int> bytes) => UTF8.decode(bytes);
|
| -String decodeAllowMalformed2(List<int> bytes) {
|
| - return UTF8.decode(bytes, allowMalformed: true);
|
| +String decode(List<int> bytes) {
|
| + StringBuffer buffer = new StringBuffer();
|
| + ChunkedConversionSink stringSink =
|
| + new StringConversionSink.fromStringSink(buffer);
|
| + var byteSink = new Utf8Decoder().startChunkedConversion(stringSink);
|
| + bytes.forEach((byte) { byteSink.add([byte]); });
|
| + byteSink.close();
|
| + return buffer.toString();
|
| }
|
|
|
| -String decode3(List<int> bytes) => new Utf8Codec().decode(bytes);
|
| -String decodeAllowMalformed3(List<int> bytes) {
|
| - return new Utf8Codec(allowMalformed: true).decode(bytes);
|
| +String decodeAllowMalformed(List<int> bytes) {
|
| + StringBuffer buffer = new StringBuffer();
|
| + ChunkedConversionSink stringSink =
|
| + new StringConversionSink.fromStringSink(buffer);
|
| + var decoder = new Utf8Decoder(allowMalformed: true);
|
| + var byteSink = decoder.startChunkedConversion(stringSink);
|
| + bytes.forEach((byte) { byteSink.add([byte]); });
|
| + byteSink.close();
|
| + return buffer.toString();
|
| }
|
|
|
| -String decode4(List<int> bytes) => new Utf8Codec().decoder.convert(bytes);
|
| -String decodeAllowMalformed4(List<int> bytes) {
|
| - return new Utf8Codec(allowMalformed: true).decoder.convert(bytes);
|
| -}
|
|
|
| final TESTS = [
|
| // Unfinished UTF-8 sequences.
|
| @@ -121,14 +122,8 @@ main() {
|
| for (var test in []..addAll(allTests)..addAll(allTests2)) {
|
| List<int> bytes = test[0];
|
| Expect.throws(() => decode(bytes), (e) => e is FormatException);
|
| - Expect.throws(() => decode2(bytes), (e) => e is FormatException);
|
| - Expect.throws(() => decode3(bytes), (e) => e is FormatException);
|
| - Expect.throws(() => decode4(bytes), (e) => e is FormatException);
|
|
|
| String expected = test[1];
|
| Expect.equals(expected, decodeAllowMalformed(bytes));
|
| - Expect.equals(expected, decodeAllowMalformed2(bytes));
|
| - Expect.equals(expected, decodeAllowMalformed3(bytes));
|
| - Expect.equals(expected, decodeAllowMalformed4(bytes));
|
| }
|
| }
|
|
|