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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
6 // for details. All rights reserved. Use of this source code is governed by a
7 // BSD-style license that can be found in the LICENSE file.
8
9 library utf8_test;
10 import "package:expect/expect.dart";
11 import 'dart:convert';
12
13 String decode(List<int> bytes) {
14 StringBuffer buffer = new StringBuffer();
15 ChunkedConversionSink stringSink =
16 new StringConversionSink.fromStringSink(buffer);
17 var byteSink = new Utf8Decoder().startChunkedConversion(stringSink);
18 bytes.forEach((byte) { byteSink.add([byte]); });
19 byteSink.close();
20 return buffer.toString();
21 }
22
23 String decodeAllowMalformed(List<int> bytes) {
24 StringBuffer buffer = new StringBuffer();
25 ChunkedConversionSink stringSink =
26 new StringConversionSink.fromStringSink(buffer);
27 var decoder = new Utf8Decoder(allowMalformed: true);
28 var byteSink = decoder.startChunkedConversion(stringSink);
29 bytes.forEach((byte) { byteSink.add([byte]); });
30 byteSink.close();
31 return buffer.toString();
32 }
33
34 main() {
35 // Test that chunked UTF8-decoder removes leading BOM.
36 Expect.equals("a", decode([0xEF, 0xBB, 0xBF, 0x61]));
37 Expect.equals("a", decodeAllowMalformed([0xEF, 0xBB, 0xBF, 0x61]));
38 Expect.equals("", decode([0xEF, 0xBB, 0xBF]));
39 Expect.equals("", decodeAllowMalformed([0xEF, 0xBB, 0xBF]));
40 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF]));
41 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF]));
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698