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

Side by Side Diff: pkg/utf/test/utf16_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 utf16_tests;
6 import 'package:expect/expect.dart';
7 import 'package:utf/utf.dart';
8
9 const String testKoreanCharSubset = """
10 가각갂갃간갅갆갇갈갉갊갋갌갍갎갏감갑값갓갔강갖갗갘같갚갛
11 개객갞갟갠갡갢갣갤갥갦갧갨갩갪갫갬갭갮갯갰갱갲갳갴갵갶갷
12 갸갹갺갻갼갽갾갿걀걁걂걃걄걅걆걇걈걉걊걋걌걍걎걏걐걑걒걓""";
13
14 const String testHanWater = "水";
15
16 const List<int> testKoreanCharSubsetUtf16beBom = const<int>[
17 0xfe, 0xff, 0xac, 0x00, 0xac, 0x01, 0xac, 0x02,
18 0xac, 0x03, 0xac, 0x04, 0xac, 0x05, 0xac, 0x06,
19 0xac, 0x07, 0xac, 0x08, 0xac, 0x09, 0xac, 0x0a,
20 0xac, 0x0b, 0xac, 0x0c, 0xac, 0x0d, 0xac, 0x0e,
21 0xac, 0x0f, 0xac, 0x10, 0xac, 0x11, 0xac, 0x12,
22 0xac, 0x13, 0xac, 0x14, 0xac, 0x15, 0xac, 0x16,
23 0xac, 0x17, 0xac, 0x18, 0xac, 0x19, 0xac, 0x1a,
24 0xac, 0x1b, 0x00, 0x0a, 0xac, 0x1c, 0xac, 0x1d,
25 0xac, 0x1e, 0xac, 0x1f, 0xac, 0x20, 0xac, 0x21,
26 0xac, 0x22, 0xac, 0x23, 0xac, 0x24, 0xac, 0x25,
27 0xac, 0x26, 0xac, 0x27, 0xac, 0x28, 0xac, 0x29,
28 0xac, 0x2a, 0xac, 0x2b, 0xac, 0x2c, 0xac, 0x2d,
29 0xac, 0x2e, 0xac, 0x2f, 0xac, 0x30, 0xac, 0x31,
30 0xac, 0x32, 0xac, 0x33, 0xac, 0x34, 0xac, 0x35,
31 0xac, 0x36, 0xac, 0x37, 0x00, 0x0a, 0xac, 0x38,
32 0xac, 0x39, 0xac, 0x3a, 0xac, 0x3b, 0xac, 0x3c,
33 0xac, 0x3d, 0xac, 0x3e, 0xac, 0x3f, 0xac, 0x40,
34 0xac, 0x41, 0xac, 0x42, 0xac, 0x43, 0xac, 0x44,
35 0xac, 0x45, 0xac, 0x46, 0xac, 0x47, 0xac, 0x48,
36 0xac, 0x49, 0xac, 0x4a, 0xac, 0x4b, 0xac, 0x4c,
37 0xac, 0x4d, 0xac, 0x4e, 0xac, 0x4f, 0xac, 0x50,
38 0xac, 0x51, 0xac, 0x52, 0xac, 0x53];
39
40 const List<int> testKoreanCharSubsetUtf16le = const<int> [
41 0x00, 0xac, 0x01, 0xac, 0x02, 0xac, 0x03, 0xac,
42 0x04, 0xac, 0x05, 0xac, 0x06, 0xac, 0x07, 0xac,
43 0x08, 0xac, 0x09, 0xac, 0x0a, 0xac, 0x0b, 0xac,
44 0x0c, 0xac, 0x0d, 0xac, 0x0e, 0xac, 0x0f, 0xac,
45 0x10, 0xac, 0x11, 0xac, 0x12, 0xac, 0x13, 0xac,
46 0x14, 0xac, 0x15, 0xac, 0x16, 0xac, 0x17, 0xac,
47 0x18, 0xac, 0x19, 0xac, 0x1a, 0xac, 0x1b, 0xac,
48 0x0a, 0x00, 0x1c, 0xac, 0x1d, 0xac, 0x1e, 0xac,
49 0x1f, 0xac, 0x20, 0xac, 0x21, 0xac, 0x22, 0xac,
50 0x23, 0xac, 0x24, 0xac, 0x25, 0xac, 0x26, 0xac,
51 0x27, 0xac, 0x28, 0xac, 0x29, 0xac, 0x2a, 0xac,
52 0x2b, 0xac, 0x2c, 0xac, 0x2d, 0xac, 0x2e, 0xac,
53 0x2f, 0xac, 0x30, 0xac, 0x31, 0xac, 0x32, 0xac,
54 0x33, 0xac, 0x34, 0xac, 0x35, 0xac, 0x36, 0xac,
55 0x37, 0xac, 0x0a, 0x00, 0x38, 0xac, 0x39, 0xac,
56 0x3a, 0xac, 0x3b, 0xac, 0x3c, 0xac, 0x3d, 0xac,
57 0x3e, 0xac, 0x3f, 0xac, 0x40, 0xac, 0x41, 0xac,
58 0x42, 0xac, 0x43, 0xac, 0x44, 0xac, 0x45, 0xac,
59 0x46, 0xac, 0x47, 0xac, 0x48, 0xac, 0x49, 0xac,
60 0x4a, 0xac, 0x4b, 0xac, 0x4c, 0xac, 0x4d, 0xac,
61 0x4e, 0xac, 0x4f, 0xac, 0x50, 0xac, 0x51, 0xac,
62 0x52, 0xac, 0x53, 0xac];
63
64 void main() {
65 testEncodeToUtf16();
66 testUtf16BytesToString();
67 testIterableMethods();
68 }
69
70 void testEncodeToUtf16() {
71 Expect.listEquals([], encodeUtf16be("")); // TODO(dcarlson) should we skip bom if empty?
72 Expect.listEquals(testKoreanCharSubsetUtf16beBom,
73 encodeUtf16(testKoreanCharSubset),
74 "encode UTF-16(BE by default) Korean");
75
76 Expect.listEquals(testKoreanCharSubsetUtf16le,
77 encodeUtf16le(testKoreanCharSubset),
78 "encode UTF-16LE Korean");
79 }
80
81 void testUtf16BytesToString() {
82 Expect.stringEquals("", decodeUtf16([]));
83 Expect.stringEquals(testHanWater, decodeUtf16([0x6C, 0x34]),
84 "Water variation 1");
85 Expect.stringEquals(testHanWater, decodeUtf16([0xFE, 0xFF, 0x6C, 0x34]),
86 "Water variation 2");
87 Expect.stringEquals(testHanWater, decodeUtf16([0xFF, 0xFE, 0x34, 0x6C]),
88 "Water variation 3");
89
90 Expect.stringEquals(testHanWater, decodeUtf16be([0x6C, 0x34]),
91 "Water variation 4");
92 Expect.stringEquals(testHanWater,
93 decodeUtf16be([0xFE, 0xFF, 0x6C, 0x34]),
94 "Water variation 5");
95
96 Expect.stringEquals(testHanWater, decodeUtf16le([0x34, 0x6C]),
97 "Water variation 6");
98 Expect.stringEquals(testHanWater,
99 decodeUtf16le([0xFF, 0xFE, 0x34, 0x6C]),
100 "Water variation 7");
101
102 Expect.stringEquals(testKoreanCharSubset,
103 decodeUtf16(testKoreanCharSubsetUtf16beBom), "UTF-16BE Korean");
104 }
105
106 void testIterableMethods() {
107 // empty input
108 Expect.isFalse(decodeUtf16AsIterable([]).iterator.moveNext());
109
110 IterableUtf16Decoder koreanDecoder =
111 decodeUtf16AsIterable(testKoreanCharSubsetUtf16beBom);
112 // get the first character
113 Expect.equals(testKoreanCharSubset.codeUnits[0], koreanDecoder.first);
114 // get the whole translation using the Iterable interface
115 Expect.stringEquals(testKoreanCharSubset,
116 new String.fromCharCodes(new List<int>.from(koreanDecoder)));
117
118 // specify types
119 Expect.equals(44032, (new List<int>
120 .from(decodeUtf16beAsIterable(testKoreanCharSubsetUtf16beBom)))[0]);
121 Expect.equals(44032, (new List<int>
122 .from(decodeUtf16leAsIterable(testKoreanCharSubsetUtf16le)))[0]);
123 bool stripBom = false;
124 Expect.equals(UNICODE_BOM, (new List<int>
125 .from(decodeUtf16beAsIterable(testKoreanCharSubsetUtf16beBom,
126 0, null, stripBom)))[0]);
floitsch 2013/11/18 17:08:17 needed to change from named to positional argument
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698