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

Side by Side Diff: pkg/utf/test/utf32_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 import 'package:expect/expect.dart';
6 import 'package:utf/utf.dart';
7
8 const String testKoreanCharSubset = """
9 가각갂갃간갅갆갇갈갉갊갋갌갍갎갏감갑값갓갔강갖갗갘같갚갛
10 개객갞갟갠갡갢갣갤갥갦갧갨갩갪갫갬갭갮갯갰갱갲갳갴갵갶갷
11 갸갹갺갻갼갽갾갿걀걁걂걃걄걅걆걇걈걉걊걋걌걍걎걏걐걑걒걓""";
12
13 const String testHanTwice = "二";
14
15 const List<int> testKoreanCharSubsetUtf32beBom = const<int>[
16 0x00, 0x00, 0xfe, 0xff, 0x00, 0x00, 0xac, 0x00,
17 0x00, 0x00, 0xac, 0x01, 0x00, 0x00, 0xac, 0x02,
18 0x00, 0x00, 0xac, 0x03, 0x00, 0x00, 0xac, 0x04,
19 0x00, 0x00, 0xac, 0x05, 0x00, 0x00, 0xac, 0x06,
20 0x00, 0x00, 0xac, 0x07, 0x00, 0x00, 0xac, 0x08,
21 0x00, 0x00, 0xac, 0x09, 0x00, 0x00, 0xac, 0x0a,
22 0x00, 0x00, 0xac, 0x0b, 0x00, 0x00, 0xac, 0x0c,
23 0x00, 0x00, 0xac, 0x0d, 0x00, 0x00, 0xac, 0x0e,
24 0x00, 0x00, 0xac, 0x0f, 0x00, 0x00, 0xac, 0x10,
25 0x00, 0x00, 0xac, 0x11, 0x00, 0x00, 0xac, 0x12,
26 0x00, 0x00, 0xac, 0x13, 0x00, 0x00, 0xac, 0x14,
27 0x00, 0x00, 0xac, 0x15, 0x00, 0x00, 0xac, 0x16,
28 0x00, 0x00, 0xac, 0x17, 0x00, 0x00, 0xac, 0x18,
29 0x00, 0x00, 0xac, 0x19, 0x00, 0x00, 0xac, 0x1a,
30 0x00, 0x00, 0xac, 0x1b, 0x00, 0x00, 0x00, 0x0a,
31 0x00, 0x00, 0xac, 0x1c, 0x00, 0x00, 0xac, 0x1d,
32 0x00, 0x00, 0xac, 0x1e, 0x00, 0x00, 0xac, 0x1f,
33 0x00, 0x00, 0xac, 0x20, 0x00, 0x00, 0xac, 0x21,
34 0x00, 0x00, 0xac, 0x22, 0x00, 0x00, 0xac, 0x23,
35 0x00, 0x00, 0xac, 0x24, 0x00, 0x00, 0xac, 0x25,
36 0x00, 0x00, 0xac, 0x26, 0x00, 0x00, 0xac, 0x27,
37 0x00, 0x00, 0xac, 0x28, 0x00, 0x00, 0xac, 0x29,
38 0x00, 0x00, 0xac, 0x2a, 0x00, 0x00, 0xac, 0x2b,
39 0x00, 0x00, 0xac, 0x2c, 0x00, 0x00, 0xac, 0x2d,
40 0x00, 0x00, 0xac, 0x2e, 0x00, 0x00, 0xac, 0x2f,
41 0x00, 0x00, 0xac, 0x30, 0x00, 0x00, 0xac, 0x31,
42 0x00, 0x00, 0xac, 0x32, 0x00, 0x00, 0xac, 0x33,
43 0x00, 0x00, 0xac, 0x34, 0x00, 0x00, 0xac, 0x35,
44 0x00, 0x00, 0xac, 0x36, 0x00, 0x00, 0xac, 0x37,
45 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0xac, 0x38,
46 0x00, 0x00, 0xac, 0x39, 0x00, 0x00, 0xac, 0x3a,
47 0x00, 0x00, 0xac, 0x3b, 0x00, 0x00, 0xac, 0x3c,
48 0x00, 0x00, 0xac, 0x3d, 0x00, 0x00, 0xac, 0x3e,
49 0x00, 0x00, 0xac, 0x3f, 0x00, 0x00, 0xac, 0x40,
50 0x00, 0x00, 0xac, 0x41, 0x00, 0x00, 0xac, 0x42,
51 0x00, 0x00, 0xac, 0x43, 0x00, 0x00, 0xac, 0x44,
52 0x00, 0x00, 0xac, 0x45, 0x00, 0x00, 0xac, 0x46,
53 0x00, 0x00, 0xac, 0x47, 0x00, 0x00, 0xac, 0x48,
54 0x00, 0x00, 0xac, 0x49, 0x00, 0x00, 0xac, 0x4a,
55 0x00, 0x00, 0xac, 0x4b, 0x00, 0x00, 0xac, 0x4c,
56 0x00, 0x00, 0xac, 0x4d, 0x00, 0x00, 0xac, 0x4e,
57 0x00, 0x00, 0xac, 0x4f, 0x00, 0x00, 0xac, 0x50,
58 0x00, 0x00, 0xac, 0x51, 0x00, 0x00, 0xac, 0x52,
59 0x00, 0x00, 0xac, 0x53];
60
61 const List<int> testKoreanCharSubsetUtf32le = const<int>[
62 0x00, 0xac, 0x00, 0x00, 0x01, 0xac, 0x00, 0x00,
63 0x02, 0xac, 0x00, 0x00, 0x03, 0xac, 0x00, 0x00,
64 0x04, 0xac, 0x00, 0x00, 0x05, 0xac, 0x00, 0x00,
65 0x06, 0xac, 0x00, 0x00, 0x07, 0xac, 0x00, 0x00,
66 0x08, 0xac, 0x00, 0x00, 0x09, 0xac, 0x00, 0x00,
67 0x0a, 0xac, 0x00, 0x00, 0x0b, 0xac, 0x00, 0x00,
68 0x0c, 0xac, 0x00, 0x00, 0x0d, 0xac, 0x00, 0x00,
69 0x0e, 0xac, 0x00, 0x00, 0x0f, 0xac, 0x00, 0x00,
70 0x10, 0xac, 0x00, 0x00, 0x11, 0xac, 0x00, 0x00,
71 0x12, 0xac, 0x00, 0x00, 0x13, 0xac, 0x00, 0x00,
72 0x14, 0xac, 0x00, 0x00, 0x15, 0xac, 0x00, 0x00,
73 0x16, 0xac, 0x00, 0x00, 0x17, 0xac, 0x00, 0x00,
74 0x18, 0xac, 0x00, 0x00, 0x19, 0xac, 0x00, 0x00,
75 0x1a, 0xac, 0x00, 0x00, 0x1b, 0xac, 0x00, 0x00,
76 0x0a, 0x00, 0x00, 0x00, 0x1c, 0xac, 0x00, 0x00,
77 0x1d, 0xac, 0x00, 0x00, 0x1e, 0xac, 0x00, 0x00,
78 0x1f, 0xac, 0x00, 0x00, 0x20, 0xac, 0x00, 0x00,
79 0x21, 0xac, 0x00, 0x00, 0x22, 0xac, 0x00, 0x00,
80 0x23, 0xac, 0x00, 0x00, 0x24, 0xac, 0x00, 0x00,
81 0x25, 0xac, 0x00, 0x00, 0x26, 0xac, 0x00, 0x00,
82 0x27, 0xac, 0x00, 0x00, 0x28, 0xac, 0x00, 0x00,
83 0x29, 0xac, 0x00, 0x00, 0x2a, 0xac, 0x00, 0x00,
84 0x2b, 0xac, 0x00, 0x00, 0x2c, 0xac, 0x00, 0x00,
85 0x2d, 0xac, 0x00, 0x00, 0x2e, 0xac, 0x00, 0x00,
86 0x2f, 0xac, 0x00, 0x00, 0x30, 0xac, 0x00, 0x00,
87 0x31, 0xac, 0x00, 0x00, 0x32, 0xac, 0x00, 0x00,
88 0x33, 0xac, 0x00, 0x00, 0x34, 0xac, 0x00, 0x00,
89 0x35, 0xac, 0x00, 0x00, 0x36, 0xac, 0x00, 0x00,
90 0x37, 0xac, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
91 0x38, 0xac, 0x00, 0x00, 0x39, 0xac, 0x00, 0x00,
92 0x3a, 0xac, 0x00, 0x00, 0x3b, 0xac, 0x00, 0x00,
93 0x3c, 0xac, 0x00, 0x00, 0x3d, 0xac, 0x00, 0x00,
94 0x3e, 0xac, 0x00, 0x00, 0x3f, 0xac, 0x00, 0x00,
95 0x40, 0xac, 0x00, 0x00, 0x41, 0xac, 0x00, 0x00,
96 0x42, 0xac, 0x00, 0x00, 0x43, 0xac, 0x00, 0x00,
97 0x44, 0xac, 0x00, 0x00, 0x45, 0xac, 0x00, 0x00,
98 0x46, 0xac, 0x00, 0x00, 0x47, 0xac, 0x00, 0x00,
99 0x48, 0xac, 0x00, 0x00, 0x49, 0xac, 0x00, 0x00,
100 0x4a, 0xac, 0x00, 0x00, 0x4b, 0xac, 0x00, 0x00,
101 0x4c, 0xac, 0x00, 0x00, 0x4d, 0xac, 0x00, 0x00,
102 0x4e, 0xac, 0x00, 0x00, 0x4f, 0xac, 0x00, 0x00,
103 0x50, 0xac, 0x00, 0x00, 0x51, 0xac, 0x00, 0x00,
104 0x52, 0xac, 0x00, 0x00, 0x53, 0xac, 0x00, 0x00];
105
106 void main() {
107 testUtf32BytesToString();
108 testEncodeToUtf32();
109 testIterableMethods();
110 }
111
112 void testEncodeToUtf32() {
113 Expect.listEquals([], encodeUtf32le(""), "no input"); // TODO(dcarlson) skip b om on empty?
114 Expect.listEquals(testKoreanCharSubsetUtf32beBom,
115 encodeUtf32(testKoreanCharSubset),
116 "encode UTF-32(BE by default) Korean");
117 Expect.listEquals(testKoreanCharSubsetUtf32le,
118 encodeUtf32le(testKoreanCharSubset),
119 "encode UTF-32(LE by default) Korean");
120 }
121
122 void testUtf32BytesToString() {
123 Expect.stringEquals("", decodeUtf32([]), "no input");
124 Expect.stringEquals("\ufffd", decodeUtf32([0]), "single byte");
125 Expect.stringEquals("\ufffd", decodeUtf32([0, 0, 0x4e]),
126 "short a byte");
127 Expect.stringEquals("\u4e8c\ufffd", decodeUtf32([0, 0, 0x4e, 0x8c, 0]),
128 "extra byte");
129
130 Expect.stringEquals(testHanTwice, decodeUtf32([0, 0, 0x4e, 0x8c]),
131 "twice variation 1");
132 Expect.stringEquals(testHanTwice,
133 decodeUtf32([0, 0, 0xfe, 0xff, 0, 0, 0x4e, 0x8c]),
134 "twice variation 2");
135 Expect.stringEquals(testHanTwice,
136 decodeUtf32([0xff, 0xfe, 0, 0, 0x8c, 0x4e, 0, 0]),
137 "twice variation 3");
138
139 Expect.stringEquals(testHanTwice, decodeUtf32be([0, 0, 0x4e, 0x8c]),
140 "twice variation 4");
141 Expect.stringEquals(testHanTwice,
142 decodeUtf32be([0, 0, 0xfe, 0xff, 0, 0, 0x4e, 0x8c]),
143 "twice variation 5");
144
145 Expect.stringEquals(testHanTwice, decodeUtf32le([0x8c, 0x4e, 0, 0]),
146 "twice variation 6");
147 Expect.stringEquals(testHanTwice,
148 decodeUtf32le([0xff, 0xfe, 0, 0, 0x8c, 0x4e, 0, 0]),
149 "twice variation 7");
150
151 Expect.stringEquals(testKoreanCharSubset,
152 decodeUtf32(testKoreanCharSubsetUtf32beBom),
153 "UTF-32BE Korean");
154 }
155
156 void testIterableMethods() {
157 // empty input
158 Expect.isFalse(decodeUtf32AsIterable([]).iterator.moveNext());
159
160 IterableUtf32Decoder koreanDecoder =
161 decodeUtf32AsIterable(testKoreanCharSubsetUtf32beBom);
162 // get the first character
163 Expect.equals(testKoreanCharSubset.codeUnits[0], koreanDecoder.first);
164 // get the whole translation using the Iterable interface
165 Expect.stringEquals(testKoreanCharSubset,
166 new String.fromCharCodes(new List<int>.from(koreanDecoder)));
167
168 // specify types
169 Expect.equals(44032, (new List<int>
170 .from(decodeUtf32beAsIterable(testKoreanCharSubsetUtf32beBom)))[0]);
171 Expect.equals(44032, (new List<int>
172 .from(decodeUtf32leAsIterable(testKoreanCharSubsetUtf32le)))[0]);
173 bool stripBom = false;
174 Expect.equals(UNICODE_BOM, (new List<int>
175 .from(decodeUtf32beAsIterable(testKoreanCharSubsetUtf32beBom,
176 0, null, stripBom)))[0]);
floitsch 2013/11/18 17:08:17 needed to change from named to positional argument
177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698