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

Side by Side Diff: utils/tests/string_encoding/UnicodeCoreTests.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: String encoding utility methods and tests for Unicode, UTF-8, -16 and -32. 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
OLDNEW
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2011, 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("UnicodeCoreTests");
7 #import("DUnit.dart");
8 #import("../../string_encoding/UnicodeCore.dart");
9
10 void main() {
11 TestSuite suite = new TestSuite();
12 suite.registerTestClass(new UnicodeCoreTests());
13 suite.run();
14 }
15
16 class UnicodeCoreTests extends TestClass {
17 void registerTests(TestSuite suite) {
18 register("testPlatform", testPlatform, suite);
19 register("testCodepointsToUtf16CodeUnits", testCodepointsToUtf16CodeUnits, s uite);
jat 2012/01/31 15:19:22 Line length.
dcarlson 2012/01/31 22:11:38 Done.
20 register("testUtf16bytesToCodepoints", testUtf16bytesToCodepoints, suite);
21 }
22
23 void testPlatform() {
24 Expect.isFalse(is16BitCodeUnit());
25 }
26
27 void testCodepointsToUtf16CodeUnits() {
28 // boundary conditions
29 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0");
30 Expect.listEquals([0xd800, 0xdc00],
31 codepointsToUtf16CodeUnits([0x10000]), "10000");
32
33 Expect.listEquals([0xffff],
34 codepointsToUtf16CodeUnits([0xffff]), "ffff");
35 Expect.listEquals([0xdbff, 0xdfff],
36 codepointsToUtf16CodeUnits([0x10ffff]), "10ffff");
37
38 Expect.listEquals([0xd7ff],
39 codepointsToUtf16CodeUnits([0xd7ff]), "d7ff");
40 Expect.listEquals([0xe000],
41 codepointsToUtf16CodeUnits([0xe000]), "e000");
42
43 Expect.listEquals([REPLACEMENT_CHARACTER_CODEPOINT],
44 codepointsToUtf16CodeUnits([0xd800]), "d800");
45 Expect.listEquals([REPLACEMENT_CHARACTER_CODEPOINT],
46 codepointsToUtf16CodeUnits([0xdfff]), "dfff");
47 }
48
49 void testUtf16bytesToCodepoints() {
50 // boundary conditions: First possible values
51 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0");
52 Expect.listEquals([0x10000],
53 utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000");
54
55 // boundary conditions: Last possible sequence of a certain length
56 Expect.listEquals([0xffff],
57 utf16CodeUnitsToCodepoints([0xffff]), "ffff");
58 Expect.listEquals([0x10ffff],
59 utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff");
60
61 // other boundary conditions
62 Expect.listEquals([0xd7ff],
63 utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff");
64 Expect.listEquals([0xe000],
65 utf16CodeUnitsToCodepoints([0xe000]), "e000");
66
67 // unexpected continuation bytes
68 Expect.listEquals([0xfffd],
69 utf16CodeUnitsToCodepoints([0xdc00]),
70 "dc00 first unexpected continuation byte");
71 Expect.listEquals([0xfffd],
72 utf16CodeUnitsToCodepoints([0xdfff]),
73 "dfff last unexpected continuation byte");
74 Expect.listEquals([0xfffd],
75 utf16CodeUnitsToCodepoints([0xdc00]),
76 "1 unexpected continuation bytes");
77 Expect.listEquals([0xfffd, 0xfffd],
78 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]),
79 "2 unexpected continuation bytes");
80 Expect.listEquals([0xfffd, 0xfffd ,0xfffd],
81 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]),
82 "3 unexpected continuation bytes");
83
84 // incomplete sequences
85 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xd800]),
86 "d800 last byte missing");
87 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdbff]),
88 "dbff last byte missing");
89
90 // concatenation of incomplete sequences
91 Expect.listEquals([0xfffd, 0xfffd],
92 utf16CodeUnitsToCodepoints([0xd800, 0xdbff]),
93 "d800 dbff last byte missing");
94
95 // impossible bytes
96 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]),
97 "110000 out of bounds");
98
99 // overlong sequences not possible in utf16 (nothing < x10000)
100 // illegal code positions d800-dfff not encodable (< x10000)
101 }
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698