| 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:utf/utf.dart'; | 6 import 'dart:convert'; |
| 7 | 7 |
| 8 const String testEnglishPhrase = | 8 const String testEnglishPhrase = |
| 9 "The quick brown fox jumps over the lazy dog."; | 9 "The quick brown fox jumps over the lazy dog."; |
| 10 | 10 |
| 11 const List<int> testEnglishUtf8 = const<int> [ | 11 const List<int> testEnglishUtf8 = const<int> [ |
| 12 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, | 12 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, |
| 13 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, | 13 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, |
| 14 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, | 14 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, |
| 15 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, | 15 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, |
| 16 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, | 16 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 0x82, 0xa2, 0xe3, 0x82, 0xb5, 0xe3, 0x82, 0xad, | 109 0x82, 0xa2, 0xe3, 0x82, 0xb5, 0xe3, 0x82, 0xad, |
| 110 0xe3, 0x83, 0xa6, 0xe3, 0x83, 0xa1, 0xe3, 0x83, | 110 0xe3, 0x83, 0xa6, 0xe3, 0x83, 0xa1, 0xe3, 0x83, |
| 111 0x9f, 0xe3, 0x82, 0xb7, 0x20, 0xe3, 0x83, 0xb1, | 111 0x9f, 0xe3, 0x82, 0xb7, 0x20, 0xe3, 0x83, 0xb1, |
| 112 0xe3, 0x83, 0x92, 0xe3, 0x83, 0xa2, 0xe3, 0x82, | 112 0xe3, 0x83, 0x92, 0xe3, 0x83, 0xa2, 0xe3, 0x82, |
| 113 0xbb, 0xe3, 0x82, 0xb9, 0xe3, 0x83, 0xb3]; | 113 0xbb, 0xe3, 0x82, 0xb9, 0xe3, 0x83, 0xb3]; |
| 114 | 114 |
| 115 void main() { | 115 void main() { |
| 116 testUtf8bytesToCodepoints(); | 116 testUtf8bytesToCodepoints(); |
| 117 testUtf8BytesToString(); | 117 testUtf8BytesToString(); |
| 118 testEncodeToUtf8(); | 118 testEncodeToUtf8(); |
| 119 testIterableMethods(); | |
| 120 } | 119 } |
| 121 | 120 |
| 121 List<int> encodeUtf8(String str) => UTF8.encode(str); |
| 122 List<int> utf8ToRunes(List<int> codeUnits) { |
| 123 return UTF8.decode(codeUnits, allowMalformed: true).runes.toList(); |
| 124 } |
| 125 String decodeUtf8(List<int> codeUnits) => UTF8.decode(codeUnits); |
| 126 |
| 122 void testEncodeToUtf8() { | 127 void testEncodeToUtf8() { |
| 123 Expect.listEquals(testEnglishUtf8, encodeUtf8(testEnglishPhrase), | 128 Expect.listEquals(testEnglishUtf8, encodeUtf8(testEnglishPhrase), |
| 124 "english to utf8"); | 129 "english to utf8"); |
| 125 | 130 |
| 126 Expect.listEquals(testDanishUtf8, encodeUtf8(testDanishPhrase), | 131 Expect.listEquals(testDanishUtf8, encodeUtf8(testDanishPhrase), |
| 127 "encode danish to utf8"); | 132 "encode danish to utf8"); |
| 128 | 133 |
| 129 Expect.listEquals(testHebrewUtf8, encodeUtf8(testHebrewPhrase), | 134 Expect.listEquals(testHebrewUtf8, encodeUtf8(testHebrewPhrase), |
| 130 "Hebrew to utf8"); | 135 "Hebrew to utf8"); |
| 131 | 136 |
| 132 Expect.listEquals(testRussianUtf8, encodeUtf8(testRussianPhrase), | 137 Expect.listEquals(testRussianUtf8, encodeUtf8(testRussianPhrase), |
| 133 "Russian to utf8"); | 138 "Russian to utf8"); |
| 134 | 139 |
| 135 Expect.listEquals(testGreekUtf8, encodeUtf8(testGreekPhrase), | 140 Expect.listEquals(testGreekUtf8, encodeUtf8(testGreekPhrase), |
| 136 "Greek to utf8"); | 141 "Greek to utf8"); |
| 137 | 142 |
| 138 Expect.listEquals(testKatakanaUtf8, encodeUtf8(testKatakanaPhrase), | 143 Expect.listEquals(testKatakanaUtf8, encodeUtf8(testKatakanaPhrase), |
| 139 "Katakana to utf8"); | 144 "Katakana to utf8"); |
| 140 } | 145 } |
| 141 | 146 |
| 142 void testUtf8bytesToCodepoints() { | 147 void testUtf8bytesToCodepoints() { |
| 143 Expect.listEquals([954, 972, 963, 956, 949], | 148 Expect.listEquals([954, 972, 963, 956, 949], |
| 144 utf8ToCodepoints([0xce, 0xba, 0xcf, 0x8c, 0xcf, | 149 utf8ToRunes([0xce, 0xba, 0xcf, 0x8c, 0xcf, |
| 145 0x83, 0xce, 0xbc, 0xce, 0xb5]), "κόσμε"); | 150 0x83, 0xce, 0xbc, 0xce, 0xb5]), "κόσμε"); |
| 146 | 151 |
| 147 // boundary conditions: First possible sequence of a certain length | 152 // boundary conditions: First possible sequence of a certain length |
| 148 Expect.listEquals([], utf8ToCodepoints([]), "no input"); | 153 Expect.listEquals([], utf8ToRunes([]), "no input"); |
| 149 Expect.listEquals([0x0], utf8ToCodepoints([0x0]), "0"); | 154 Expect.listEquals([0x0], utf8ToRunes([0x0]), "0"); |
| 150 Expect.listEquals([0x80], utf8ToCodepoints([0xc2, 0x80]), "80"); | 155 Expect.listEquals([0x80], utf8ToRunes([0xc2, 0x80]), "80"); |
| 151 Expect.listEquals([0x800], | 156 Expect.listEquals([0x800], |
| 152 utf8ToCodepoints([0xe0, 0xa0, 0x80]), "800"); | 157 utf8ToRunes([0xe0, 0xa0, 0x80]), "800"); |
| 153 Expect.listEquals([0x10000], | 158 Expect.listEquals([0x10000], |
| 154 utf8ToCodepoints([0xf0, 0x90, 0x80, 0x80]), "10000"); | 159 utf8ToRunes([0xf0, 0x90, 0x80, 0x80]), "10000"); |
| 155 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 160 Expect.listEquals( |
| 156 utf8ToCodepoints([0xf8, 0x88, 0x80, 0x80, 0x80]), "200000"); | 161 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 157 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 162 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 158 utf8ToCodepoints([0xfc, 0x84, 0x80, 0x80, 0x80, 0x80]), | 163 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 164 utf8ToRunes([0xf8, 0x88, 0x80, 0x80, 0x80]), "200000"); |
| 165 Expect.listEquals( |
| 166 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 167 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 168 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 169 utf8ToRunes([0xfc, 0x84, 0x80, 0x80, 0x80, 0x80]), |
| 159 "4000000"); | 170 "4000000"); |
| 160 | 171 |
| 161 // boundary conditions: Last possible sequence of a certain length | 172 // boundary conditions: Last possible sequence of a certain length |
| 162 Expect.listEquals([0x7f], utf8ToCodepoints([0x7f]), "7f"); | 173 Expect.listEquals([0x7f], utf8ToRunes([0x7f]), "7f"); |
| 163 Expect.listEquals([0x7ff], utf8ToCodepoints([0xdf, 0xbf]), "7ff"); | 174 Expect.listEquals([0x7ff], utf8ToRunes([0xdf, 0xbf]), "7ff"); |
| 164 Expect.listEquals([0xffff], | 175 Expect.listEquals([0xffff], |
| 165 utf8ToCodepoints([0xef, 0xbf, 0xbf]), "ffff"); | 176 utf8ToRunes([0xef, 0xbf, 0xbf]), "ffff"); |
| 166 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 177 Expect.listEquals( |
| 167 utf8ToCodepoints([0xf7, 0xbf, 0xbf, 0xbf]), "1fffff"); | 178 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 168 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 179 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 169 utf8ToCodepoints([0xfb, 0xbf, 0xbf, 0xbf, 0xbf]), "3ffffff"); | 180 utf8ToRunes([0xf7, 0xbf, 0xbf, 0xbf]), "1fffff"); |
| 170 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 181 Expect.listEquals( |
| 171 utf8ToCodepoints([0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf]), | 182 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 183 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 184 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 185 utf8ToRunes([0xfb, 0xbf, 0xbf, 0xbf, 0xbf]), "3ffffff"); |
| 186 Expect.listEquals( |
| 187 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 188 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 189 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 190 utf8ToRunes([0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf]), |
| 172 "4000000"); | 191 "4000000"); |
| 173 | 192 |
| 174 // other boundary conditions | 193 // other boundary conditions |
| 175 Expect.listEquals([0xd7ff], | 194 Expect.listEquals([0xd7ff], |
| 176 utf8ToCodepoints([0xed, 0x9f, 0xbf]), "d7ff"); | 195 utf8ToRunes([0xed, 0x9f, 0xbf]), "d7ff"); |
| 177 Expect.listEquals([0xe000], | 196 Expect.listEquals([0xe000], |
| 178 utf8ToCodepoints([0xee, 0x80, 0x80]), "e000"); | 197 utf8ToRunes([0xee, 0x80, 0x80]), "e000"); |
| 179 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 198 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 180 utf8ToCodepoints([0xef, 0xbf, 0xbd]), "fffd"); | 199 utf8ToRunes([0xef, 0xbf, 0xbd]), "fffd"); |
| 181 Expect.listEquals([0x10ffff], | 200 Expect.listEquals([0x10ffff], |
| 182 utf8ToCodepoints([0xf4, 0x8f, 0xbf, 0xbf]), "10ffff"); | 201 utf8ToRunes([0xf4, 0x8f, 0xbf, 0xbf]), "10ffff"); |
| 183 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 202 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 184 utf8ToCodepoints([0xf4, 0x90, 0x80, 0x80]), "110000"); | 203 utf8ToRunes([0xf4, 0x90, 0x80, 0x80]), "110000"); |
| 185 | 204 |
| 186 // unexpected continuation bytes | 205 // unexpected continuation bytes |
| 187 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 206 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 188 utf8ToCodepoints([0x80]), "80 => replacement character"); | 207 utf8ToRunes([0x80]), "80 => replacement character"); |
| 189 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 208 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 190 utf8ToCodepoints([0xbf]), "bf => replacement character"); | 209 utf8ToRunes([0xbf]), "bf => replacement character"); |
| 191 | 210 |
| 192 List<int> allContinuationBytes = <int>[]; | 211 List<int> allContinuationBytes = <int>[]; |
| 193 List<int> matchingReplacementChars = <int>[]; | 212 List<int> matchingReplacementChars = <int>[]; |
| 194 for (int i = 0x80; i < 0xc0; i++) { | 213 for (int i = 0x80; i < 0xc0; i++) { |
| 195 allContinuationBytes.add(i); | 214 allContinuationBytes.add(i); |
| 196 matchingReplacementChars.add(UNICODE_REPLACEMENT_CHARACTER_CODEPOINT); | 215 matchingReplacementChars.add(UNICODE_REPLACEMENT_CHARACTER_RUNE); |
| 197 } | 216 } |
| 198 Expect.listEquals(matchingReplacementChars, | 217 Expect.listEquals(matchingReplacementChars, |
| 199 utf8ToCodepoints(allContinuationBytes), | 218 utf8ToRunes(allContinuationBytes), |
| 200 "80 - bf => replacement character x 64"); | 219 "80 - bf => replacement character x 64"); |
| 201 | 220 |
| 202 List<int> allFirstTwoByteSeq = <int>[]; | 221 List<int> allFirstTwoByteSeq = <int>[]; |
| 203 matchingReplacementChars = <int>[]; | 222 matchingReplacementChars = <int>[]; |
| 204 for (int i = 0xc0; i < 0xe0; i++) { | 223 for (int i = 0xc0; i < 0xe0; i++) { |
| 205 allFirstTwoByteSeq.addAll([i, 0x20]); | 224 allFirstTwoByteSeq.addAll([i, 0x20]); |
| 206 matchingReplacementChars.addAll( | 225 matchingReplacementChars.addAll( |
| 207 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 226 [UNICODE_REPLACEMENT_CHARACTER_RUNE, 0x20]); |
| 208 } | 227 } |
| 209 Expect.listEquals(matchingReplacementChars, | 228 Expect.listEquals(matchingReplacementChars, |
| 210 utf8ToCodepoints(allFirstTwoByteSeq), | 229 utf8ToRunes(allFirstTwoByteSeq), |
| 211 "c0 - df + space => replacement character + space x 32"); | 230 "c0 - df + space => replacement character + space x 32"); |
| 212 | 231 |
| 213 List<int> allFirstThreeByteSeq = <int>[]; | 232 List<int> allFirstThreeByteSeq = <int>[]; |
| 214 matchingReplacementChars = <int>[]; | 233 matchingReplacementChars = <int>[]; |
| 215 for (int i = 0xe0; i < 0xf0; i++) { | 234 for (int i = 0xe0; i < 0xf0; i++) { |
| 216 allFirstThreeByteSeq.addAll([i, 0x20]); | 235 allFirstThreeByteSeq.addAll([i, 0x20]); |
| 217 matchingReplacementChars.addAll( | 236 matchingReplacementChars.addAll( |
| 218 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 237 [UNICODE_REPLACEMENT_CHARACTER_RUNE, 0x20]); |
| 219 } | 238 } |
| 220 Expect.listEquals(matchingReplacementChars, | 239 Expect.listEquals(matchingReplacementChars, |
| 221 utf8ToCodepoints(allFirstThreeByteSeq), | 240 utf8ToRunes(allFirstThreeByteSeq), |
| 222 "e0 - ef + space => replacement character x 16"); | 241 "e0 - ef + space => replacement character x 16"); |
| 223 | 242 |
| 224 List<int> allFirstFourByteSeq = <int>[]; | 243 List<int> allFirstFourByteSeq = <int>[]; |
| 225 matchingReplacementChars = <int>[]; | 244 matchingReplacementChars = <int>[]; |
| 226 for (int i = 0xf0; i < 0xf8; i++) { | 245 for (int i = 0xf0; i < 0xf8; i++) { |
| 227 allFirstFourByteSeq.addAll([i, 0x20]); | 246 allFirstFourByteSeq.addAll([i, 0x20]); |
| 228 matchingReplacementChars.addAll( | 247 matchingReplacementChars.addAll( |
| 229 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 248 [UNICODE_REPLACEMENT_CHARACTER_RUNE, 0x20]); |
| 230 } | 249 } |
| 231 Expect.listEquals(matchingReplacementChars, | 250 Expect.listEquals(matchingReplacementChars, |
| 232 utf8ToCodepoints(allFirstFourByteSeq), | 251 utf8ToRunes(allFirstFourByteSeq), |
| 233 "f0 - f7 + space => replacement character x 8"); | 252 "f0 - f7 + space => replacement character x 8"); |
| 234 | 253 |
| 235 List<int> allFirstFiveByteSeq = <int>[]; | 254 List<int> allFirstFiveByteSeq = <int>[]; |
| 236 matchingReplacementChars = <int>[]; | 255 matchingReplacementChars = <int>[]; |
| 237 for (int i = 0xf8; i < 0xfc; i++) { | 256 for (int i = 0xf8; i < 0xfc; i++) { |
| 238 allFirstFiveByteSeq.addAll([i, 0x20]); | 257 allFirstFiveByteSeq.addAll([i, 0x20]); |
| 239 matchingReplacementChars.addAll( | 258 matchingReplacementChars.addAll( |
| 240 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 259 [UNICODE_REPLACEMENT_CHARACTER_RUNE, 0x20]); |
| 241 } | 260 } |
| 242 Expect.listEquals(matchingReplacementChars, | 261 Expect.listEquals(matchingReplacementChars, |
| 243 utf8ToCodepoints(allFirstFiveByteSeq), | 262 utf8ToRunes(allFirstFiveByteSeq), |
| 244 "f8 - fb + space => replacement character x 4"); | 263 "f8 - fb + space => replacement character x 4"); |
| 245 | 264 |
| 246 List<int> allFirstSixByteSeq = <int>[]; | 265 List<int> allFirstSixByteSeq = <int>[]; |
| 247 matchingReplacementChars = <int>[]; | 266 matchingReplacementChars = <int>[]; |
| 248 for (int i = 0xfc; i < 0xfe; i++) { | 267 for (int i = 0xfc; i < 0xfe; i++) { |
| 249 allFirstSixByteSeq.addAll([i, 0x20]); | 268 allFirstSixByteSeq.addAll([i, 0x20]); |
| 250 matchingReplacementChars.addAll( | 269 matchingReplacementChars.addAll( |
| 251 [UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 270 [UNICODE_REPLACEMENT_CHARACTER_RUNE, 0x20]); |
| 252 } | 271 } |
| 253 Expect.listEquals(matchingReplacementChars, | 272 Expect.listEquals(matchingReplacementChars, |
| 254 utf8ToCodepoints(allFirstSixByteSeq), | 273 utf8ToRunes(allFirstSixByteSeq), |
| 255 "fc - fd + space => replacement character x 2"); | 274 "fc - fd + space => replacement character x 2"); |
| 256 | 275 |
| 257 // Sequences with last continuation byte missing | 276 // Sequences with last continuation byte missing |
| 258 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 277 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 259 utf8ToCodepoints([0xc2]), | 278 utf8ToRunes([0xc2]), |
| 260 "2-byte sequence with last byte missing"); | 279 "2-byte sequence with last byte missing"); |
| 261 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 280 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 262 utf8ToCodepoints([0xe0, 0x80]), | 281 utf8ToRunes([0xe0, 0x80]), |
| 263 "3-byte sequence with last byte missing"); | 282 "3-byte sequence with last byte missing"); |
| 264 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 283 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 265 utf8ToCodepoints([0xf0, 0x80, 0x80]), | 284 utf8ToRunes([0xf0, 0x80, 0x80]), |
| 266 "4-byte sequence with last byte missing"); | 285 "4-byte sequence with last byte missing"); |
| 267 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 286 Expect.listEquals( |
| 268 utf8ToCodepoints([0xf8, 0x88, 0x80, 0x80]), | 287 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 288 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 289 utf8ToRunes([0xf8, 0x88, 0x80, 0x80]), |
| 269 "5-byte sequence with last byte missing"); | 290 "5-byte sequence with last byte missing"); |
| 270 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 291 Expect.listEquals( |
| 271 utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80]), | 292 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 293 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 294 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 295 utf8ToRunes([0xfc, 0x80, 0x80, 0x80, 0x80]), |
| 272 "6-byte sequence with last byte missing"); | 296 "6-byte sequence with last byte missing"); |
| 273 | 297 |
| 274 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 298 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 275 utf8ToCodepoints([0xdf]), | 299 utf8ToRunes([0xdf]), |
| 276 "2-byte sequence with last byte missing (hi)"); | 300 "2-byte sequence with last byte missing (hi)"); |
| 277 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 301 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 278 utf8ToCodepoints([0xef, 0xbf]), | 302 utf8ToRunes([0xef, 0xbf]), |
| 279 "3-byte sequence with last byte missing (hi)"); | 303 "3-byte sequence with last byte missing (hi)"); |
| 280 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 304 Expect.listEquals( |
| 281 utf8ToCodepoints([0xf7, 0xbf, 0xbf]), | 305 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 306 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 307 utf8ToRunes([0xf7, 0xbf, 0xbf]), |
| 282 "4-byte sequence with last byte missing (hi)"); | 308 "4-byte sequence with last byte missing (hi)"); |
| 283 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 309 Expect.listEquals( |
| 284 utf8ToCodepoints([0xfb, 0xbf, 0xbf, 0xbf]), | 310 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 311 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 312 utf8ToRunes([0xfb, 0xbf, 0xbf, 0xbf]), |
| 285 "5-byte sequence with last byte missing (hi)"); | 313 "5-byte sequence with last byte missing (hi)"); |
| 286 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 314 Expect.listEquals( |
| 287 utf8ToCodepoints([0xfd, 0xbf, 0xbf, 0xbf, 0xbf]), | 315 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 316 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 317 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 318 utf8ToRunes([0xfd, 0xbf, 0xbf, 0xbf, 0xbf]), |
| 288 "6-byte sequence with last byte missing (hi)"); | 319 "6-byte sequence with last byte missing (hi)"); |
| 289 | 320 |
| 290 // Concatenation of incomplete sequences | 321 // Concatenation of incomplete sequences |
| 291 Expect.listEquals( | 322 Expect.listEquals( |
| 292 [ UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 323 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 293 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 324 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 294 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 325 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 295 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 326 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 296 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 327 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 297 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 328 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 298 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 329 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 299 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 330 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 300 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 331 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 301 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT ], | 332 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 302 utf8ToCodepoints( | 333 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 334 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 335 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 336 utf8ToRunes( |
| 303 [ 0xc2, | 337 [ 0xc2, |
| 304 0xe0, 0x80, | 338 0xe0, 0x80, |
| 305 0xf0, 0x80, 0x80, | 339 0xf0, 0x80, 0x80, |
| 306 0xf8, 0x88, 0x80, 0x80, | 340 0xf8, 0x88, 0x80, 0x80, |
| 307 0xfc, 0x80, 0x80, 0x80, 0x80, | 341 0xfc, 0x80, 0x80, 0x80, 0x80, |
| 308 0xdf, | 342 0xdf, |
| 309 0xef, 0xbf, | 343 0xef, 0xbf, |
| 310 0xf7, 0xbf, 0xbf, | 344 0xf7, 0xbf, 0xbf, |
| 311 0xfb, 0xbf, 0xbf, 0xbf, | 345 0xfb, 0xbf, 0xbf, 0xbf, |
| 312 0xfd, 0xbf, 0xbf, 0xbf, 0xbf ]), | 346 0xfd, 0xbf, 0xbf, 0xbf, 0xbf ]), |
| 313 "Concatenation of incomplete sequences"); | 347 "Concatenation of incomplete sequences"); |
| 314 | 348 |
| 315 // Impossible bytes | 349 // Impossible bytes |
| 316 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 350 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 317 utf8ToCodepoints([0xfe]), "fe"); | 351 utf8ToRunes([0xfe]), "fe"); |
| 318 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 352 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 319 utf8ToCodepoints([0xff]), "ff"); | 353 utf8ToRunes([0xff]), "ff"); |
| 320 Expect.listEquals([ | 354 Expect.listEquals([ |
| 321 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 355 UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 322 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 356 UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 323 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | 357 UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 324 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 358 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 325 utf8ToCodepoints([0xfe, 0xfe, 0xff, 0xff]), "fe fe ff ff"); | 359 utf8ToRunes([0xfe, 0xfe, 0xff, 0xff]), "fe fe ff ff"); |
| 326 | 360 |
| 327 // Overlong sequences | 361 // Overlong sequences |
| 328 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 362 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 329 utf8ToCodepoints([0xc0, 0xaf]), "c0 af"); | 363 utf8ToRunes([0xc0, 0xaf]), "c0 af"); |
| 330 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 364 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 331 utf8ToCodepoints([0xe0, 0x80, 0xaf]), "e0 80 af"); | 365 utf8ToRunes([0xe0, 0x80, 0xaf]), "e0 80 af"); |
| 332 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 366 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 333 utf8ToCodepoints([0xf0, 0x80, 0x80, 0xaf]), "f0 80 80 af"); | 367 utf8ToRunes([0xf0, 0x80, 0x80, 0xaf]), "f0 80 80 af"); |
| 334 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 368 Expect.listEquals( |
| 335 utf8ToCodepoints([0xf8, 0x80, 0x80, 0x80, 0xaf]), "f8 80 80 80 af"); | 369 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 336 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 370 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 337 utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80, 0xaf]), | 371 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 372 utf8ToRunes([0xf8, 0x80, 0x80, 0x80, 0xaf]), "f8 80 80 80 af"); |
| 373 Expect.listEquals( |
| 374 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 375 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 376 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 377 utf8ToRunes([0xfc, 0x80, 0x80, 0x80, 0x80, 0xaf]), |
| 338 "fc 80 80 80 80 af"); | 378 "fc 80 80 80 80 af"); |
| 339 | 379 |
| 340 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 380 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 341 utf8ToCodepoints([0xc1, 0xbf]), "c1 bf"); | 381 utf8ToRunes([0xc1, 0xbf]), "c1 bf"); |
| 342 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 382 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 343 utf8ToCodepoints([0xe0, 0x9f, 0xbf]), "e0 9f bf"); | 383 utf8ToRunes([0xe0, 0x9f, 0xbf]), "e0 9f bf"); |
| 344 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 384 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 345 utf8ToCodepoints([0xf0, 0x8f, 0xbf, 0xbf]), "f0 8f bf bf"); | 385 utf8ToRunes([0xf0, 0x8f, 0xbf, 0xbf]), "f0 8f bf bf"); |
| 346 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 386 Expect.listEquals( |
| 347 utf8ToCodepoints([0xf8, 0x87, 0xbf, 0xbf, 0xbf]), "f8 87 bf bf bf"); | 387 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 348 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 388 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 349 utf8ToCodepoints([0xfc, 0x83, 0xbf, 0xbf, 0xbf, 0xbf]), | 389 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 390 utf8ToRunes([0xf8, 0x87, 0xbf, 0xbf, 0xbf]), "f8 87 bf bf bf"); |
| 391 Expect.listEquals( |
| 392 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 393 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 394 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 395 utf8ToRunes([0xfc, 0x83, 0xbf, 0xbf, 0xbf, 0xbf]), |
| 350 "fc 83 bf bf bf bf"); | 396 "fc 83 bf bf bf bf"); |
| 351 | 397 |
| 352 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 398 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 353 utf8ToCodepoints([0xc0, 0x80]), "c0 80"); | 399 utf8ToRunes([0xc0, 0x80]), "c0 80"); |
| 354 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 400 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 355 utf8ToCodepoints([0xe0, 0x80, 0x80]), "e0 80 80"); | 401 utf8ToRunes([0xe0, 0x80, 0x80]), "e0 80 80"); |
| 356 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 402 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 357 utf8ToCodepoints([0xf0, 0x80, 0x80, 0x80]), "f0 80 80 80"); | 403 utf8ToRunes([0xf0, 0x80, 0x80, 0x80]), "f0 80 80 80"); |
| 358 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 404 Expect.listEquals( |
| 359 utf8ToCodepoints([0xf8, 0x80, 0x80, 0x80, 0x80]), "f8 80 80 80 80"); | 405 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 360 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | 406 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 361 utf8ToCodepoints([0xfc, 0x80, 0x80, 0x80, 0x80, 0x80]), | 407 UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 408 utf8ToRunes([0xf8, 0x80, 0x80, 0x80, 0x80]), "f8 80 80 80 80"); |
| 409 Expect.listEquals( |
| 410 [UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 411 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE, |
| 412 UNICODE_REPLACEMENT_CHARACTER_RUNE, UNICODE_REPLACEMENT_CHARACTER_RUNE], |
| 413 utf8ToRunes([0xfc, 0x80, 0x80, 0x80, 0x80, 0x80]), |
| 362 "fc 80 80 80 80 80"); | 414 "fc 80 80 80 80 80"); |
| 363 | 415 |
| 364 // Illegal code positions | |
| 365 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 366 utf8ToCodepoints([0xed, 0xa0, 0x80]), "U+D800"); | |
| 367 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 368 utf8ToCodepoints([0xed, 0xad, 0xbf]), "U+DB7F"); | |
| 369 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 370 utf8ToCodepoints([0xed, 0xae, 0x80]), "U+DB80"); | |
| 371 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 372 utf8ToCodepoints([0xed, 0xaf, 0xbf]), "U+DBFF"); | |
| 373 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 374 utf8ToCodepoints([0xed, 0xb0, 0x80]), "U+DC00"); | |
| 375 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 376 utf8ToCodepoints([0xed, 0xbe, 0x80]), "U+DF80"); | |
| 377 Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 378 utf8ToCodepoints([0xed, 0xbf, 0xbf]), "U+DFFF"); | |
| 379 | |
| 380 // Paired UTF-16 surrogates | |
| 381 Expect.listEquals([ | |
| 382 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 383 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 384 utf8ToCodepoints([0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80]), | |
| 385 "U+D800 U+DC00"); | |
| 386 Expect.listEquals([ | |
| 387 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 388 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 389 utf8ToCodepoints([0xed, 0xa0, 0x80, 0xed, 0xbf, 0xbf]), | |
| 390 "U+D800 U+DFFF"); | |
| 391 Expect.listEquals([ | |
| 392 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 393 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 394 utf8ToCodepoints([0xed, 0xad, 0xbf, 0xed, 0xb0, 0x80]), | |
| 395 "U+DB7F U+DC00"); | |
| 396 Expect.listEquals([ | |
| 397 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 398 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 399 utf8ToCodepoints([0xed, 0xad, 0xbf, 0xed, 0xbf, 0xbf]), | |
| 400 "U+DB7F U+DFFF"); | |
| 401 Expect.listEquals([ | |
| 402 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 403 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 404 utf8ToCodepoints([0xed, 0xae, 0x80, 0xed, 0xb0, 0x80]), | |
| 405 "U+DB80 U+DC00"); | |
| 406 Expect.listEquals([ | |
| 407 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 408 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 409 utf8ToCodepoints([0xed, 0xae, 0x80, 0xed, 0xbf, 0xbf]), | |
| 410 "U+DB80 U+DFFF"); | |
| 411 Expect.listEquals([ | |
| 412 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 413 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 414 utf8ToCodepoints([0xed, 0xaf, 0xbf, 0xed, 0xb0, 0x80]), | |
| 415 "U+DBFF U+DC00"); | |
| 416 Expect.listEquals([ | |
| 417 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT, | |
| 418 UNICODE_REPLACEMENT_CHARACTER_CODEPOINT], | |
| 419 utf8ToCodepoints([0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf]), | |
| 420 "U+DBFF U+DFFF"); | |
| 421 | |
| 422 // Other illegal code positions (???) | 416 // Other illegal code positions (???) |
| 423 Expect.listEquals([0xfffe], utf8ToCodepoints([0xef, 0xbf, 0xbe]), | 417 Expect.listEquals([0xfffe], utf8ToRunes([0xef, 0xbf, 0xbe]), |
| 424 "U+FFFE"); | 418 "U+FFFE"); |
| 425 Expect.listEquals([0xffff], utf8ToCodepoints([0xef, 0xbf, 0xbf]), | 419 Expect.listEquals([0xffff], utf8ToRunes([0xef, 0xbf, 0xbf]), |
| 426 "U+FFFF"); | 420 "U+FFFF"); |
| 427 } | 421 } |
| 428 | 422 |
| 429 void testUtf8BytesToString() { | 423 void testUtf8BytesToString() { |
| 430 Expect.stringEquals(testEnglishPhrase, | 424 Expect.stringEquals(testEnglishPhrase, |
| 431 decodeUtf8(testEnglishUtf8), "English"); | 425 decodeUtf8(testEnglishUtf8), "English"); |
| 432 | 426 |
| 433 Expect.stringEquals(testDanishPhrase, | 427 Expect.stringEquals(testDanishPhrase, |
| 434 decodeUtf8(testDanishUtf8), "Danish"); | 428 decodeUtf8(testDanishUtf8), "Danish"); |
| 435 | 429 |
| 436 Expect.stringEquals(testHebrewPhrase, | 430 Expect.stringEquals(testHebrewPhrase, |
| 437 decodeUtf8(testHebrewUtf8), "Hebrew"); | 431 decodeUtf8(testHebrewUtf8), "Hebrew"); |
| 438 | 432 |
| 439 Expect.stringEquals(testRussianPhrase, | 433 Expect.stringEquals(testRussianPhrase, |
| 440 decodeUtf8(testRussianUtf8), "Russian"); | 434 decodeUtf8(testRussianUtf8), "Russian"); |
| 441 | 435 |
| 442 Expect.stringEquals(testGreekPhrase, | 436 Expect.stringEquals(testGreekPhrase, |
| 443 decodeUtf8(testGreekUtf8), "Greek"); | 437 decodeUtf8(testGreekUtf8), "Greek"); |
| 444 | 438 |
| 445 Expect.stringEquals(testKatakanaPhrase, | 439 Expect.stringEquals(testKatakanaPhrase, |
| 446 decodeUtf8(testKatakanaUtf8), "Katakana"); | 440 decodeUtf8(testKatakanaUtf8), "Katakana"); |
| 447 } | 441 } |
| 448 | |
| 449 void testIterableMethods() { | |
| 450 IterableUtf8Decoder englishDecoder = decodeUtf8AsIterable(testEnglishUtf8); | |
| 451 // get the first character | |
| 452 Expect.equals(testEnglishUtf8[0], englishDecoder.first); | |
| 453 // get the whole translation using the Iterable interface | |
| 454 Expect.stringEquals(testEnglishPhrase, | |
| 455 new String.fromCharCodes(new List<int>.from(englishDecoder))); | |
| 456 | |
| 457 IterableUtf8Decoder kataDecoder = decodeUtf8AsIterable(testKatakanaUtf8); | |
| 458 // get the first character | |
| 459 Expect.equals(testKatakanaPhrase.codeUnits[0], kataDecoder.first); | |
| 460 // get the whole translation using the Iterable interface | |
| 461 Expect.stringEquals(testKatakanaPhrase, | |
| 462 new String.fromCharCodes(new List<int>.from(kataDecoder))); | |
| 463 } | |
| OLD | NEW |