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