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

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

Issue 11725007: Rewrite test (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
« no previous file with comments | « 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part '../../../sdk/lib/io/buffer_list.dart'; 5 import "dart:io";
6 part '../../../sdk/lib/io/input_stream.dart';
7 part '../../../sdk/lib/io/string_stream.dart';
8 6
9 void test() { 7 void test() {
10 // Code point U+10FFFF is the largest code point supported by Dart. 8 // Code point U+10FFFF is the largest code point supported by Dart.
11 var decoder = _StringDecoders.decoder(Encoding.UTF_8); 9 //var decoder = _StringDecoders.decoder(Encoding.UTF_8);
12 decoder.write([0xf0, 0x90, 0x80, 0x80]); // U+10000 10 ListInputStream lis = new ListInputStream();
13 decoder.write([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF 11 lis.write([0xf0, 0x90, 0x80, 0x80]); // U+10000
14 decoder.write([0xf4, 0x90, 0x80, 0x80]); // U+110000 12 lis.write([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
15 decoder.write([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000 13 lis.write([0xf4, 0x90, 0x80, 0x80]); // U+110000
16 decoder.write([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000 14 lis.write([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
15 lis.write([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
16 lis.markEndOfStream();
17 17
18 var decoded = decoder.decoded(); 18 var sis = new StringInputStream(lis);
19 Expect.equals(7, decoded.length); 19 sis.onData = () {
20 var decoded = sis.read();
21 Expect.equals(7, decoded.length);
20 22
21 var replacementChar = '?'.charCodeAt(0); 23 var replacementChar = '?'.charCodeAt(0);
22 Expect.equals(0xd800, decoded.charCodeAt(0)); 24 Expect.equals(0xd800, decoded.charCodeAt(0));
23 Expect.equals(0xdc00, decoded.charCodeAt(1)); 25 Expect.equals(0xdc00, decoded.charCodeAt(1));
24 Expect.equals(0xdbff, decoded.charCodeAt(2)); 26 Expect.equals(0xdbff, decoded.charCodeAt(2));
25 Expect.equals(0xdfff, decoded.charCodeAt(3)); 27 Expect.equals(0xdfff, decoded.charCodeAt(3));
26 Expect.equals(replacementChar, decoded.charCodeAt(4)); 28 Expect.equals(replacementChar, decoded.charCodeAt(4));
27 Expect.equals(replacementChar, decoded.charCodeAt(5)); 29 Expect.equals(replacementChar, decoded.charCodeAt(5));
28 Expect.equals(replacementChar, decoded.charCodeAt(6)); 30 Expect.equals(replacementChar, decoded.charCodeAt(6));
31 };
29 } 32 }
30 33
31 void testInvalid() { 34 void testInvalid() {
32 var decoder = _StringDecoders.decoder(Encoding.UTF_8); 35 void invalid(var bytes) {
33 Expect.throws(() => decoder.write([0x80])); 36 ListInputStream lis = new ListInputStream();
34 Expect.throws(() => decoder.write([0xff])); 37 lis.write(bytes);
35 Expect.throws(() => decoder.write([0xf0, 0xc0])); 38 lis.markEndOfStream();
39 var sis = new StringInputStream(lis);
40 sis.onData = () { throw "onData not expected"; };
41 sis.onError = (e) { Expect.isTrue(e is DecoderException); };
42 sis.onClosed = () { throw "onClosed not expected"; };
43 }
44
45 invalid([0x80]);
46 invalid([0xff]);
47 invalid([0xf0, 0xc0]);
36 } 48 }
37 49
38 void main() { 50 void main() {
39 test(); 51 test();
40 testInvalid(); 52 testInvalid();
41 } 53 }
OLDNEW
« no previous file with comments | « sdk/lib/io/string_stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698