OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library utf; | 5 library utf.unicode_core_test; |
| 6 |
6 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
7 import 'dart:collection'; | |
8 | 8 |
9 part '../lib/constants.dart'; | 9 import 'package:utf/utf.dart'; |
10 part '../lib/list_range.dart'; | 10 import 'package:utf/src/util.dart'; |
11 part '../lib/utf16.dart'; | |
12 | 11 |
13 main() { | 12 void main() { |
14 testCodepointsToUtf16CodeUnits(); | 13 testCodepointsToUtf16CodeUnits(); |
15 testUtf16bytesToCodepoints(); | 14 testUtf16bytesToCodepoints(); |
16 } | 15 } |
17 | 16 |
18 void testCodepointsToUtf16CodeUnits() { | 17 void testCodepointsToUtf16CodeUnits() { |
19 // boundary conditions | 18 // boundary conditions |
20 Expect.listEquals([], _codepointsToUtf16CodeUnits([]), "no input"); | 19 Expect.listEquals([], codepointsToUtf16CodeUnits([]), "no input"); |
21 Expect.listEquals([0x0], _codepointsToUtf16CodeUnits([0x0]), "0"); | 20 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0"); |
22 Expect.listEquals([0xd800, 0xdc00], | 21 Expect.listEquals([0xd800, 0xdc00], |
23 _codepointsToUtf16CodeUnits([0x10000]), "10000"); | 22 codepointsToUtf16CodeUnits([0x10000]), "10000"); |
24 | 23 |
25 Expect.listEquals([0xffff], | 24 Expect.listEquals([0xffff], |
26 _codepointsToUtf16CodeUnits([0xffff]), "ffff"); | 25 codepointsToUtf16CodeUnits([0xffff]), "ffff"); |
27 Expect.listEquals([0xdbff, 0xdfff], | 26 Expect.listEquals([0xdbff, 0xdfff], |
28 _codepointsToUtf16CodeUnits([0x10ffff]), "10ffff"); | 27 codepointsToUtf16CodeUnits([0x10ffff]), "10ffff"); |
29 | 28 |
30 Expect.listEquals([0xd7ff], | 29 Expect.listEquals([0xd7ff], |
31 _codepointsToUtf16CodeUnits([0xd7ff]), "d7ff"); | 30 codepointsToUtf16CodeUnits([0xd7ff]), "d7ff"); |
32 Expect.listEquals([0xe000], | 31 Expect.listEquals([0xe000], |
33 _codepointsToUtf16CodeUnits([0xe000]), "e000"); | 32 codepointsToUtf16CodeUnits([0xe000]), "e000"); |
34 | 33 |
35 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 34 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], |
36 _codepointsToUtf16CodeUnits([0xd800]), "d800"); | 35 codepointsToUtf16CodeUnits([0xd800]), "d800"); |
37 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 36 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], |
38 _codepointsToUtf16CodeUnits([0xdfff]), "dfff"); | 37 codepointsToUtf16CodeUnits([0xdfff]), "dfff"); |
39 } | 38 } |
40 | 39 |
41 void testUtf16bytesToCodepoints() { | 40 void testUtf16bytesToCodepoints() { |
42 // boundary conditions: First possible values | 41 // boundary conditions: First possible values |
43 Expect.listEquals([], _utf16CodeUnitsToCodepoints([]), "no input"); | 42 Expect.listEquals([], utf16CodeUnitsToCodepoints([]), "no input"); |
44 Expect.listEquals([0x0], _utf16CodeUnitsToCodepoints([0x0]), "0"); | 43 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0"); |
45 Expect.listEquals([0x10000], | 44 Expect.listEquals([0x10000], |
46 _utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000"); | 45 utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000"); |
47 | 46 |
48 // boundary conditions: Last possible sequence of a certain length | 47 // boundary conditions: Last possible sequence of a certain length |
49 Expect.listEquals([0xffff], | 48 Expect.listEquals([0xffff], |
50 _utf16CodeUnitsToCodepoints([0xffff]), "ffff"); | 49 utf16CodeUnitsToCodepoints([0xffff]), "ffff"); |
51 Expect.listEquals([0x10ffff], | 50 Expect.listEquals([0x10ffff], |
52 _utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff"); | 51 utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff"); |
53 | 52 |
54 // other boundary conditions | 53 // other boundary conditions |
55 Expect.listEquals([0xd7ff], | 54 Expect.listEquals([0xd7ff], |
56 _utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff"); | 55 utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff"); |
57 Expect.listEquals([0xe000], | 56 Expect.listEquals([0xe000], |
58 _utf16CodeUnitsToCodepoints([0xe000]), "e000"); | 57 utf16CodeUnitsToCodepoints([0xe000]), "e000"); |
59 | 58 |
60 // unexpected continuation bytes | 59 // unexpected continuation bytes |
61 Expect.listEquals([0xfffd], | 60 Expect.listEquals([0xfffd], |
62 _utf16CodeUnitsToCodepoints([0xdc00]), | 61 utf16CodeUnitsToCodepoints([0xdc00]), |
63 "dc00 first unexpected continuation byte"); | 62 "dc00 first unexpected continuation byte"); |
64 Expect.listEquals([0xfffd], | 63 Expect.listEquals([0xfffd], |
65 _utf16CodeUnitsToCodepoints([0xdfff]), | 64 utf16CodeUnitsToCodepoints([0xdfff]), |
66 "dfff last unexpected continuation byte"); | 65 "dfff last unexpected continuation byte"); |
67 Expect.listEquals([0xfffd], | 66 Expect.listEquals([0xfffd], |
68 _utf16CodeUnitsToCodepoints([0xdc00]), | 67 utf16CodeUnitsToCodepoints([0xdc00]), |
69 "1 unexpected continuation bytes"); | 68 "1 unexpected continuation bytes"); |
70 Expect.listEquals([0xfffd, 0xfffd], | 69 Expect.listEquals([0xfffd, 0xfffd], |
71 _utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]), | 70 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]), |
72 "2 unexpected continuation bytes"); | 71 "2 unexpected continuation bytes"); |
73 Expect.listEquals([0xfffd, 0xfffd ,0xfffd], | 72 Expect.listEquals([0xfffd, 0xfffd ,0xfffd], |
74 _utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]), | 73 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]), |
75 "3 unexpected continuation bytes"); | 74 "3 unexpected continuation bytes"); |
76 | 75 |
77 // incomplete sequences | 76 // incomplete sequences |
78 Expect.listEquals([0xfffd], _utf16CodeUnitsToCodepoints([0xd800]), | 77 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xd800]), |
79 "d800 last byte missing"); | 78 "d800 last byte missing"); |
80 Expect.listEquals([0xfffd], _utf16CodeUnitsToCodepoints([0xdbff]), | 79 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdbff]), |
81 "dbff last byte missing"); | 80 "dbff last byte missing"); |
82 | 81 |
83 // concatenation of incomplete sequences | 82 // concatenation of incomplete sequences |
84 Expect.listEquals([0xfffd, 0xfffd], | 83 Expect.listEquals([0xfffd, 0xfffd], |
85 _utf16CodeUnitsToCodepoints([0xd800, 0xdbff]), | 84 utf16CodeUnitsToCodepoints([0xd800, 0xdbff]), |
86 "d800 dbff last byte missing"); | 85 "d800 dbff last byte missing"); |
87 | 86 |
88 // impossible bytes | 87 // impossible bytes |
89 Expect.listEquals([0xfffd], _utf16CodeUnitsToCodepoints([0x110000]), | 88 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]), |
90 "110000 out of bounds"); | 89 "110000 out of bounds"); |
91 | 90 |
92 // overlong sequences not possible in utf16 (nothing < x10000) | 91 // overlong sequences not possible in utf16 (nothing < x10000) |
93 // illegal code positions d800-dfff not encodable (< x10000) | 92 // illegal code positions d800-dfff not encodable (< x10000) |
94 } | 93 } |
OLD | NEW |