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

Side by Side Diff: tests/standalone/io/string_decoder_test.dart

Issue 11473018: Improve streaming UTF-8 decoder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
« sdk/lib/io/string_stream.dart ('K') | « sdk/lib/io/string_stream.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part '../../../sdk/lib/io/buffer_list.dart';
6 part '../../../sdk/lib/io/input_stream.dart';
7 part '../../../sdk/lib/io/string_stream.dart';
8
9 void test() {
10 // Code point U+10FFFF is the largest code point supported by Dart.
11 var decoder = _StringDecoders.decoder(Encoding.UTF_8);
12 decoder.write([0xf0, 0x90, 0x80, 0x80]); // U+10000
13 decoder.write([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
14 decoder.write([0xf4, 0x90, 0x80, 0x80]); // U+110000
15 decoder.write([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
16 decoder.write([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
17
18 var decoded = decoder.decoded();
19 Expect.equals(7, decoded.length);
20
21 var replacementChar = '?'.charCodeAt(0);
22 Expect.equals(0xd800, decoded.charCodeAt(0));
23 Expect.equals(0xdc00, decoded.charCodeAt(1));
24 Expect.equals(0xdbff, decoded.charCodeAt(2));
25 Expect.equals(0xdfff, decoded.charCodeAt(3));
26 Expect.equals(replacementChar, decoded.charCodeAt(4));
27 Expect.equals(replacementChar, decoded.charCodeAt(5));
28 Expect.equals(replacementChar, decoded.charCodeAt(6));
29 }
30
31 void testInvalid() {
32 var decoder = _StringDecoders.decoder(Encoding.UTF_8);
33 Expect.throws(() => decoder.write([0x80]));
34 Expect.throws(() => decoder.write([0xff]));
35 Expect.throws(() => decoder.write([0xf0, 0xc0]));
36 }
37
38 void main() {
39 test();
40 testInvalid();
41 }
OLDNEW
« sdk/lib/io/string_stream.dart ('K') | « sdk/lib/io/string_stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698