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:async"; | 6 import "dart:async"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:isolate"; | 8 import "dart:isolate"; |
9 import "dart:utf"; | 9 import "dart:utf"; |
10 | 10 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 var controller = new StreamController(); | 190 var controller = new StreamController(); |
191 var errors = 0; | 191 var errors = 0; |
192 var stream = controller.stream | 192 var stream = controller.stream |
193 .transform(new StringDecoder()) | 193 .transform(new StringDecoder()) |
194 .transform(new LineTransformer()); | 194 .transform(new LineTransformer()); |
195 stream.listen( | 195 stream.listen( |
196 (_) {}, | 196 (_) {}, |
197 onDone: () { | 197 onDone: () { |
198 Expect.equals(1, errors); | 198 Expect.equals(1, errors); |
199 }, | 199 }, |
200 onError: (e) { | 200 onError: (error) { |
201 errors++; | 201 errors++; |
202 Expect.isTrue(e.error is TestException); | 202 Expect.isTrue(error is TestException); |
203 }); | 203 }); |
204 controller.addError(new TestException()); | 204 controller.addError(new TestException()); |
205 controller.close(); | 205 controller.close(); |
206 } | 206 } |
207 | 207 |
208 testLatin1EncoderError() { | 208 testLatin1EncoderError() { |
209 List<int> data = [0x01, | 209 List<int> data = [0x01, |
210 0x7f, | 210 0x7f, |
211 0x44, 0x61, 0x72, 0x74, | 211 0x44, 0x61, 0x72, 0x74, |
212 0x80, | 212 0x80, |
213 0xff, | 213 0xff, |
214 0x100]; | 214 0x100]; |
215 var controller = new StreamController(); | 215 var controller = new StreamController(); |
216 controller.add(new String.fromCharCodes(data)); | 216 controller.add(new String.fromCharCodes(data)); |
217 controller.close(); | 217 controller.close(); |
218 var stream = controller.stream | 218 var stream = controller.stream |
219 .transform(new StringEncoder(Encoding.ISO_8859_1)); | 219 .transform(new StringEncoder(Encoding.ISO_8859_1)); |
220 stream.listen( | 220 stream.listen( |
221 (s) { | 221 (s) { |
222 Expect.fail("data not expected"); | 222 Expect.fail("data not expected"); |
223 }, | 223 }, |
224 onError: (error) { | 224 onError: (error) { |
225 Expect.isTrue(error.error is FormatException); | 225 Expect.isTrue(error is FormatException); |
226 }); | 226 }); |
227 | 227 |
228 } | 228 } |
229 | 229 |
230 main() { | 230 main() { |
231 testUtf8(); | 231 testUtf8(); |
232 testLatin1(); | 232 testLatin1(); |
233 testAscii(); | 233 testAscii(); |
234 testReadLine1(); | 234 testReadLine1(); |
235 testReadLine2(); | 235 testReadLine2(); |
236 testErrorHandler(); | 236 testErrorHandler(); |
237 testLatin1EncoderError(); | 237 testLatin1EncoderError(); |
238 } | 238 } |
OLD | NEW |