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

Unified Diff: utils/tests/string_encoding/Utf8Tests.dart

Issue 9233041: String encoding utility methods and tests for Unicode, UTF-8, -16 and -32. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates from initial review. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: utils/tests/string_encoding/Utf8Tests.dart
diff --git a/utils/tests/string_encoding/Utf8Tests.dart b/utils/tests/string_encoding/Utf8Tests.dart
new file mode 100755
index 0000000000000000000000000000000000000000..2baeefd26b32ddfd8c859413954bebe9b4772748
--- /dev/null
+++ b/utils/tests/string_encoding/Utf8Tests.dart
@@ -0,0 +1,480 @@
+#!/usr/bin/env dart
+// Copyright (c) 2011, 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.
+
+#library("Utf8Tests");
+#import("DUnit.dart");
+#import("../../string_encoding/Unicode.dart");
+#import("../../string_encoding/UnicodeCore.dart");
+#source("../../string_encoding/Utf8_impl.dart");
+
+void main() {
+ TestSuite suite = new TestSuite();
+ suite.registerTestClass(new Utf8Tests());
+ suite.run();
+}
+
+class Utf8Tests extends TestClass {
+ void registerTests(TestSuite suite) {
+ register("testUtf8bytesToCodepoints", testUtf8bytesToCodepoints, suite);
+ register("testUtf8BytesToString", testUtf8BytesToString, suite);
+ register("testEncodeToUtf8", testEncodeToUtf8, suite);
+ }
+
+ void testEncodeToUtf8() {
+ Expect.listEquals([
+ 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63,
+ 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20,
+ 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70,
+ 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74,
+ 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20,
+ 0x64, 0x6f, 0x67, 0x2e],
+ encodeAsUtf8("The quick brown fox jumps over the lazy dog."),
+ "english to utf8");
+
+ Expect.listEquals([
+ 0x51, 0x75, 0x69, 0x7a, 0x64, 0x65, 0x6c, 0x74,
+ 0x61, 0x67, 0x65, 0x72, 0x6e, 0x65, 0x20, 0x73,
+ 0x70, 0x69, 0x73, 0x74, 0x65, 0x20, 0x6a, 0x6f,
+ 0x72, 0x64, 0x62, 0xc3, 0xa6, 0x72, 0x20, 0x6d,
+ 0x65, 0x64, 0x20, 0x66, 0x6c, 0xc3, 0xb8, 0x64,
+ 0x65, 0x20, 0x6d, 0x65, 0x6e, 0x73, 0x20, 0x63,
+ 0x69, 0x72, 0x6b, 0x75, 0x73, 0x6b, 0x6c, 0x6f,
+ 0x76, 0x6e, 0x65, 0x6e, 0x20, 0x57, 0x6f, 0x6c,
+ 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x70, 0x69,
+ 0x6c, 0x6c, 0x65, 0x64, 0x65, 0x20, 0x70, 0xc3,
+ 0xa5, 0x20, 0x78, 0x79, 0x6c, 0x6f, 0x66, 0x6f,
+ 0x6e, 0x2e],
+ encodeAsUtf8("Quizdeltagerne spiste jordbær med fløde mens " +
+ "cirkusklovnen Wolther spillede på xylofon."),
+ "encode danish to utf8");
+
+
+ Expect.listEquals([
+ 0x3f, 0x20, 0xd7, 0x93, 0xd7, 0x92, 0x20, 0xd7,
+ 0xa1, 0xd7, 0xa7, 0xd7, 0xa8, 0xd7, 0x9f, 0x20,
+ 0xd7, 0xa9, 0xd7, 0x98, 0x20, 0xd7, 0x91, 0xd7,
+ 0x99, 0xd7, 0x9d, 0x20, 0xd7, 0x9e, 0xd7, 0x90,
+ 0xd7, 0x95, 0xd7, 0x9b, 0xd7, 0x96, 0xd7, 0x91,
+ 0x20, 0xd7, 0x95, 0xd7, 0x9c, 0xd7, 0xa4, 0xd7,
+ 0xaa, 0xd7, 0xa2, 0x20, 0xd7, 0x9e, 0xd7, 0xa6,
+ 0xd7, 0x90, 0x20, 0xd7, 0x9c, 0xd7, 0x95, 0x20,
+ 0xd7, 0x97, 0xd7, 0x91, 0xd7, 0xa8, 0xd7, 0x94,
+ 0x20, 0xd7, 0x90, 0xd7, 0x99, 0xd7, 0x9a, 0x20,
+ 0xd7, 0x94, 0xd7, 0xa7, 0xd7, 0x9c, 0xd7, 0x99],
+ encodeAsUtf8("? דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקלי"),
+ "Hebrew to utf8");
+
+ Expect.listEquals([
+ 0xd0, 0xa1, 0xd1, 0x8a, 0xd0, 0xb5, 0xd1, 0x88,
+ 0xd1, 0x8c, 0x20, 0xd0, 0xb6, 0xd0, 0xb5, 0x20,
+ 0xd0, 0xb5, 0xd1, 0x89, 0xd1, 0x91, 0x20, 0xd1,
+ 0x8d, 0xd1, 0x82, 0xd0, 0xb8, 0xd1, 0x85, 0x20,
+ 0xd0, 0xbc, 0xd1, 0x8f, 0xd0, 0xb3, 0xd0, 0xba,
+ 0xd0, 0xb8, 0xd1, 0x85, 0x20, 0xd1, 0x84, 0xd1,
+ 0x80, 0xd0, 0xb0, 0xd0, 0xbd, 0xd1, 0x86, 0xd1,
+ 0x83, 0xd0, 0xb7, 0xd1, 0x81, 0xd0, 0xba, 0xd0,
+ 0xb8, 0xd1, 0x85, 0x20, 0xd0, 0xb1, 0xd1, 0x83,
+ 0xd0, 0xbb, 0xd0, 0xbe, 0xd0, 0xba, 0x20, 0xd0,
+ 0xb4, 0xd0, 0xb0, 0x20, 0xd0, 0xb2, 0xd1, 0x8b,
+ 0xd0, 0xbf, 0xd0, 0xb5, 0xd0, 0xb9, 0x20, 0xd1,
+ 0x87, 0xd0, 0xb0, 0xd1, 0x8e],
+ encodeAsUtf8("Съешь же ещё этих мягких французских булок да выпей" +
+ " чаю"), "Russian #2 to utf8");
+
+ Expect.listEquals([
+ 0xce, 0x93, 0xce, 0xb1, 0xce, 0xb6, 0xce, 0xad,
+ 0xce, 0xb5, 0xcf, 0x82, 0x20, 0xce, 0xba, 0xce,
+ 0xb1, 0xe1, 0xbd, 0xb6, 0x20, 0xce, 0xbc, 0xcf,
+ 0x85, 0xcf, 0x81, 0xcf, 0x84, 0xce, 0xb9, 0xe1,
+ 0xbd, 0xb2, 0xcf, 0x82, 0x20, 0xce, 0xb4, 0xe1,
+ 0xbd, 0xb2, 0xce, 0xbd, 0x20, 0xce, 0xb8, 0xe1,
+ 0xbd, 0xb0, 0x20, 0xce, 0xb2, 0xcf, 0x81, 0xe1,
+ 0xbf, 0xb6, 0x20, 0xcf, 0x80, 0xce, 0xb9, 0xe1,
+ 0xbd, 0xb0, 0x20, 0xcf, 0x83, 0xcf, 0x84, 0xe1,
+ 0xbd, 0xb8, 0x20, 0xcf, 0x87, 0xcf, 0x81, 0xcf,
+ 0x85, 0xcf, 0x83, 0xce, 0xb1, 0xcf, 0x86, 0xe1,
+ 0xbd, 0xb6, 0x20, 0xce, 0xbe, 0xce, 0xad, 0xcf,
+ 0x86, 0xcf, 0x89, 0xcf, 0x84, 0xce, 0xbf],
+ encodeAsUtf8("Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο"),
+ "Greek to utf8");
+
+ Expect.listEquals([
+ 0xe3, 0x82, 0xa4, 0xe3, 0x83, 0xad, 0xe3, 0x83,
+ 0x8f, 0xe3, 0x83, 0x8b, 0xe3, 0x83, 0x9b, 0xe3,
+ 0x83, 0x98, 0xe3, 0x83, 0x88, 0x20, 0xe3, 0x83,
+ 0x81, 0xe3, 0x83, 0xaa, 0xe3, 0x83, 0x8c, 0xe3,
+ 0x83, 0xab, 0xe3, 0x83, 0xb2, 0x20, 0xe3, 0x83,
+ 0xaf, 0xe3, 0x82, 0xab, 0xe3, 0x83, 0xa8, 0xe3,
+ 0x82, 0xbf, 0xe3, 0x83, 0xac, 0xe3, 0x82, 0xbd,
+ 0x20, 0xe3, 0x83, 0x84, 0xe3, 0x83, 0x8d, 0xe3,
+ 0x83, 0x8a, 0xe3, 0x83, 0xa9, 0xe3, 0x83, 0xa0,
+ 0x0a, 0xe3, 0x82, 0xa6, 0xe3, 0x83, 0xb0, 0xe3,
+ 0x83, 0x8e, 0xe3, 0x82, 0xaa, 0xe3, 0x82, 0xaf,
+ 0xe3, 0x83, 0xa4, 0xe3, 0x83, 0x9e, 0x20, 0xe3,
+ 0x82, 0xb1, 0xe3, 0x83, 0x95, 0xe3, 0x82, 0xb3,
+ 0xe3, 0x82, 0xa8, 0xe3, 0x83, 0x86, 0x20, 0xe3,
+ 0x82, 0xa2, 0xe3, 0x82, 0xb5, 0xe3, 0x82, 0xad,
+ 0xe3, 0x83, 0xa6, 0xe3, 0x83, 0xa1, 0xe3, 0x83,
+ 0x9f, 0xe3, 0x82, 0xb7, 0x20, 0xe3, 0x83, 0xb1,
+ 0xe3, 0x83, 0x92, 0xe3, 0x83, 0xa2, 0xe3, 0x82,
+ 0xbb, 0xe3, 0x82, 0xb9, 0xe3, 0x83, 0xb3],
+ encodeAsUtf8( """
+イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム
+ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"""),
+ "Katakana");
+ }
+
+ void testUtf8bytesToCodepoints() {
+ Expect.listEquals([954, 972, 963, 956, 949],
+ _utf8ToCodepoints([0xce, 0xba, 0xcf, 0x8c, 0xcf,
+ 0x83, 0xce, 0xbc, 0xce, 0xb5]), "κόσμε");
+
+ // boundary conditions: First possible sequence of a certain length
+ Expect.listEquals([0x0], _utf8ToCodepoints([0x0]), "0");
+ Expect.listEquals([0x80], _utf8ToCodepoints([0xc2, 0x80]), "80");
+ Expect.listEquals([0x800],
+ _utf8ToCodepoints([0xe0, 0xa0, 0x80]), "800");
+ Expect.listEquals([0x10000],
+ _utf8ToCodepoints([0xf0, 0x90, 0x80, 0x80]), "10000");
+ Expect.listEquals([0x200000],
+ _utf8ToCodepoints([0xf8, 0x88, 0x80, 0x80, 0x80]), "200000");
+ Expect.listEquals([0x4000000],
+ _utf8ToCodepoints([0xfc, 0x84, 0x80, 0x80, 0x80, 0x80]),
+ "4000000");
+
+ // boundary conditions: Last possible sequence of a certain length
+ Expect.listEquals([0x7f], _utf8ToCodepoints([0x7f]), "7f");
+ Expect.listEquals([0x7ff], _utf8ToCodepoints([0xdf, 0xbf]), "7ff");
+ Expect.listEquals([0xffff],
+ _utf8ToCodepoints([0xef, 0xbf, 0xbf]), "ffff");
+ Expect.listEquals([0x1fffff],
+ _utf8ToCodepoints([0xf7, 0xbf, 0xbf, 0xbf]), "1fffff");
+ Expect.listEquals([0x3ffffff],
+ _utf8ToCodepoints([0xfb, 0xbf, 0xbf, 0xbf, 0xbf]), "3ffffff");
+ Expect.listEquals([0x7fffffff],
+ _utf8ToCodepoints([0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf]),
+ "4000000");
+
+ // other boundary conditions
+ Expect.listEquals([0xd7ff],
+ _utf8ToCodepoints([0xed, 0x9f, 0xbf]), "d7ff");
+ Expect.listEquals([0xe000],
+ _utf8ToCodepoints([0xee, 0x80, 0x80]), "e000");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xef, 0xbf, 0xbd]), "fffd");
+ Expect.listEquals([0x10ffff],
+ _utf8ToCodepoints([0xf4, 0x8f, 0xbf, 0xbf]), "10ffff");
+ Expect.listEquals([0x110000],
+ _utf8ToCodepoints([0xf4, 0x90, 0x80, 0x80]), "110000");
+
+ // unexpected continuation bytes
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0x80]), "80 => replacement character");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xbf]), "bf => replacement character");
+
+ List<int> allContinuationBytes = <int>[];
+ List<int> matchingReplacementChars = <int>[];
+ for (int i = 0x80; i < 0xc0; i++) {
+ allContinuationBytes.add(i);
+ matchingReplacementChars.add(0xfffd);
+ }
+ Expect.listEquals(matchingReplacementChars,
+ _utf8ToCodepoints(allContinuationBytes),
+ "80 - bf => replacement character x 64");
+
+ List<int> allFirstTwoByteSeq = <int>[];
+ matchingReplacementChars = <int>[];
+ for (int i = 0xc0; i < 0xe0; i++) {
+ allFirstTwoByteSeq.addAll([i, 0x20]);
+ matchingReplacementChars.addAll([0xfffd]);
+ }
+ Expect.listEquals(matchingReplacementChars,
+ _utf8ToCodepoints(allFirstTwoByteSeq),
+ "c0 - df + space => replacement character + space x 32");
+
+ List<int> allFirstThreeByteSeq = <int>[];
+ matchingReplacementChars = <int>[];
+ for (int i = 0xe0; i < 0xf0; i++) {
+ allFirstThreeByteSeq.addAll([i, 0x20]);
+ matchingReplacementChars.addAll([0xfffd]);
+ }
+ Expect.listEquals(matchingReplacementChars,
+ _utf8ToCodepoints(allFirstThreeByteSeq),
+ "e0 - ef + space => replacement character x 16");
+
+ List<int> allFirstFourByteSeq = <int>[];
+ matchingReplacementChars = <int>[];
+ for (int i = 0xf0; i < 0xf8; i++) {
+ allFirstFourByteSeq.addAll([i, 0x20]);
+ matchingReplacementChars.addAll([0xfffd]);
+ }
+ Expect.listEquals(matchingReplacementChars,
+ _utf8ToCodepoints(allFirstFourByteSeq),
+ "f0 - f7 + space => replacement character x 8");
+
+ List<int> allFirstFiveByteSeq = <int>[];
+ matchingReplacementChars = <int>[];
+ for (int i = 0xf8; i < 0xfc; i++) {
+ allFirstFiveByteSeq.addAll([i, 0x20]);
+ matchingReplacementChars.addAll([0xfffd]);
+ }
+ Expect.listEquals(matchingReplacementChars,
+ _utf8ToCodepoints(allFirstFiveByteSeq),
+ "f8 - fb + space => replacement character x 4");
+
+ List<int> allFirstSixByteSeq = <int>[];
+ matchingReplacementChars = <int>[];
+ for (int i = 0xfc; i < 0xfe; i++) {
+ allFirstSixByteSeq.addAll([i, 0x20]);
+ matchingReplacementChars.addAll([0xfffd]);
+ }
+ Expect.listEquals(matchingReplacementChars,
+ _utf8ToCodepoints(allFirstSixByteSeq),
+ "fc - fd + space => replacement character x 2");
+
+ // Sequences with last continuation byte missing
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xc2]),
+ "2-byte sequence with last byte missing");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xe0, 0x80]),
+ "3-byte sequence with last byte missing");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xf0, 0x80, 0x80]),
+ "4-byte sequence with last byte missing");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xf8, 0x88, 0x80, 0x80]),
+ "5-byte sequence with last byte missing");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80]),
+ "6-byte sequence with last byte missing");
+
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xdf]),
+ "2-byte sequence with last byte missing (hi)");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xef, 0xbf]),
+ "3-byte sequence with last byte missing (hi)");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xf7, 0xbf, 0xbf]),
+ "4-byte sequence with last byte missing (hi)");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xfb, 0xbf, 0xbf, 0xbf]),
+ "5-byte sequence with last byte missing (hi)");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xfd, 0xbf, 0xbf, 0xbf, 0xbf]),
+ "6-byte sequence with last byte missing (hi)");
+
+ // Concatenation of incomplete sequences
+ Expect.listEquals(
+ [ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd ],
+ _utf8ToCodepoints(
+ [ 0xc2,
+ 0xe0, 0x80,
+ 0xf0, 0x80, 0x80,
+ 0xf8, 0x88, 0x80, 0x80,
+ 0xfc, 0x80, 0x80, 0x80, 0x80,
+ 0xdf,
+ 0xef, 0xbf,
+ 0xf7, 0xbf, 0xbf,
+ 0xfb, 0xbf, 0xbf, 0xbf,
+ 0xfd, 0xbf, 0xbf, 0xbf, 0xbf ]),
+ "Concatenation of incomplete sequences");
+
+ // Impossible bytes
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xfe]), "fe");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xff]), "ff");
+ Expect.listEquals([0xfffd, 0xfffd, 0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xfe, 0xfe, 0xff, 0xff]), "fe fe ff ff");
+
+ // Overlong sequences
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xc0, 0xaf]),
+ "c0 af");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xe0, 0x80, 0xaf]),
+ "e0 80 af");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xf0, 0x80, 0x80, 0xaf]),
+ "f0 80 80 af");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xf8, 0x80, 0x80, 0x80, 0xaf]),
+ "f8 80 80 80 af");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80, 0xaf]),
+ "fc 80 80 80 80 af");
+
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xc1, 0xbf]),
+ "c1 bf");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xe0, 0x9f, 0xbf]),
+ "e0 9f bf");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xf0, 0x8f, 0xbf, 0xbf]),
+ "f0 8f bf bf");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xf8, 0x87, 0xbf, 0xbf, 0xbf]),
+ "f8 87 bf bf bf");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xfc, 0x83, 0xbf, 0xbf, 0xbf, 0xbf]),
+ "fc 83 bf bf bf bf");
+
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xc0, 0x80]),
+ "c0 80");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xe0, 0x80, 0x80]),
+ "e0 80 80");
+ Expect.listEquals([0xfffd], _utf8ToCodepoints([0xf0, 0x80, 0x80, 0x80]),
+ "f0 80 80 80");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xf8, 0x80, 0x80, 0x80, 0x80]),
+ "f8 80 80 80 80");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80, 0x80]),
+ "fc 80 80 80 80 80");
+
+ // Illegal code positions
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xa0, 0x80]), "U+D800");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xad, 0xbf]), "U+DB7F");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xae, 0x80]), "U+DB80");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xaf, 0xbf]), "U+DBFF");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xb0, 0x80]), "U+DC00");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xbe, 0x80]), "U+DF80");
+ Expect.listEquals([0xfffd],
+ _utf8ToCodepoints([0xed, 0xbf, 0xbf]), "U+DFFF");
+
+ // Paired UTF-16 surrogates
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80]),
+ "U+D800 U+DC00");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xa0, 0x80, 0xed, 0xbf, 0xbf]),
+ "U+D800 U+DFFF");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xad, 0xbf, 0xed, 0xb0, 0x80]),
+ "U+DB7F U+DC00");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xad, 0xbf, 0xed, 0xbf, 0xbf]),
+ "U+DB7F U+DFFF");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xae, 0x80, 0xed, 0xb0, 0x80]),
+ "U+DB80 U+DC00");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xae, 0x80, 0xed, 0xbf, 0xbf]),
+ "U+DB80 U+DFFF");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xaf, 0xbf, 0xed, 0xb0, 0x80]),
+ "U+DBFF U+DC00");
+ Expect.listEquals([0xfffd, 0xfffd],
+ _utf8ToCodepoints([0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf]),
+ "U+DBFF U+DFFF");
+
+ // Other illegal code positions (???)
+ Expect.listEquals([0xfffe], _utf8ToCodepoints([0xef, 0xbf, 0xbe]),
+ "U+FFFE");
+ Expect.listEquals([0xffff], _utf8ToCodepoints([0xef, 0xbf, 0xbf]),
+ "U+FFFF");
+ }
+
+ void testUtf8BytesToString() {
+
+ Expect.stringEquals("The quick brown fox jumps over the lazy dog.",
+ decodeFromUtf8([
+ 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63,
+ 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20,
+ 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70,
+ 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74,
+ 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20,
+ 0x64, 0x6f, 0x67, 0x2e]), "English");
+
+ Expect.stringEquals("Quizdeltagerne spiste jordbær med fløde mens " +
+ "cirkusklovnen Wolther spillede på xylofon.",
+ decodeFromUtf8([
+ 0x51, 0x75, 0x69, 0x7a, 0x64, 0x65, 0x6c, 0x74,
+ 0x61, 0x67, 0x65, 0x72, 0x6e, 0x65, 0x20, 0x73,
+ 0x70, 0x69, 0x73, 0x74, 0x65, 0x20, 0x6a, 0x6f,
+ 0x72, 0x64, 0x62, 0xc3, 0xa6, 0x72, 0x20, 0x6d,
+ 0x65, 0x64, 0x20, 0x66, 0x6c, 0xc3, 0xb8, 0x64,
+ 0x65, 0x20, 0x6d, 0x65, 0x6e, 0x73, 0x20, 0x63,
+ 0x69, 0x72, 0x6b, 0x75, 0x73, 0x6b, 0x6c, 0x6f,
+ 0x76, 0x6e, 0x65, 0x6e, 0x20, 0x57, 0x6f, 0x6c,
+ 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x70, 0x69,
+ 0x6c, 0x6c, 0x65, 0x64, 0x65, 0x20, 0x70, 0xc3,
+ 0xa5, 0x20, 0x78, 0x79, 0x6c, 0x6f, 0x66, 0x6f,
+ 0x6e, 0x2e]), "Danish");
+
+ Expect.stringEquals("? דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקלי",
Dan Rice 2012/01/31 16:01:10 הקליטה
dcarlson 2012/01/31 22:11:38 Done.
+ decodeFromUtf8([
+ 0x3f, 0x20, 0xd7, 0x93, 0xd7, 0x92, 0x20, 0xd7,
+ 0xa1, 0xd7, 0xa7, 0xd7, 0xa8, 0xd7, 0x9f, 0x20,
+ 0xd7, 0xa9, 0xd7, 0x98, 0x20, 0xd7, 0x91, 0xd7,
+ 0x99, 0xd7, 0x9d, 0x20, 0xd7, 0x9e, 0xd7, 0x90,
+ 0xd7, 0x95, 0xd7, 0x9b, 0xd7, 0x96, 0xd7, 0x91,
+ 0x20, 0xd7, 0x95, 0xd7, 0x9c, 0xd7, 0xa4, 0xd7,
+ 0xaa, 0xd7, 0xa2, 0x20, 0xd7, 0x9e, 0xd7, 0xa6,
+ 0xd7, 0x90, 0x20, 0xd7, 0x9c, 0xd7, 0x95, 0x20,
+ 0xd7, 0x97, 0xd7, 0x91, 0xd7, 0xa8, 0xd7, 0x94,
+ 0x20, 0xd7, 0x90, 0xd7, 0x99, 0xd7, 0x9a, 0x20,
+ 0xd7, 0x94, 0xd7, 0xa7, 0xd7, 0x9c, 0xd7, 0x99]), "Hebrew");
+
+ Expect.stringEquals("Съешь же ещё этих мягких французских булок да выпей " +
+ "чаю",
+ decodeFromUtf8([
+ 0xd0, 0xa1, 0xd1, 0x8a, 0xd0 ,0xb5, 0xd1, 0x88,
+ 0xd1, 0x8c, 0x20, 0xd0, 0xb6, 0xd0, 0xb5, 0x20,
+ 0xd0, 0xb5, 0xd1, 0x89, 0xd1, 0x91, 0x20, 0xd1,
+ 0x8d, 0xd1, 0x82, 0xd0, 0xb8, 0xd1, 0x85, 0x20,
+ 0xd0, 0xbc, 0xd1, 0x8f, 0xd0, 0xb3, 0xd0, 0xba,
+ 0xd0, 0xb8, 0xd1, 0x85, 0x20, 0xd1, 0x84, 0xd1,
+ 0x80, 0xd0, 0xb0, 0xd0, 0xbd, 0xd1, 0x86, 0xd1,
+ 0x83, 0xd0, 0xb7, 0xd1, 0x81, 0xd0, 0xba, 0xd0,
+ 0xb8, 0xd1, 0x85, 0x20, 0xd0, 0xb1, 0xd1, 0x83,
+ 0xd0, 0xbb, 0xd0, 0xbe, 0xd0, 0xba, 0x20, 0xd0,
+ 0xb4, 0xd0, 0xb0, 0x20, 0xd0, 0xb2, 0xd1, 0x8b,
+ 0xd0, 0xbf, 0xd0, 0xb5, 0xd0, 0xb9, 0x20, 0xd1,
+ 0x87, 0xd0, 0xb0, 0xd1, 0x8e]), "Russian #2");
+
+ Expect.stringEquals("Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο",
+ decodeFromUtf8([
+ 0xce, 0x93, 0xce, 0xb1, 0xce, 0xb6, 0xce, 0xad,
+ 0xce, 0xb5, 0xcf, 0x82, 0x20, 0xce, 0xba, 0xce,
+ 0xb1, 0xe1, 0xbd, 0xb6, 0x20, 0xce, 0xbc, 0xcf,
+ 0x85, 0xcf, 0x81, 0xcf, 0x84, 0xce, 0xb9, 0xe1,
+ 0xbd, 0xb2, 0xcf, 0x82, 0x20, 0xce, 0xb4, 0xe1,
+ 0xbd, 0xb2, 0xce, 0xbd, 0x20, 0xce, 0xb8, 0xe1,
+ 0xbd, 0xb0, 0x20, 0xce, 0xb2, 0xcf, 0x81, 0xe1,
+ 0xbf, 0xb6, 0x20, 0xcf, 0x80, 0xce, 0xb9, 0xe1,
+ 0xbd, 0xb0, 0x20, 0xcf, 0x83, 0xcf, 0x84, 0xe1,
+ 0xbd, 0xb8, 0x20, 0xcf, 0x87, 0xcf, 0x81, 0xcf,
+ 0x85, 0xcf, 0x83, 0xce, 0xb1, 0xcf, 0x86, 0xe1,
+ 0xbd, 0xb6, 0x20, 0xce, 0xbe, 0xce, 0xad, 0xcf,
+ 0x86, 0xcf, 0x89, 0xcf, 0x84, 0xce, 0xbf]), "Greek");
+ Expect.stringEquals("""
+イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム
+ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン""",
+ decodeFromUtf8([
+ 0xe3, 0x82, 0xa4, 0xe3, 0x83, 0xad, 0xe3, 0x83,
+ 0x8f, 0xe3, 0x83, 0x8b, 0xe3, 0x83, 0x9b, 0xe3,
+ 0x83, 0x98, 0xe3, 0x83, 0x88, 0x20, 0xe3, 0x83,
+ 0x81, 0xe3, 0x83, 0xaa, 0xe3, 0x83, 0x8c, 0xe3,
+ 0x83, 0xab, 0xe3, 0x83, 0xb2, 0x20, 0xe3, 0x83,
+ 0xaf, 0xe3, 0x82, 0xab, 0xe3, 0x83, 0xa8, 0xe3,
+ 0x82, 0xbf, 0xe3, 0x83, 0xac, 0xe3, 0x82, 0xbd,
+ 0x20, 0xe3, 0x83, 0x84, 0xe3, 0x83, 0x8d, 0xe3,
+ 0x83, 0x8a, 0xe3, 0x83, 0xa9, 0xe3, 0x83, 0xa0,
+ 0x0a, 0xe3, 0x82, 0xa6, 0xe3, 0x83, 0xb0, 0xe3,
+ 0x83, 0x8e, 0xe3, 0x82, 0xaa, 0xe3, 0x82, 0xaf,
+ 0xe3, 0x83, 0xa4, 0xe3, 0x83, 0x9e, 0x20, 0xe3,
+ 0x82, 0xb1, 0xe3, 0x83, 0x95, 0xe3, 0x82, 0xb3,
+ 0xe3, 0x82, 0xa8, 0xe3, 0x83, 0x86, 0x20, 0xe3,
+ 0x82, 0xa2, 0xe3, 0x82, 0xb5, 0xe3, 0x82, 0xad,
+ 0xe3, 0x83, 0xa6, 0xe3, 0x83, 0xa1, 0xe3, 0x83,
+ 0x9f, 0xe3, 0x82, 0xb7, 0x20, 0xe3, 0x83, 0xb1,
+ 0xe3, 0x83, 0x92, 0xe3, 0x83, 0xa2, 0xe3, 0x82,
+ 0xbb, 0xe3, 0x82, 0xb9, 0xe3, 0x83, 0xb3]), "Katakana");
+ }
+}
« utils/string_encoding/Utf8_impl.dart ('K') | « utils/tests/string_encoding/Utf32Tests.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698