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 latin1Strings = [ | 8 var latin1Strings = [ |
9 "pure ascii", | 9 "pure ascii", |
10 "blåbærgrød", | 10 "blåbærgrød", |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); | 82 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); |
83 decoded = allowInvalidCodec.decoder.convert(invalidBytes); | 83 decoded = allowInvalidCodec.decoder.convert(invalidBytes); |
84 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); | 84 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); |
85 decoded = LATIN1.decode(invalidBytes, allowInvalid: true); | 85 decoded = LATIN1.decode(invalidBytes, allowInvalid: true); |
86 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); | 86 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); |
87 } | 87 } |
88 | 88 |
89 List<int> encode(String str, int chunkSize, | 89 List<int> encode(String str, int chunkSize, |
90 Converter<String, List<int>> converter) { | 90 Converter<String, List<int>> converter) { |
91 List<int> bytes = <int>[]; | 91 List<int> bytes = <int>[]; |
92 ChunkedConversionSink byteSink = | 92 var byteSink = new ByteConversionSink.withCallback(bytes.addAll); |
93 new ByteConversionSink.withCallback(bytes.addAll); | |
94 var stringConversionSink = converter.startChunkedConversion(byteSink); | 93 var stringConversionSink = converter.startChunkedConversion(byteSink); |
95 for (int i = 0; i < str.length; i += chunkSize) { | 94 for (int i = 0; i < str.length; i += chunkSize) { |
96 if (i + chunkSize <= str.length) { | 95 if (i + chunkSize <= str.length) { |
97 stringConversionSink.add(str.substring(i, i + chunkSize)); | 96 stringConversionSink.add(str.substring(i, i + chunkSize)); |
98 } else { | 97 } else { |
99 stringConversionSink.add(str.substring(i)); | 98 stringConversionSink.add(str.substring(i)); |
100 } | 99 } |
101 } | 100 } |
102 stringConversionSink.close(); | 101 stringConversionSink.close(); |
103 return bytes; | 102 return bytes; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 148 } |
150 for (var nonLatin1String in nonLatin1Strings) { | 149 for (var nonLatin1String in nonLatin1Strings) { |
151 var units = nonLatin1String.codeUnits.toList(); | 150 var units = nonLatin1String.codeUnits.toList(); |
152 Expect.throws(() { | 151 Expect.throws(() { |
153 decode(units, chunkSize, converter); | 152 decode(units, chunkSize, converter); |
154 }); | 153 }); |
155 } | 154 } |
156 } | 155 } |
157 } | 156 } |
158 } | 157 } |
OLD | NEW |