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])); |
+} |