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

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

Issue 19883003: Add chunked conversion to converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve some typse. 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_utf83_test.dart
diff --git a/tests/lib/convert/chunked_conversion_utf83_test.dart b/tests/lib/convert/chunked_conversion_utf83_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0cf9ad25593f32ebef4afba7f77a69c1bd7c972a
--- /dev/null
+++ b/tests/lib/convert/chunked_conversion_utf83_test.dart
@@ -0,0 +1,42 @@
+// Copyright (c) 2012, 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.
+
+// 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.
+
+library utf8_test;
+import "package:expect/expect.dart";
+import 'dart:convert';
+
+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 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();
+}
+
+main() {
+ // Test that chunked UTF8-decoder removes leading BOM.
+ Expect.equals("a", decode([0xEF, 0xBB, 0xBF, 0x61]));
+ Expect.equals("a", decodeAllowMalformed([0xEF, 0xBB, 0xBF, 0x61]));
+ Expect.equals("", decode([0xEF, 0xBB, 0xBF]));
+ Expect.equals("", decodeAllowMalformed([0xEF, 0xBB, 0xBF]));
+ Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF]));
+ Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF]));
+}

Powered by Google App Engine
This is Rietveld 408576698