| OLD | NEW |
| (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 } |
| OLD | NEW |