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

Side by Side Diff: utils/tests/string_encoding/unicode_core_tests.dart

Issue 9410001: restructure string decoding to support iterable use and include benchmarks for UTF-8 decoding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 #library("unicode_core_tests"); 6 #library("unicode_core_tests");
7 #import("dunit.dart"); 7 #import("dunit.dart");
8 #import("../../string_encoding/unicode_core.dart"); 8 #import("../../string_encoding/unicode_core.dart");
9 9
10 void main() { 10 void main() {
11 TestSuite suite = new TestSuite(); 11 TestSuite suite = new TestSuite();
12 suite.registerTestClass(new UnicodeCoreTests()); 12 suite.registerTestClass(new UnicodeCoreTests());
13 suite.run(); 13 suite.run();
14 } 14 }
15 15
16 class UnicodeCoreTests extends TestClass { 16 class UnicodeCoreTests extends TestClass {
17 void registerTests(TestSuite suite) { 17 void registerTests(TestSuite suite) {
18 register("testPlatform", testPlatform, suite); 18 register("testPlatform", testPlatform, suite);
19 register("testCodepointsToUtf16CodeUnits", 19 register("testCodepointsToUtf16CodeUnits",
20 testCodepointsToUtf16CodeUnits, suite); 20 testCodepointsToUtf16CodeUnits, suite);
21 register("testUtf16bytesToCodepoints", testUtf16bytesToCodepoints, suite); 21 register("testUtf16bytesToCodepoints", testUtf16bytesToCodepoints, suite);
22 } 22 }
23 23
24 void testPlatform() { 24 void testPlatform() {
25 Expect.isFalse(is16BitCodeUnit()); 25 Expect.isFalse(is16BitCodeUnit());
26 } 26 }
27 27
28 void testCodepointsToUtf16CodeUnits() { 28 void testCodepointsToUtf16CodeUnits() {
29 // boundary conditions 29 // boundary conditions
30 Expect.listEquals([], codepointsToUtf16CodeUnits([]), "no input");
30 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0"); 31 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0");
31 Expect.listEquals([0xd800, 0xdc00], 32 Expect.listEquals([0xd800, 0xdc00],
32 codepointsToUtf16CodeUnits([0x10000]), "10000"); 33 codepointsToUtf16CodeUnits([0x10000]), "10000");
33 34
34 Expect.listEquals([0xffff], 35 Expect.listEquals([0xffff],
35 codepointsToUtf16CodeUnits([0xffff]), "ffff"); 36 codepointsToUtf16CodeUnits([0xffff]), "ffff");
36 Expect.listEquals([0xdbff, 0xdfff], 37 Expect.listEquals([0xdbff, 0xdfff],
37 codepointsToUtf16CodeUnits([0x10ffff]), "10ffff"); 38 codepointsToUtf16CodeUnits([0x10ffff]), "10ffff");
38 39
39 Expect.listEquals([0xd7ff], 40 Expect.listEquals([0xd7ff],
40 codepointsToUtf16CodeUnits([0xd7ff]), "d7ff"); 41 codepointsToUtf16CodeUnits([0xd7ff]), "d7ff");
41 Expect.listEquals([0xe000], 42 Expect.listEquals([0xe000],
42 codepointsToUtf16CodeUnits([0xe000]), "e000"); 43 codepointsToUtf16CodeUnits([0xe000]), "e000");
43 44
44 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], 45 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
45 codepointsToUtf16CodeUnits([0xd800]), "d800"); 46 codepointsToUtf16CodeUnits([0xd800]), "d800");
46 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], 47 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
47 codepointsToUtf16CodeUnits([0xdfff]), "dfff"); 48 codepointsToUtf16CodeUnits([0xdfff]), "dfff");
48 } 49 }
49 50
50 void testUtf16bytesToCodepoints() { 51 void testUtf16bytesToCodepoints() {
51 // boundary conditions: First possible values 52 // boundary conditions: First possible values
53 Expect.listEquals([], utf16CodeUnitsToCodepoints([]), "no input");
52 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0"); 54 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0");
53 Expect.listEquals([0x10000], 55 Expect.listEquals([0x10000],
54 utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000"); 56 utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000");
55 57
56 // boundary conditions: Last possible sequence of a certain length 58 // boundary conditions: Last possible sequence of a certain length
57 Expect.listEquals([0xffff], 59 Expect.listEquals([0xffff],
58 utf16CodeUnitsToCodepoints([0xffff]), "ffff"); 60 utf16CodeUnitsToCodepoints([0xffff]), "ffff");
59 Expect.listEquals([0x10ffff], 61 Expect.listEquals([0x10ffff],
60 utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff"); 62 utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff");
61 63
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 "d800 dbff last byte missing"); 96 "d800 dbff last byte missing");
95 97
96 // impossible bytes 98 // impossible bytes
97 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]), 99 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]),
98 "110000 out of bounds"); 100 "110000 out of bounds");
99 101
100 // overlong sequences not possible in utf16 (nothing < x10000) 102 // overlong sequences not possible in utf16 (nothing < x10000)
101 // illegal code positions d800-dfff not encodable (< x10000) 103 // illegal code positions d800-dfff not encodable (< x10000)
102 } 104 }
103 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698