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.unicode_core_test; | 5 library utf.unicode_core_test; |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:test/test.dart'; |
8 | |
9 import 'package:utf/utf.dart'; | 8 import 'package:utf/utf.dart'; |
10 import 'package:utf/src/util.dart'; | 9 import 'package:utf/src/util.dart'; |
11 | 10 |
| 11 import 'expect.dart' as Expect; |
| 12 |
12 void main() { | 13 void main() { |
13 testCodepointsToUtf16CodeUnits(); | 14 test('codepoints to utf16 codepoints', testCodepointsToUtf16CodeUnits); |
14 testUtf16bytesToCodepoints(); | 15 test('utf16 bytes to codepoints', testUtf16bytesToCodepoints); |
15 } | 16 } |
16 | 17 |
17 void testCodepointsToUtf16CodeUnits() { | 18 void testCodepointsToUtf16CodeUnits() { |
18 // boundary conditions | 19 // boundary conditions |
19 Expect.listEquals([], codepointsToUtf16CodeUnits([]), "no input"); | 20 Expect.listEquals([], codepointsToUtf16CodeUnits([]), "no input"); |
20 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0"); | 21 Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0"); |
21 Expect.listEquals([0xd800, 0xdc00], | 22 Expect.listEquals( |
22 codepointsToUtf16CodeUnits([0x10000]), "10000"); | 23 [0xd800, 0xdc00], codepointsToUtf16CodeUnits([0x10000]), "10000"); |
23 | 24 |
24 Expect.listEquals([0xffff], | 25 Expect.listEquals([0xffff], codepointsToUtf16CodeUnits([0xffff]), "ffff"); |
25 codepointsToUtf16CodeUnits([0xffff]), "ffff"); | 26 Expect.listEquals( |
26 Expect.listEquals([0xdbff, 0xdfff], | 27 [0xdbff, 0xdfff], codepointsToUtf16CodeUnits([0x10ffff]), "10ffff"); |
27 codepointsToUtf16CodeUnits([0x10ffff]), "10ffff"); | |
28 | 28 |
29 Expect.listEquals([0xd7ff], | 29 Expect.listEquals([0xd7ff], codepointsToUtf16CodeUnits([0xd7ff]), "d7ff"); |
30 codepointsToUtf16CodeUnits([0xd7ff]), "d7ff"); | 30 Expect.listEquals([0xe000], codepointsToUtf16CodeUnits([0xe000]), "e000"); |
31 Expect.listEquals([0xe000], | |
32 codepointsToUtf16CodeUnits([0xe000]), "e000"); | |
33 | 31 |
34 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 32 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], |
35 codepointsToUtf16CodeUnits([0xd800]), "d800"); | 33 codepointsToUtf16CodeUnits([0xd800]), "d800"); |
36 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 34 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], |
37 codepointsToUtf16CodeUnits([0xdfff]), "dfff"); | 35 codepointsToUtf16CodeUnits([0xdfff]), "dfff"); |
38 } | 36 } |
39 | 37 |
40 void testUtf16bytesToCodepoints() { | 38 void testUtf16bytesToCodepoints() { |
41 // boundary conditions: First possible values | 39 // boundary conditions: First possible values |
42 Expect.listEquals([], utf16CodeUnitsToCodepoints([]), "no input"); | 40 Expect.listEquals([], utf16CodeUnitsToCodepoints([]), "no input"); |
43 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0"); | 41 Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0"); |
44 Expect.listEquals([0x10000], | 42 Expect.listEquals( |
45 utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000"); | 43 [0x10000], utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000"); |
46 | 44 |
47 // boundary conditions: Last possible sequence of a certain length | 45 // boundary conditions: Last possible sequence of a certain length |
48 Expect.listEquals([0xffff], | 46 Expect.listEquals([0xffff], utf16CodeUnitsToCodepoints([0xffff]), "ffff"); |
49 utf16CodeUnitsToCodepoints([0xffff]), "ffff"); | 47 Expect.listEquals( |
50 Expect.listEquals([0x10ffff], | 48 [0x10ffff], utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff"); |
51 utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff"); | |
52 | 49 |
53 // other boundary conditions | 50 // other boundary conditions |
54 Expect.listEquals([0xd7ff], | 51 Expect.listEquals([0xd7ff], utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff"); |
55 utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff"); | 52 Expect.listEquals([0xe000], utf16CodeUnitsToCodepoints([0xe000]), "e000"); |
56 Expect.listEquals([0xe000], | |
57 utf16CodeUnitsToCodepoints([0xe000]), "e000"); | |
58 | 53 |
59 // unexpected continuation bytes | 54 // unexpected continuation bytes |
60 Expect.listEquals([0xfffd], | 55 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdc00]), |
61 utf16CodeUnitsToCodepoints([0xdc00]), | |
62 "dc00 first unexpected continuation byte"); | 56 "dc00 first unexpected continuation byte"); |
63 Expect.listEquals([0xfffd], | 57 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdfff]), |
64 utf16CodeUnitsToCodepoints([0xdfff]), | |
65 "dfff last unexpected continuation byte"); | 58 "dfff last unexpected continuation byte"); |
66 Expect.listEquals([0xfffd], | 59 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdc00]), |
67 utf16CodeUnitsToCodepoints([0xdc00]), | |
68 "1 unexpected continuation bytes"); | 60 "1 unexpected continuation bytes"); |
69 Expect.listEquals([0xfffd, 0xfffd], | 61 Expect.listEquals( |
| 62 [0xfffd, 0xfffd], |
70 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]), | 63 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]), |
71 "2 unexpected continuation bytes"); | 64 "2 unexpected continuation bytes"); |
72 Expect.listEquals([0xfffd, 0xfffd ,0xfffd], | 65 Expect.listEquals( |
| 66 [0xfffd, 0xfffd, 0xfffd], |
73 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]), | 67 utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]), |
74 "3 unexpected continuation bytes"); | 68 "3 unexpected continuation bytes"); |
75 | 69 |
76 // incomplete sequences | 70 // incomplete sequences |
77 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xd800]), | 71 Expect.listEquals( |
78 "d800 last byte missing"); | 72 [0xfffd], utf16CodeUnitsToCodepoints([0xd800]), "d800 last byte missing"); |
79 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdbff]), | 73 Expect.listEquals( |
80 "dbff last byte missing"); | 74 [0xfffd], utf16CodeUnitsToCodepoints([0xdbff]), "dbff last byte missing"); |
81 | 75 |
82 // concatenation of incomplete sequences | 76 // concatenation of incomplete sequences |
83 Expect.listEquals([0xfffd, 0xfffd], | 77 Expect.listEquals( |
| 78 [0xfffd, 0xfffd], |
84 utf16CodeUnitsToCodepoints([0xd800, 0xdbff]), | 79 utf16CodeUnitsToCodepoints([0xd800, 0xdbff]), |
85 "d800 dbff last byte missing"); | 80 "d800 dbff last byte missing"); |
86 | 81 |
87 // impossible bytes | 82 // impossible bytes |
88 Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]), | 83 Expect.listEquals( |
89 "110000 out of bounds"); | 84 [0xfffd], utf16CodeUnitsToCodepoints([0x110000]), "110000 out of bounds"); |
90 | 85 |
91 // overlong sequences not possible in utf16 (nothing < x10000) | 86 // overlong sequences not possible in utf16 (nothing < x10000) |
92 // illegal code positions d800-dfff not encodable (< x10000) | 87 // illegal code positions d800-dfff not encodable (< x10000) |
93 } | 88 } |
OLD | NEW |