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 var asciiStrings = [ | 8 var asciiStrings = [ |
9 "pure ascii", | 9 "pure ascii", |
10 "\x00 with control characters \n", | 10 "\x00 with control characters \n", |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); | 84 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); |
85 decoded = allowInvalidCodec.decoder.convert(invalidBytes); | 85 decoded = allowInvalidCodec.decoder.convert(invalidBytes); |
86 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); | 86 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); |
87 decoded = ASCII.decode(invalidBytes, allowInvalid: true); | 87 decoded = ASCII.decode(invalidBytes, allowInvalid: true); |
88 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); | 88 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); |
89 } | 89 } |
90 | 90 |
91 List<int> encode(String str, int chunkSize, | 91 List<int> encode(String str, int chunkSize, |
92 Converter<String, List<int>> converter) { | 92 Converter<String, List<int>> converter) { |
93 List<int> bytes = <int>[]; | 93 List<int> bytes = <int>[]; |
94 ChunkedConversionSink byteSink = | 94 var byteSink = new ByteConversionSink.withCallback(bytes.addAll); |
95 new ByteConversionSink.withCallback(bytes.addAll); | |
96 var stringConversionSink = converter.startChunkedConversion(byteSink); | 95 var stringConversionSink = converter.startChunkedConversion(byteSink); |
97 for (int i = 0; i < str.length; i += chunkSize) { | 96 for (int i = 0; i < str.length; i += chunkSize) { |
98 if (i + chunkSize <= str.length) { | 97 if (i + chunkSize <= str.length) { |
99 stringConversionSink.add(str.substring(i, i + chunkSize)); | 98 stringConversionSink.add(str.substring(i, i + chunkSize)); |
100 } else { | 99 } else { |
101 stringConversionSink.add(str.substring(i)); | 100 stringConversionSink.add(str.substring(i)); |
102 } | 101 } |
103 } | 102 } |
104 stringConversionSink.close(); | 103 stringConversionSink.close(); |
105 return bytes; | 104 return bytes; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 150 } |
152 for (var nonAsciiString in nonAsciiStrings) { | 151 for (var nonAsciiString in nonAsciiStrings) { |
153 var units = nonAsciiString.codeUnits.toList(); | 152 var units = nonAsciiString.codeUnits.toList(); |
154 Expect.throws(() { | 153 Expect.throws(() { |
155 decode(units, chunkSize, converter); | 154 decode(units, chunkSize, converter); |
156 }); | 155 }); |
157 } | 156 } |
158 } | 157 } |
159 } | 158 } |
160 } | 159 } |
OLD | NEW |