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

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

Issue 17573010: Add a static method decode to StringDecoder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "dart:async"; 6 import "dart:async";
7 import "dart:io"; 7 import "dart:io";
8 8
9 void test() { 9 void testTransform() {
10 // Code point U+10FFFF is the largest code point supported by Dart. 10 // Code point U+10FFFF is the largest code point supported by Dart.
11 var controller = new StreamController(sync: true); 11 var controller = new StreamController(sync: true);
12 controller.add([0xf0, 0x90, 0x80, 0x80]); // U+10000 12 controller.add([0xf0, 0x90, 0x80, 0x80]); // U+10000
13 controller.add([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF 13 controller.add([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
14 controller.add([0xf4, 0x90, 0x80, 0x80]); // U+110000 14 controller.add([0xf4, 0x90, 0x80, 0x80]); // U+110000
15 controller.add([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000 15 controller.add([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
16 controller.add([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000 16 controller.add([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
17 controller.close(); 17 controller.close();
18 18
19 var decoder = new StringDecoder(Encoding.UTF_8, '?'.codeUnitAt(0)); 19 var decoder = new StringDecoder(Encoding.UTF_8, '?'.codeUnitAt(0));
(...skipping 13 matching lines...) Expand all
33 Expect.equals(0xdc00, decoded.codeUnitAt(1)); 33 Expect.equals(0xdc00, decoded.codeUnitAt(1));
34 Expect.equals(0xdbff, decoded.codeUnitAt(2)); 34 Expect.equals(0xdbff, decoded.codeUnitAt(2));
35 Expect.equals(0xdfff, decoded.codeUnitAt(3)); 35 Expect.equals(0xdfff, decoded.codeUnitAt(3));
36 Expect.equals(replacementChar, decoded.codeUnitAt(4)); 36 Expect.equals(replacementChar, decoded.codeUnitAt(4));
37 Expect.equals(replacementChar, decoded.codeUnitAt(5)); 37 Expect.equals(replacementChar, decoded.codeUnitAt(5));
38 Expect.equals(replacementChar, decoded.codeUnitAt(6)); 38 Expect.equals(replacementChar, decoded.codeUnitAt(6));
39 Expect.equals(replacementChar, decoded.codeUnitAt(7)); 39 Expect.equals(replacementChar, decoded.codeUnitAt(7));
40 }); 40 });
41 } 41 }
42 42
43 void testDecode() {
44 // Code point U+10FFFF is the largest code point supported by Dart.
45 var controller = new StreamController(sync: true);
46 controller.add([0xf0, 0x90, 0x80, 0x80]); // U+10000
47 controller.add([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
48 controller.add([0xf4, 0x90, 0x80, 0x80]); // U+110000
49 controller.add([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
50 controller.add([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
51 controller.close();
52
53 StringDecoder.decode(controller.stream,
54 Encoding.UTF_8,
55 '?'.codeUnitAt(0)).then((decoded) {
56 Expect.equals(8, decoded.length);
57
58 var replacementChar = '?'.codeUnitAt(0);
59 Expect.equals(0xd800, decoded.codeUnitAt(0));
60 Expect.equals(0xdc00, decoded.codeUnitAt(1));
61 Expect.equals(0xdbff, decoded.codeUnitAt(2));
62 Expect.equals(0xdfff, decoded.codeUnitAt(3));
63 Expect.equals(replacementChar, decoded.codeUnitAt(4));
64 Expect.equals(replacementChar, decoded.codeUnitAt(5));
65 Expect.equals(replacementChar, decoded.codeUnitAt(6));
66 Expect.equals(replacementChar, decoded.codeUnitAt(7));
67 });
68 }
69
43 void testInvalid() { 70 void testInvalid() {
44 void invalid(var bytes, var outputLength) { 71 void invalid(var bytes, var outputLength) {
45 var controller = new StreamController(sync: true); 72 var controller = new StreamController(sync: true);
46 controller.add(bytes); 73 controller.add(bytes);
47 controller.close(); 74 controller.close();
48 controller.stream.transform(new StringDecoder()).listen((string) { 75 controller.stream.transform(new StringDecoder()).listen((string) {
49 Expect.equals(outputLength, string.length); 76 Expect.equals(outputLength, string.length);
50 for (var i = 0; i < outputLength; i++) { 77 for (var i = 0; i < outputLength; i++) {
51 Expect.equals(0xFFFD, string.codeUnitAt(i)); 78 Expect.equals(0xFFFD, string.codeUnitAt(i));
52 } 79 }
53 }); 80 });
54 } 81 }
55 82
56 invalid([0x80], 1); 83 invalid([0x80], 1);
57 invalid([0xff], 1); 84 invalid([0xff], 1);
58 invalid([0xf0, 0xc0], 1); 85 invalid([0xf0, 0xc0], 1);
59 invalid([0xc0, 0x80], 1); 86 invalid([0xc0, 0x80], 1);
60 invalid([0xfd, 0x80, 0x80], 3); // Unfinished encoding. 87 invalid([0xfd, 0x80, 0x80], 3); // Unfinished encoding.
61 } 88 }
62 89
63 void main() { 90 void main() {
64 test(); 91 testTransform();
92 testDecode();
65 testInvalid(); 93 testInvalid();
66 } 94 }
OLDNEW
« sdk/lib/io/string_transformer.dart ('K') | « sdk/lib/io/string_transformer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698