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

Unified 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/io/string_stream.dart ('K') | « sdk/lib/io/string_stream.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/string_decoder_test.dart
diff --git a/tests/standalone/io/string_decoder_test.dart b/tests/standalone/io/string_decoder_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d79bf8d7bf365dce538e7ee7be59518b06e5103b
--- /dev/null
+++ b/tests/standalone/io/string_decoder_test.dart
@@ -0,0 +1,41 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part '../../../sdk/lib/io/buffer_list.dart';
+part '../../../sdk/lib/io/input_stream.dart';
+part '../../../sdk/lib/io/string_stream.dart';
+
+void test() {
+ // Code point U+10FFFF is the largest code point supported by Dart.
+ var decoder = _StringDecoders.decoder(Encoding.UTF_8);
+ decoder.write([0xf0, 0x90, 0x80, 0x80]); // U+10000
+ decoder.write([0xf4, 0x8f, 0xbf, 0xbf]); // U+10FFFF
+ decoder.write([0xf4, 0x90, 0x80, 0x80]); // U+110000
+ decoder.write([0xfa, 0x80, 0x80, 0x80, 0x80]); // U+2000000
+ decoder.write([0xfd, 0x80, 0x80, 0x80, 0x80, 0x80]); // U+40000000
+
+ var decoded = decoder.decoded();
+ Expect.equals(7, decoded.length);
+
+ var replacementChar = '?'.charCodeAt(0);
+ Expect.equals(0xd800, decoded.charCodeAt(0));
+ Expect.equals(0xdc00, decoded.charCodeAt(1));
+ Expect.equals(0xdbff, decoded.charCodeAt(2));
+ Expect.equals(0xdfff, decoded.charCodeAt(3));
+ Expect.equals(replacementChar, decoded.charCodeAt(4));
+ Expect.equals(replacementChar, decoded.charCodeAt(5));
+ Expect.equals(replacementChar, decoded.charCodeAt(6));
+}
+
+void testInvalid() {
+ var decoder = _StringDecoders.decoder(Encoding.UTF_8);
+ Expect.throws(() => decoder.write([0x80]));
+ Expect.throws(() => decoder.write([0xff]));
+ Expect.throws(() => decoder.write([0xf0, 0xc0]));
+}
+
+void main() {
+ test();
+ testInvalid();
+}
« 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