| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 utf8_test; | 5 library utf8_tests; |
| 6 import "package:expect/expect.dart"; | |
| 7 import 'dart:convert'; | |
| 8 | 6 |
| 9 // Google favorite: "Îñţérñåţîöñåļîžåţîờñ". | 7 // Google favorite: "Îñţérñåţîöñåļîžåţîờñ". |
| 10 const INTER_BYTES = const [0xc3, 0x8e, 0xc3, 0xb1, 0xc5, 0xa3, 0xc3, 0xa9, 0x72, | 8 const INTER_BYTES = const [0xc3, 0x8e, 0xc3, 0xb1, 0xc5, 0xa3, 0xc3, 0xa9, 0x72, |
| 11 0xc3, 0xb1, 0xc3, 0xa5, 0xc5, 0xa3, 0xc3, 0xae, 0xc3, | 9 0xc3, 0xb1, 0xc3, 0xa5, 0xc5, 0xa3, 0xc3, 0xae, 0xc3, |
| 12 0xb6, 0xc3, 0xb1, 0xc3, 0xa5, 0xc4, 0xbc, 0xc3, 0xae, | 10 0xb6, 0xc3, 0xb1, 0xc3, 0xa5, 0xc4, 0xbc, 0xc3, 0xae, |
| 13 0xc5, 0xbe, 0xc3, 0xa5, 0xc5, 0xa3, 0xc3, 0xae, 0xe1, | 11 0xc5, 0xbe, 0xc3, 0xa5, 0xc5, 0xa3, 0xc3, 0xae, 0xe1, |
| 14 0xbb, 0x9d, 0xc3, 0xb1]; | 12 0xbb, 0x9d, 0xc3, 0xb1]; |
| 15 const INTER_STRING = "Îñţérñåţîöñåļîžåţîờñ"; | 13 const INTER_STRING = "Îñţérñåţîöñåļîžåţîờñ"; |
| 16 | 14 |
| 17 // Blueberry porridge in Danish: "blåbærgrød". | 15 // Blueberry porridge in Danish: "blåbærgrød". |
| (...skipping 22 matching lines...) Expand all Loading... |
| 40 | 38 |
| 41 const DIGIT_BYTES = const [ 0x35 ]; | 39 const DIGIT_BYTES = const [ 0x35 ]; |
| 42 const DIGIT_STRING = "5"; | 40 const DIGIT_STRING = "5"; |
| 43 | 41 |
| 44 const ASCII_BYTES = const [ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, | 42 const ASCII_BYTES = const [ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
| 45 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, | 43 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, |
| 46 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, | 44 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
| 47 0x79, 0x7A ]; | 45 0x79, 0x7A ]; |
| 48 const ASCII_STRING = "abcdefghijklmnopqrstuvwxyz"; | 46 const ASCII_STRING = "abcdefghijklmnopqrstuvwxyz"; |
| 49 | 47 |
| 50 const TESTS = const [ | 48 const _TEST_PAIRS = const [ |
| 51 const [ const [], "" ], | 49 const [ const [], "" ], |
| 52 const [ INTER_BYTES, INTER_STRING ], | 50 const [ INTER_BYTES, INTER_STRING ], |
| 53 const [ BLUEBERRY_BYTES, BLUEBERRY_STRING ], | 51 const [ BLUEBERRY_BYTES, BLUEBERRY_STRING ], |
| 54 const [ SIVA_BYTES1, SIVA_STRING1 ], | 52 const [ SIVA_BYTES1, SIVA_STRING1 ], |
| 55 const [ SIVA_BYTES2, SIVA_STRING2 ], | 53 const [ SIVA_BYTES2, SIVA_STRING2 ], |
| 56 const [ BEE_BYTES, BEE_STRING ], | 54 const [ BEE_BYTES, BEE_STRING ], |
| 57 const [ DIGIT_BYTES, DIGIT_STRING ], | 55 const [ DIGIT_BYTES, DIGIT_STRING ], |
| 58 const [ ASCII_BYTES, ASCII_STRING ]]; | 56 const [ ASCII_BYTES, ASCII_STRING ]]; |
| 59 | 57 |
| 60 List<int> encode(String str) => new Utf8Encoder().convert(str); | 58 _expandTestPairs() { |
| 61 List<int> encode2(String str) => UTF8.encode(str); | 59 assert(2 == BEE_STRING.length); |
| 62 | 60 var tests = []; |
| 63 main() { | 61 tests.addAll(_TEST_PAIRS); |
| 64 Expect.equals(2, BEE_STRING.length); | 62 tests.addAll(_TEST_PAIRS.expand((test) { |
| 65 var tests = TESTS.expand((test) { | |
| 66 var bytes = test[0]; | 63 var bytes = test[0]; |
| 67 var string = test[1]; | 64 var string = test[1]; |
| 68 var longBytes = []; | 65 var longBytes = []; |
| 69 var longString = ""; | 66 var longString = ""; |
| 70 for (int i = 0; i < 100; i++) { | 67 for (int i = 0; i < 100; i++) { |
| 71 longBytes.addAll(bytes); | 68 longBytes.addAll(bytes); |
| 72 longString += string; | 69 longString += string; |
| 73 } | 70 } |
| 74 return [test, [longBytes, longString]]; | 71 return [test, [longBytes, longString]]; |
| 75 }); | 72 })); |
| 76 for (var test in tests) { | 73 return tests; |
| 77 List<int> bytes = test[0]; | |
| 78 String string = test[1]; | |
| 79 Expect.listEquals(bytes, encode(string)); | |
| 80 Expect.listEquals(bytes, encode2(string)); | |
| 81 } | |
| 82 } | 74 } |
| 75 |
| 76 final List UNICODE_TESTS = _expandTestPairs(); |
| OLD | NEW |