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