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

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: remove notes to self 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) 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("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",
20 testCodepointsToUtf16CodeUnits, suite);
21 register("testUtf16bytesToCodepoints", testUtf16bytesToCodepoints, suite);
22 }
23
24 void testPlatform() {
25 Expect.isFalse(is16BitCodeUnit());
26 }
27
28 void testCodepointsToUtf16CodeUnits() {
29 // boundary conditions
Søren Gjesse 2012/02/01 11:25:25 How about having a shared list of the "sane" test
dcarlson 2012/02/01 22:18:46 Thanks for the suggestion -- I think this is clear
30 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0");
31 Expect.listEquals([0xd800, 0xdc00],
32 codepointsToUtf16CodeUnits([0x10000]), "10000");
33
34 Expect.listEquals([0xffff],
35 codepointsToUtf16CodeUnits([0xffff]), "ffff");
36 Expect.listEquals([0xdbff, 0xdfff],
37 codepointsToUtf16CodeUnits([0x10ffff]), "10ffff");
38
39 Expect.listEquals([0xd7ff],
40 codepointsToUtf16CodeUnits([0xd7ff]), "d7ff");
41 Expect.listEquals([0xe000],
42 codepointsToUtf16CodeUnits([0xe000]), "e000");
43
44 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
45 codepointsToUtf16CodeUnits([0xd800]), "d800");
46 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
47 codepointsToUtf16CodeUnits([0xdfff]), "dfff");
48 }
49
50 void testUtf16bytesToCodepoints() {
51 // boundary conditions: First possible values
52 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0");
53 Expect.listEquals([0x10000],
54 utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000");
55
56 // boundary conditions: Last possible sequence of a certain length
57 Expect.listEquals([0xffff],
58 utf16CodeUnitsToCodepoints([0xffff]), "ffff");
59 Expect.listEquals([0x10ffff],
60 utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff");
61
62 // other boundary conditions
63 Expect.listEquals([0xd7ff],
64 utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff");
65 Expect.listEquals([0xe000],
66 utf16CodeUnitsToCodepoints([0xe000]), "e000");
67
68 // unexpected continuation bytes
69 Expect.listEquals([0xfffd],
70 utf16CodeUnitsToCodepoints([0xdc00]),
71 "dc00 first unexpected continuation byte");
72 Expect.listEquals([0xfffd],
73 utf16CodeUnitsToCodepoints([0xdfff]),
74 "dfff last unexpected continuation byte");
75 Expect.listEquals([0xfffd],
76 utf16CodeUnitsToCodepoints([0xdc00]),
77 "1 unexpected continuation bytes");
78 Expect.listEquals([0xfffd, 0xfffd],
79 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]),
80 "2 unexpected continuation bytes");
81 Expect.listEquals([0xfffd, 0xfffd ,0xfffd],
82 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]),
83 "3 unexpected continuation bytes");
84
85 // incomplete sequences
86 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xd800]),
87 "d800 last byte missing");
88 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdbff]),
89 "dbff last byte missing");
90
91 // concatenation of incomplete sequences
92 Expect.listEquals([0xfffd, 0xfffd],
93 utf16CodeUnitsToCodepoints([0xd800, 0xdbff]),
94 "d800 dbff last byte missing");
95
96 // impossible bytes
97 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]),
98 "110000 out of bounds");
99
100 // overlong sequences not possible in utf16 (nothing < x10000)
101 // illegal code positions d800-dfff not encodable (< x10000)
102 }
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698