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