| 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 utf8_test; | 5 library utf8_test; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 String decode(List<int> bytes) => new Utf8Decoder().convert(bytes); | 9 String decode(List<int> bytes) => new Utf8Decoder().convert(bytes); |
| 10 String decodeAllowMalformed(List<int> bytes) { | 10 String decodeAllowMalformed(List<int> bytes) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 [ 0xF9 ], | 43 [ 0xF9 ], |
| 44 [ 0xFA ], | 44 [ 0xFA ], |
| 45 [ 0xFB ], | 45 [ 0xFB ], |
| 46 [ 0xFC ], | 46 [ 0xFC ], |
| 47 [ 0xFD ], | 47 [ 0xFD ], |
| 48 [ 0xFE ], | 48 [ 0xFE ], |
| 49 [ 0xFF ], | 49 [ 0xFF ], |
| 50 [ 0xC0, 0x80 ], | 50 [ 0xC0, 0x80 ], |
| 51 [ 0xC1, 0x80 ], | 51 [ 0xC1, 0x80 ], |
| 52 // Outside valid range. | 52 // Outside valid range. |
| 53 [ 0xF4, 0xBF, 0xBF, 0xBF ]]; | 53 [ 0xF4, 0xBF, 0xBF, 0xBF ], |
| 54 // Negative |
| 55 [ -0x01 ], |
| 56 [ -0xFF ], |
| 57 [ -0x80000000 ], |
| 58 [ -0x40000000 ], |
| 59 [ -0x80000000000000000]]; |
| 54 | 60 |
| 55 final TESTS2 = [ | 61 final TESTS2 = [ |
| 56 // Test that 0xC0|1, 0x80 does not eat the next character. | 62 // Test that 0xC0|1, 0x80 does not eat the next character. |
| 57 [[ 0xC0, 0x80, 0x61 ], "Xa" ], | 63 [[ 0xC0, 0x80, 0x61 ], "Xa" ], |
| 58 [[ 0xC1, 0x80, 0x61 ], "Xa" ], | 64 [[ 0xC1, 0x80, 0x61 ], "Xa" ], |
| 59 // 0xF5 .. 0xFF never appear in valid UTF-8 sequences. | 65 // 0xF5 .. 0xFF never appear in valid UTF-8 sequences. |
| 60 [[ 0xF5, 0x80 ], "XX" ], | 66 [[ 0xF5, 0x80 ], "XX" ], |
| 61 [[ 0xF6, 0x80 ], "XX" ], | 67 [[ 0xF6, 0x80 ], "XX" ], |
| 62 [[ 0xF7, 0x80 ], "XX" ], | 68 [[ 0xF7, 0x80 ], "XX" ], |
| 63 [[ 0xF8, 0x80 ], "XX" ], | 69 [[ 0xF8, 0x80 ], "XX" ], |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 Expect.throws(() => decode3(bytes), (e) => e is FormatException); | 131 Expect.throws(() => decode3(bytes), (e) => e is FormatException); |
| 126 Expect.throws(() => decode4(bytes), (e) => e is FormatException); | 132 Expect.throws(() => decode4(bytes), (e) => e is FormatException); |
| 127 | 133 |
| 128 String expected = test[1]; | 134 String expected = test[1]; |
| 129 Expect.equals(expected, decodeAllowMalformed(bytes)); | 135 Expect.equals(expected, decodeAllowMalformed(bytes)); |
| 130 Expect.equals(expected, decodeAllowMalformed2(bytes)); | 136 Expect.equals(expected, decodeAllowMalformed2(bytes)); |
| 131 Expect.equals(expected, decodeAllowMalformed3(bytes)); | 137 Expect.equals(expected, decodeAllowMalformed3(bytes)); |
| 132 Expect.equals(expected, decodeAllowMalformed4(bytes)); | 138 Expect.equals(expected, decodeAllowMalformed4(bytes)); |
| 133 } | 139 } |
| 134 } | 140 } |
| OLD | NEW |