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