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

Side by Side Diff: utils/tests/string_encoding/utf8_tests.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 to comments. Created 8 years, 10 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 | « utils/tests/string_encoding/utf32_tests.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
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file.
5
6 #library("utf8_tests");
7 #import("dunit.dart");
8 #import("../../string_encoding/unicode.dart");
9 #import("../../string_encoding/unicode_core.dart");
10 #source("../../string_encoding/utf8_impl.dart");
11
12 void main() {
13 TestSuite suite = new TestSuite();
14 suite.registerTestClass(new Utf8Tests());
15 suite.run();
16 }
17
18 class Utf8Tests extends TestClass {
19 static final String testEnglishPhrase =
20 "The quick brown fox jumps over the lazy dog.";
21
22 static final List<int> testEnglishUtf8 = const<int> [
23 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63,
24 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20,
25 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70,
26 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74,
27 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20,
28 0x64, 0x6f, 0x67, 0x2e];
29
30 static final String testDanishPhrase = "Quizdeltagerne spiste jordbær med " +
31 "fløde mens cirkusklovnen Wolther spillede på xylofon.";
32
33 static final List<int> testDanishUtf8 = const<int>[
34 0x51, 0x75, 0x69, 0x7a, 0x64, 0x65, 0x6c, 0x74,
35 0x61, 0x67, 0x65, 0x72, 0x6e, 0x65, 0x20, 0x73,
36 0x70, 0x69, 0x73, 0x74, 0x65, 0x20, 0x6a, 0x6f,
37 0x72, 0x64, 0x62, 0xc3, 0xa6, 0x72, 0x20, 0x6d,
38 0x65, 0x64, 0x20, 0x66, 0x6c, 0xc3, 0xb8, 0x64,
39 0x65, 0x20, 0x6d, 0x65, 0x6e, 0x73, 0x20, 0x63,
40 0x69, 0x72, 0x6b, 0x75, 0x73, 0x6b, 0x6c, 0x6f,
41 0x76, 0x6e, 0x65, 0x6e, 0x20, 0x57, 0x6f, 0x6c,
42 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x70, 0x69,
43 0x6c, 0x6c, 0x65, 0x64, 0x65, 0x20, 0x70, 0xc3,
44 0xa5, 0x20, 0x78, 0x79, 0x6c, 0x6f, 0x66, 0x6f,
45 0x6e, 0x2e];
46
47 // unusual formatting due to strange editor interaction w/ text direction.
48 static final String
49 testHebrewPhrase = "דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה";
50
51 static final List<int> testHebrewUtf8 = const<int>[
52 0xd7, 0x93, 0xd7, 0x92, 0x20, 0xd7, 0xa1, 0xd7,
53 0xa7, 0xd7, 0xa8, 0xd7, 0x9f, 0x20, 0xd7, 0xa9,
54 0xd7, 0x98, 0x20, 0xd7, 0x91, 0xd7, 0x99, 0xd7,
55 0x9d, 0x20, 0xd7, 0x9e, 0xd7, 0x90, 0xd7, 0x95,
56 0xd7, 0x9b, 0xd7, 0x96, 0xd7, 0x91, 0x20, 0xd7,
57 0x95, 0xd7, 0x9c, 0xd7, 0xa4, 0xd7, 0xaa, 0xd7,
58 0xa2, 0x20, 0xd7, 0x9e, 0xd7, 0xa6, 0xd7, 0x90,
59 0x20, 0xd7, 0x9c, 0xd7, 0x95, 0x20, 0xd7, 0x97,
60 0xd7, 0x91, 0xd7, 0xa8, 0xd7, 0x94, 0x20, 0xd7,
61 0x90, 0xd7, 0x99, 0xd7, 0x9a, 0x20, 0xd7, 0x94,
62 0xd7, 0xa7, 0xd7, 0x9c, 0xd7, 0x99, 0xd7, 0x98,
63 0xd7, 0x94];
64
65 static final String testRussianPhrase = "Съешь же ещё этих мягких " +
66 "французских булок да выпей чаю";
67
68 static final List<int> testRussianUtf8 = const<int>[
69 0xd0, 0xa1, 0xd1, 0x8a, 0xd0, 0xb5, 0xd1, 0x88,
70 0xd1, 0x8c, 0x20, 0xd0, 0xb6, 0xd0, 0xb5, 0x20,
71 0xd0, 0xb5, 0xd1, 0x89, 0xd1, 0x91, 0x20, 0xd1,
72 0x8d, 0xd1, 0x82, 0xd0, 0xb8, 0xd1, 0x85, 0x20,
73 0xd0, 0xbc, 0xd1, 0x8f, 0xd0, 0xb3, 0xd0, 0xba,
74 0xd0, 0xb8, 0xd1, 0x85, 0x20, 0xd1, 0x84, 0xd1,
75 0x80, 0xd0, 0xb0, 0xd0, 0xbd, 0xd1, 0x86, 0xd1,
76 0x83, 0xd0, 0xb7, 0xd1, 0x81, 0xd0, 0xba, 0xd0,
77 0xb8, 0xd1, 0x85, 0x20, 0xd0, 0xb1, 0xd1, 0x83,
78 0xd0, 0xbb, 0xd0, 0xbe, 0xd0, 0xba, 0x20, 0xd0,
79 0xb4, 0xd0, 0xb0, 0x20, 0xd0, 0xb2, 0xd1, 0x8b,
80 0xd0, 0xbf, 0xd0, 0xb5, 0xd0, 0xb9, 0x20, 0xd1,
81 0x87, 0xd0, 0xb0, 0xd1, 0x8e];
82
83 static final String testGreekPhrase = "Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ " +
84 "στὸ χρυσαφὶ ξέφωτο";
85
86 static final List<int> testGreekUtf8 = const<int>[
87 0xce, 0x93, 0xce, 0xb1, 0xce, 0xb6, 0xce, 0xad,
88 0xce, 0xb5, 0xcf, 0x82, 0x20, 0xce, 0xba, 0xce,
89 0xb1, 0xe1, 0xbd, 0xb6, 0x20, 0xce, 0xbc, 0xcf,
90 0x85, 0xcf, 0x81, 0xcf, 0x84, 0xce, 0xb9, 0xe1,
91 0xbd, 0xb2, 0xcf, 0x82, 0x20, 0xce, 0xb4, 0xe1,
92 0xbd, 0xb2, 0xce, 0xbd, 0x20, 0xce, 0xb8, 0xe1,
93 0xbd, 0xb0, 0x20, 0xce, 0xb2, 0xcf, 0x81, 0xe1,
94 0xbf, 0xb6, 0x20, 0xcf, 0x80, 0xce, 0xb9, 0xe1,
95 0xbd, 0xb0, 0x20, 0xcf, 0x83, 0xcf, 0x84, 0xe1,
96 0xbd, 0xb8, 0x20, 0xcf, 0x87, 0xcf, 0x81, 0xcf,
97 0x85, 0xcf, 0x83, 0xce, 0xb1, 0xcf, 0x86, 0xe1,
98 0xbd, 0xb6, 0x20, 0xce, 0xbe, 0xce, 0xad, 0xcf,
99 0x86, 0xcf, 0x89, 0xcf, 0x84, 0xce, 0xbf];
100
101 static final String testKatakanaPhrase = """
102 イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム
103 ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン""";
104
105 static final List<int> testKatakanaUtf8 = const<int>[
106 0xe3, 0x82, 0xa4, 0xe3, 0x83, 0xad, 0xe3, 0x83,
107 0x8f, 0xe3, 0x83, 0x8b, 0xe3, 0x83, 0x9b, 0xe3,
108 0x83, 0x98, 0xe3, 0x83, 0x88, 0x20, 0xe3, 0x83,
109 0x81, 0xe3, 0x83, 0xaa, 0xe3, 0x83, 0x8c, 0xe3,
110 0x83, 0xab, 0xe3, 0x83, 0xb2, 0x20, 0xe3, 0x83,
111 0xaf, 0xe3, 0x82, 0xab, 0xe3, 0x83, 0xa8, 0xe3,
112 0x82, 0xbf, 0xe3, 0x83, 0xac, 0xe3, 0x82, 0xbd,
113 0x20, 0xe3, 0x83, 0x84, 0xe3, 0x83, 0x8d, 0xe3,
114 0x83, 0x8a, 0xe3, 0x83, 0xa9, 0xe3, 0x83, 0xa0,
115 0x0a, 0xe3, 0x82, 0xa6, 0xe3, 0x83, 0xb0, 0xe3,
116 0x83, 0x8e, 0xe3, 0x82, 0xaa, 0xe3, 0x82, 0xaf,
117 0xe3, 0x83, 0xa4, 0xe3, 0x83, 0x9e, 0x20, 0xe3,
118 0x82, 0xb1, 0xe3, 0x83, 0x95, 0xe3, 0x82, 0xb3,
119 0xe3, 0x82, 0xa8, 0xe3, 0x83, 0x86, 0x20, 0xe3,
120 0x82, 0xa2, 0xe3, 0x82, 0xb5, 0xe3, 0x82, 0xad,
121 0xe3, 0x83, 0xa6, 0xe3, 0x83, 0xa1, 0xe3, 0x83,
122 0x9f, 0xe3, 0x82, 0xb7, 0x20, 0xe3, 0x83, 0xb1,
123 0xe3, 0x83, 0x92, 0xe3, 0x83, 0xa2, 0xe3, 0x82,
124 0xbb, 0xe3, 0x82, 0xb9, 0xe3, 0x83, 0xb3];
125
126 void registerTests(TestSuite suite) {
127 register("testUtf8bytesToCodepoints", testUtf8bytesToCodepoints, suite);
128 register("testUtf8BytesToString", testUtf8BytesToString, suite);
129 register("testEncodeToUtf8", testEncodeToUtf8, suite);
130 }
131
132 void testEncodeToUtf8() {
133 Expect.listEquals(testEnglishUtf8, encodeAsUtf8(testEnglishPhrase),
134 "english to utf8");
135
136 Expect.listEquals(testDanishUtf8, encodeAsUtf8(testDanishPhrase),
137 "encode danish to utf8");
138
139 Expect.listEquals(testHebrewUtf8, encodeAsUtf8(testHebrewPhrase),
140 "Hebrew to utf8");
141
142 Expect.listEquals(testRussianUtf8, encodeAsUtf8(testRussianPhrase),
143 "Russian to utf8");
144
145 Expect.listEquals(testGreekUtf8, encodeAsUtf8(testGreekPhrase),
146 "Greek to utf8");
147
148 Expect.listEquals(testKatakanaUtf8, encodeAsUtf8(testKatakanaPhrase),
149 "Katakana to utf8");
150 }
151
152 void testUtf8bytesToCodepoints() {
153 Expect.listEquals([954, 972, 963, 956, 949],
154 _utf8ToCodepoints([0xce, 0xba, 0xcf, 0x8c, 0xcf,
155 0x83, 0xce, 0xbc, 0xce, 0xb5]), "κόσμε");
156
157 // boundary conditions: First possible sequence of a certain length
158 Expect.listEquals([0x0], _utf8ToCodepoints([0x0]), "0");
159 Expect.listEquals([0x80], _utf8ToCodepoints([0xc2, 0x80]), "80");
160 Expect.listEquals([0x800],
161 _utf8ToCodepoints([0xe0, 0xa0, 0x80]), "800");
162 Expect.listEquals([0x10000],
163 _utf8ToCodepoints([0xf0, 0x90, 0x80, 0x80]), "10000");
164 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
165 _utf8ToCodepoints([0xf8, 0x88, 0x80, 0x80, 0x80]), "200000");
166 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
167 _utf8ToCodepoints([0xfc, 0x84, 0x80, 0x80, 0x80, 0x80]),
168 "4000000");
169
170 // boundary conditions: Last possible sequence of a certain length
171 Expect.listEquals([0x7f], _utf8ToCodepoints([0x7f]), "7f");
172 Expect.listEquals([0x7ff], _utf8ToCodepoints([0xdf, 0xbf]), "7ff");
173 Expect.listEquals([0xffff],
174 _utf8ToCodepoints([0xef, 0xbf, 0xbf]), "ffff");
175 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
176 _utf8ToCodepoints([0xf7, 0xbf, 0xbf, 0xbf]), "1fffff");
177 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
178 _utf8ToCodepoints([0xfb, 0xbf, 0xbf, 0xbf, 0xbf]), "3ffffff");
179 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
180 _utf8ToCodepoints([0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf]),
181 "4000000");
182
183 // other boundary conditions
184 Expect.listEquals([0xd7ff],
185 _utf8ToCodepoints([0xed, 0x9f, 0xbf]), "d7ff");
186 Expect.listEquals([0xe000],
187 _utf8ToCodepoints([0xee, 0x80, 0x80]), "e000");
188 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
189 _utf8ToCodepoints([0xef, 0xbf, 0xbd]), "fffd");
190 Expect.listEquals([0x10ffff],
191 _utf8ToCodepoints([0xf4, 0x8f, 0xbf, 0xbf]), "10ffff");
192 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
193 _utf8ToCodepoints([0xf4, 0x90, 0x80, 0x80]), "110000");
194
195 // unexpected continuation bytes
196 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
197 _utf8ToCodepoints([0x80]), "80 => replacement character");
198 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
199 _utf8ToCodepoints([0xbf]), "bf => replacement character");
200
201 List<int> allContinuationBytes = <int>[];
202 List<int> matchingReplacementChars = <int>[];
203 for (int i = 0x80; i < 0xc0; i++) {
204 allContinuationBytes.add(i);
205 matchingReplacementChars.add(UNICODE_REPLACEMENT_CHARACTER_CODEPOINT);
206 }
207 Expect.listEquals(matchingReplacementChars,
208 _utf8ToCodepoints(allContinuationBytes),
209 "80 - bf => replacement character x 64");
210
211 List<int> allFirstTwoByteSeq = <int>[];
212 matchingReplacementChars = <int>[];
213 for (int i = 0xc0; i < 0xe0; i++) {
214 allFirstTwoByteSeq.addAll([i, 0x20]);
215 matchingReplacementChars.addAll(
216 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]);
217 }
218 Expect.listEquals(matchingReplacementChars,
219 _utf8ToCodepoints(allFirstTwoByteSeq),
220 "c0 - df + space => replacement character + space x 32");
221
222 List<int> allFirstThreeByteSeq = <int>[];
223 matchingReplacementChars = <int>[];
224 for (int i = 0xe0; i < 0xf0; i++) {
225 allFirstThreeByteSeq.addAll([i, 0x20]);
226 matchingReplacementChars.addAll(
227 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]);
228 }
229 Expect.listEquals(matchingReplacementChars,
230 _utf8ToCodepoints(allFirstThreeByteSeq),
231 "e0 - ef + space => replacement character x 16");
232
233 List<int> allFirstFourByteSeq = <int>[];
234 matchingReplacementChars = <int>[];
235 for (int i = 0xf0; i < 0xf8; i++) {
236 allFirstFourByteSeq.addAll([i, 0x20]);
237 matchingReplacementChars.addAll(
238 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]);
239 }
240 Expect.listEquals(matchingReplacementChars,
241 _utf8ToCodepoints(allFirstFourByteSeq),
242 "f0 - f7 + space => replacement character x 8");
243
244 List<int> allFirstFiveByteSeq = <int>[];
245 matchingReplacementChars = <int>[];
246 for (int i = 0xf8; i < 0xfc; i++) {
247 allFirstFiveByteSeq.addAll([i, 0x20]);
248 matchingReplacementChars.addAll(
249 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]);
250 }
251 Expect.listEquals(matchingReplacementChars,
252 _utf8ToCodepoints(allFirstFiveByteSeq),
253 "f8 - fb + space => replacement character x 4");
254
255 List<int> allFirstSixByteSeq = <int>[];
256 matchingReplacementChars = <int>[];
257 for (int i = 0xfc; i < 0xfe; i++) {
258 allFirstSixByteSeq.addAll([i, 0x20]);
259 matchingReplacementChars.addAll(
260 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]);
261 }
262 Expect.listEquals(matchingReplacementChars,
263 _utf8ToCodepoints(allFirstSixByteSeq),
264 "fc - fd + space => replacement character x 2");
265
266 // Sequences with last continuation byte missing
267 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
268 _utf8ToCodepoints([0xc2]),
269 "2-byte sequence with last byte missing");
270 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
271 _utf8ToCodepoints([0xe0, 0x80]),
272 "3-byte sequence with last byte missing");
273 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
274 _utf8ToCodepoints([0xf0, 0x80, 0x80]),
275 "4-byte sequence with last byte missing");
276 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
277 _utf8ToCodepoints([0xf8, 0x88, 0x80, 0x80]),
278 "5-byte sequence with last byte missing");
279 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
280 _utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80]),
281 "6-byte sequence with last byte missing");
282
283 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
284 _utf8ToCodepoints([0xdf]),
285 "2-byte sequence with last byte missing (hi)");
286 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
287 _utf8ToCodepoints([0xef, 0xbf]),
288 "3-byte sequence with last byte missing (hi)");
289 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
290 _utf8ToCodepoints([0xf7, 0xbf, 0xbf]),
291 "4-byte sequence with last byte missing (hi)");
292 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
293 _utf8ToCodepoints([0xfb, 0xbf, 0xbf, 0xbf]),
294 "5-byte sequence with last byte missing (hi)");
295 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
296 _utf8ToCodepoints([0xfd, 0xbf, 0xbf, 0xbf, 0xbf]),
297 "6-byte sequence with last byte missing (hi)");
298
299 // Concatenation of incomplete sequences
300 Expect.listEquals(
301 [ UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
302 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
303 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
304 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
305 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
306 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
307 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
308 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
309 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
310 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT ],
311 _utf8ToCodepoints(
312 [ 0xc2,
313 0xe0, 0x80,
314 0xf0, 0x80, 0x80,
315 0xf8, 0x88, 0x80, 0x80,
316 0xfc, 0x80, 0x80, 0x80, 0x80,
317 0xdf,
318 0xef, 0xbf,
319 0xf7, 0xbf, 0xbf,
320 0xfb, 0xbf, 0xbf, 0xbf,
321 0xfd, 0xbf, 0xbf, 0xbf, 0xbf ]),
322 "Concatenation of incomplete sequences");
323
324 // Impossible bytes
325 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
326 _utf8ToCodepoints([0xfe]), "fe");
327 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
328 _utf8ToCodepoints([0xff]), "ff");
329 Expect.listEquals([
330 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
331 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
332 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
333 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
334 _utf8ToCodepoints([0xfe, 0xfe, 0xff, 0xff]), "fe fe ff ff");
335
336 // Overlong sequences
337 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
338 _utf8ToCodepoints([0xc0, 0xaf]), "c0 af");
339 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
340 _utf8ToCodepoints([0xe0, 0x80, 0xaf]), "e0 80 af");
341 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
342 _utf8ToCodepoints([0xf0, 0x80, 0x80, 0xaf]), "f0 80 80 af");
343 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
344 _utf8ToCodepoints([0xf8, 0x80, 0x80, 0x80, 0xaf]), "f8 80 80 80 af");
345 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
346 _utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80, 0xaf]),
347 "fc 80 80 80 80 af");
348
349 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
350 _utf8ToCodepoints([0xc1, 0xbf]), "c1 bf");
351 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
352 _utf8ToCodepoints([0xe0, 0x9f, 0xbf]), "e0 9f bf");
353 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
354 _utf8ToCodepoints([0xf0, 0x8f, 0xbf, 0xbf]), "f0 8f bf bf");
355 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
356 _utf8ToCodepoints([0xf8, 0x87, 0xbf, 0xbf, 0xbf]), "f8 87 bf bf bf");
357 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
358 _utf8ToCodepoints([0xfc, 0x83, 0xbf, 0xbf, 0xbf, 0xbf]),
359 "fc 83 bf bf bf bf");
360
361 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
362 _utf8ToCodepoints([0xc0, 0x80]), "c0 80");
363 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
364 _utf8ToCodepoints([0xe0, 0x80, 0x80]), "e0 80 80");
365 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
366 _utf8ToCodepoints([0xf0, 0x80, 0x80, 0x80]), "f0 80 80 80");
367 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
368 _utf8ToCodepoints([0xf8, 0x80, 0x80, 0x80, 0x80]), "f8 80 80 80 80");
369 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
370 _utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80, 0x80]),
371 "fc 80 80 80 80 80");
372
373 // Illegal code positions
374 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
375 _utf8ToCodepoints([0xed, 0xa0, 0x80]), "U+D800");
376 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
377 _utf8ToCodepoints([0xed, 0xad, 0xbf]), "U+DB7F");
378 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
379 _utf8ToCodepoints([0xed, 0xae, 0x80]), "U+DB80");
380 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
381 _utf8ToCodepoints([0xed, 0xaf, 0xbf]), "U+DBFF");
382 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
383 _utf8ToCodepoints([0xed, 0xb0, 0x80]), "U+DC00");
384 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
385 _utf8ToCodepoints([0xed, 0xbe, 0x80]), "U+DF80");
386 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
387 _utf8ToCodepoints([0xed, 0xbf, 0xbf]), "U+DFFF");
388
389 // Paired UTF-16 surrogates
390 Expect.listEquals([
391 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
392 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
393 _utf8ToCodepoints([0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80]),
394 "U+D800 U+DC00");
395 Expect.listEquals([
396 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
397 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
398 _utf8ToCodepoints([0xed, 0xa0, 0x80, 0xed, 0xbf, 0xbf]),
399 "U+D800 U+DFFF");
400 Expect.listEquals([
401 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
402 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
403 _utf8ToCodepoints([0xed, 0xad, 0xbf, 0xed, 0xb0, 0x80]),
404 "U+DB7F U+DC00");
405 Expect.listEquals([
406 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
407 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
408 _utf8ToCodepoints([0xed, 0xad, 0xbf, 0xed, 0xbf, 0xbf]),
409 "U+DB7F U+DFFF");
410 Expect.listEquals([
411 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
412 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
413 _utf8ToCodepoints([0xed, 0xae, 0x80, 0xed, 0xb0, 0x80]),
414 "U+DB80 U+DC00");
415 Expect.listEquals([
416 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
417 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
418 _utf8ToCodepoints([0xed, 0xae, 0x80, 0xed, 0xbf, 0xbf]),
419 "U+DB80 U+DFFF");
420 Expect.listEquals([
421 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
422 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
423 _utf8ToCodepoints([0xed, 0xaf, 0xbf, 0xed, 0xb0, 0x80]),
424 "U+DBFF U+DC00");
425 Expect.listEquals([
426 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT,
427 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
428 _utf8ToCodepoints([0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf]),
429 "U+DBFF U+DFFF");
430
431 // Other illegal code positions (???)
432 Expect.listEquals([0xfffe], _utf8ToCodepoints([0xef, 0xbf, 0xbe]),
433 "U+FFFE");
434 Expect.listEquals([0xffff], _utf8ToCodepoints([0xef, 0xbf, 0xbf]),
435 "U+FFFF");
436 }
437
438 void testUtf8BytesToString() {
439 Expect.stringEquals(testEnglishPhrase,
440 decodeFromUtf8(testEnglishUtf8), "English");
441
442 Expect.stringEquals(testDanishPhrase,
443 decodeFromUtf8(testDanishUtf8), "Danish");
444
445 Expect.stringEquals(testHebrewPhrase,
446 decodeFromUtf8(testHebrewUtf8), "Hebrew");
447
448 Expect.stringEquals(testRussianPhrase,
449 decodeFromUtf8(testRussianUtf8), "Russian");
450
451 Expect.stringEquals(testGreekPhrase,
452 decodeFromUtf8(testGreekUtf8), "Greek");
453
454 Expect.stringEquals(testKatakanaPhrase,
455 decodeFromUtf8(testKatakanaUtf8), "Katakana");
456 }
457 }
OLDNEW
« no previous file with comments | « utils/tests/string_encoding/utf32_tests.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698