| 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 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 String decode(List<int> bytes) => new Utf8Decoder().convert(bytes); | 10 String decode(List<int> bytes) => new Utf8Decoder().convert(bytes); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 ] | 206 ] |
| 207 ]; | 207 ]; |
| 208 | 208 |
| 209 main() { | 209 main() { |
| 210 var allTests = TESTS.expand((test) { | 210 var allTests = TESTS.expand((test) { |
| 211 // Pairs of test and expected string output when malformed strings are | 211 // Pairs of test and expected string output when malformed strings are |
| 212 // allowed. Replacement character: U+FFFD | 212 // allowed. Replacement character: U+FFFD |
| 213 return [ | 213 return [ |
| 214 [test, "\u{FFFD}"], | 214 [test, "\u{FFFD}"], |
| 215 [ | 215 [ |
| 216 new List.from([0x61])..addAll(test), | 216 new List<int>.from([0x61])..addAll(test), |
| 217 "a\u{FFFD}" | 217 "a\u{FFFD}" |
| 218 ], | 218 ], |
| 219 [ | 219 [ |
| 220 new List.from([0x61]) | 220 new List<int>.from([0x61]) |
| 221 ..addAll(test) | 221 ..addAll(test) |
| 222 ..add(0x61), | 222 ..add(0x61), |
| 223 "a\u{FFFD}a" | 223 "a\u{FFFD}a" |
| 224 ], | 224 ], |
| 225 [new List.from(test)..add(0x61), "\u{FFFD}a"], | 225 [new List<int>.from(test)..add(0x61), "\u{FFFD}a"], |
| 226 [new List.from(test)..addAll(test), "\u{FFFD}\u{FFFD}"], | 226 [new List<int>.from(test)..addAll(test), "\u{FFFD}\u{FFFD}"], |
| 227 [ | 227 [ |
| 228 new List.from(test) | 228 new List<int>.from(test) |
| 229 ..add(0x61) | 229 ..add(0x61) |
| 230 ..addAll(test), | 230 ..addAll(test), |
| 231 "\u{FFFD}a\u{FFFD}" | 231 "\u{FFFD}a\u{FFFD}" |
| 232 ], | 232 ], |
| 233 [ | 233 [ |
| 234 new List.from([0xc3, 0xa5])..addAll(test), | 234 new List<int>.from([0xc3, 0xa5])..addAll(test), |
| 235 "å\u{FFFD}" | 235 "å\u{FFFD}" |
| 236 ], | 236 ], |
| 237 [ | 237 [ |
| 238 new List.from([0xc3, 0xa5])..addAll(test)..addAll([0xc3, 0xa5]), | 238 new List<int>.from([0xc3, 0xa5])..addAll(test)..addAll([0xc3, 0xa5]), |
| 239 "å\u{FFFD}å" | 239 "å\u{FFFD}å" |
| 240 ], | 240 ], |
| 241 [ | 241 [ |
| 242 new List.from(test)..addAll([0xc3, 0xa5]), | 242 new List<int>.from(test)..addAll([0xc3, 0xa5]), |
| 243 "\u{FFFD}å" | 243 "\u{FFFD}å" |
| 244 ], | 244 ], |
| 245 [ | 245 [ |
| 246 new List.from(test)..addAll([0xc3, 0xa5])..addAll(test), | 246 new List<int>.from(test)..addAll([0xc3, 0xa5])..addAll(test), |
| 247 "\u{FFFD}å\u{FFFD}" | 247 "\u{FFFD}å\u{FFFD}" |
| 248 ] | 248 ] |
| 249 ]; | 249 ]; |
| 250 }); | 250 }); |
| 251 | 251 |
| 252 var allTests2 = TESTS2.map((test) { | 252 var allTests2 = TESTS2.map((test) { |
| 253 // Pairs of test and expected string output when malformed strings are | 253 // Pairs of test and expected string output when malformed strings are |
| 254 // allowed. Replacement character: U+FFFD | 254 // allowed. Replacement character: U+FFFD |
| 255 String expected = (test[1] as String).replaceAll("X", "\u{FFFD}"); | 255 String expected = (test[1] as String).replaceAll("X", "\u{FFFD}"); |
| 256 return [test[0], expected]; | 256 return [test[0], expected]; |
| 257 }); | 257 }); |
| 258 | 258 |
| 259 for (var test in []..addAll(allTests)..addAll(allTests2)) { | 259 for (var test in []..addAll(allTests)..addAll(allTests2)) { |
| 260 List<int> bytes = test[0]; | 260 List<int> bytes = test[0]; |
| 261 Expect.throws(() => decode(bytes), (e) => e is FormatException); | 261 Expect.throws(() => decode(bytes), (e) => e is FormatException); |
| 262 Expect.throws(() => decode2(bytes), (e) => e is FormatException); | 262 Expect.throws(() => decode2(bytes), (e) => e is FormatException); |
| 263 Expect.throws(() => decode3(bytes), (e) => e is FormatException); | 263 Expect.throws(() => decode3(bytes), (e) => e is FormatException); |
| 264 Expect.throws(() => decode4(bytes), (e) => e is FormatException); | 264 Expect.throws(() => decode4(bytes), (e) => e is FormatException); |
| 265 | 265 |
| 266 String expected = test[1]; | 266 String expected = test[1]; |
| 267 Expect.equals(expected, decodeAllowMalformed(bytes)); | 267 Expect.equals(expected, decodeAllowMalformed(bytes)); |
| 268 Expect.equals(expected, decodeAllowMalformed2(bytes)); | 268 Expect.equals(expected, decodeAllowMalformed2(bytes)); |
| 269 Expect.equals(expected, decodeAllowMalformed3(bytes)); | 269 Expect.equals(expected, decodeAllowMalformed3(bytes)); |
| 270 Expect.equals(expected, decodeAllowMalformed4(bytes)); | 270 Expect.equals(expected, decodeAllowMalformed4(bytes)); |
| 271 } | 271 } |
| 272 } | 272 } |
| OLD | NEW |