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

Side by Side Diff: pkg/utf/test/unicode_core_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698