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

Unified Diff: tests/lib/convert/chunked_conversion_utf82_test.dart

Issue 19883003: Add chunked conversion to converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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 side-by-side diff with in-line comments
Download patch
Index: tests/lib/convert/chunked_conversion_utf82_test.dart
diff --git a/tests/lib/convert/utf82_test.dart b/tests/lib/convert/chunked_conversion_utf82_test.dart
similarity index 66%
copy from tests/lib/convert/utf82_test.dart
copy to tests/lib/convert/chunked_conversion_utf82_test.dart
index b52f240ccdabc98b5a1f2b75c9ab6d4c92aa1fb7..6e1c6e78416cb1acfeb05638814d46e763fc3eea 100644
--- a/tests/lib/convert/utf82_test.dart
+++ b/tests/lib/convert/chunked_conversion_utf82_test.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// 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.
@@ -6,24 +6,45 @@ 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 decode3(List<int> bytes) => new Utf8Codec().decode(bytes);
-String decodeAllowMalformed3(List<int> bytes) {
- return new Utf8Codec(allowMalformed: true).decode(bytes);
+String decode(List<int> bytes, int chunkSize) {
+ StringBuffer buffer = new StringBuffer();
+ ChunkedConversionSink stringSink =
+ new StringConversionSink.fromStringSink(buffer);
+ var byteSink = new Utf8Decoder().startChunkedConversion(stringSink);
+ int i = 0;
+ while (i < bytes.length) {
+ List nextChunk = [];
+ for (int j = 0; j < chunkSize; j++) {
+ if (i < bytes.length) {
+ nextChunk.add(bytes[i]);
+ i++;
+ }
+ }
+ byteSink.add(nextChunk);
+ }
+ 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);
+String decodeAllowMalformed(List<int> bytes, int chunkSize) {
+ StringBuffer buffer = new StringBuffer();
+ ChunkedConversionSink stringSink =
+ new StringConversionSink.fromStringSink(buffer);
+ var decoder = new Utf8Decoder(allowMalformed: true);
+ var byteSink = decoder.startChunkedConversion(stringSink);
+ int i = 0;
+ while (i < bytes.length) {
+ List nextChunk = [];
+ for (int j = 0; j < chunkSize; j++) {
+ if (i < bytes.length) {
+ nextChunk.add(bytes[i]);
+ i++;
+ }
+ }
+ byteSink.add(nextChunk);
+ }
+ byteSink.close();
+ return buffer.toString();
}
final TESTS = [
@@ -120,15 +141,15 @@ 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);
+ Expect.throws(() => decode(bytes, 1), (e) => e is FormatException);
+ Expect.throws(() => decode(bytes, 2), (e) => e is FormatException);
+ Expect.throws(() => decode(bytes, 3), (e) => e is FormatException);
+ Expect.throws(() => decode(bytes, 4), (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));
+ Expect.equals(expected, decodeAllowMalformed(bytes, 1));
+ Expect.equals(expected, decodeAllowMalformed(bytes, 2));
+ Expect.equals(expected, decodeAllowMalformed(bytes, 3));
+ Expect.equals(expected, decodeAllowMalformed(bytes, 4));
}
}
« no previous file with comments | « tests/lib/convert/chunked_conversion_json_encode1_test.dart ('k') | tests/lib/convert/chunked_conversion_utf83_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698