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("dart:io"); | 5 #import("dart:io"); |
6 #import("dart:isolate"); | 6 #import("dart:isolate"); |
7 | 7 |
8 void testUtf8() { | 8 void testUtf8() { |
9 List<int> data = [0x01, | 9 List<int> data = [0x01, |
10 0x7f, | 10 0x7f, |
11 0xc2, 0x80, | 11 0xc2, 0x80, |
12 0xdf, 0xbf, | 12 0xdf, 0xbf, |
13 0xe0, 0xa0, 0x80, | 13 0xe0, 0xa0, 0x80, |
14 0xef, 0xbf, 0xbf]; | 14 0xef, 0xbf, 0xbf, |
| 15 0xf0, 0x9d, 0x84, 0x9e]; |
15 ListInputStream s = new ListInputStream(); | 16 ListInputStream s = new ListInputStream(); |
16 s.write(data); | 17 s.write(data); |
17 s.markEndOfStream(); | 18 s.markEndOfStream(); |
18 StringInputStream stream = new StringInputStream(s); | 19 StringInputStream stream = new StringInputStream(s); |
19 void stringData() { | 20 void stringData() { |
20 String s = stream.read(); | 21 String s = stream.read(); |
21 Expect.equals(6, s.length); | 22 Expect.equals(8, s.length); |
22 Expect.equals(new String.fromCharCodes([0x01]), s[0]); | 23 Expect.equals(new String.fromCharCodes([0x01]), s[0]); |
23 Expect.equals(new String.fromCharCodes([0x7f]), s[1]); | 24 Expect.equals(new String.fromCharCodes([0x7f]), s[1]); |
24 Expect.equals(new String.fromCharCodes([0x80]), s[2]); | 25 Expect.equals(new String.fromCharCodes([0x80]), s[2]); |
25 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]); | 26 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]); |
26 Expect.equals(new String.fromCharCodes([0x800]), s[4]); | 27 Expect.equals(new String.fromCharCodes([0x800]), s[4]); |
27 Expect.equals(new String.fromCharCodes([0xffff]), s[5]); | 28 Expect.equals(new String.fromCharCodes([0xffff]), s[5]); |
| 29 Expect.equals(new String.fromCharCodes([0xffff]), s[5]); |
| 30 |
| 31 // Surrogate pair for U+1D11E. |
| 32 Expect.equals(new String.fromCharCodes([0xd834]), s[6]); |
| 33 Expect.equals(new String.fromCharCodes([0xdd1e]), s[7]); |
28 } | 34 } |
29 stream.onData = stringData; | 35 stream.onData = stringData; |
30 } | 36 } |
31 | 37 |
32 void testLatin1() { | 38 void testLatin1() { |
33 List<int> data = [0x01, | 39 List<int> data = [0x01, |
34 0x7f, | 40 0x7f, |
35 0x44, 0x61, 0x72, 0x74, | 41 0x44, 0x61, 0x72, 0x74, |
36 0x80, | 42 0x80, |
37 0xff]; | 43 0xff]; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 var errors = 0; | 299 var errors = 0; |
294 var stream = new StringInputStream(new ErrorInputStream()); | 300 var stream = new StringInputStream(new ErrorInputStream()); |
295 stream.onError = (e) { | 301 stream.onError = (e) { |
296 errors++; | 302 errors++; |
297 Expect.isTrue(e is TestException); | 303 Expect.isTrue(e is TestException); |
298 }; | 304 }; |
299 Expect.equals(1, errors); | 305 Expect.equals(1, errors); |
300 } | 306 } |
301 | 307 |
302 testEncodingErrorWithHandler() { | 308 testEncodingErrorWithHandler() { |
303 var port = new ReceivePort(); | 309 var port = new ReceivePort(); |
304 var errors = 0; | 310 var errors = 0; |
305 var expected = [206, 187, 120, 46, 32, 120, 10]; | 311 var expected = [206, 187, 120, 46, 32, 120, 10]; |
306 ListInputStream input = new ListInputStream(); | 312 ListInputStream input = new ListInputStream(); |
307 input.write(expected); | 313 input.write(expected); |
308 var stringStream = new StringInputStream(input, Encoding.ASCII); | 314 var stringStream = new StringInputStream(input, Encoding.ASCII); |
309 stringStream.onData = () { | 315 stringStream.onData = () { |
310 Expect.fail("We should not get any data"); | 316 Expect.fail("We should not get any data"); |
311 }; | 317 }; |
312 stringStream.onError = (e) { | 318 stringStream.onError = (e) { |
313 port.close(); | 319 port.close(); |
314 Expect.isTrue(e is Exception); | 320 Expect.isTrue(e is Exception); |
315 }; | 321 }; |
316 } | 322 } |
317 | 323 |
318 | 324 |
319 main() { | 325 main() { |
320 testUtf8(); | 326 testUtf8(); |
321 testLatin1(); | 327 testLatin1(); |
322 testAscii(); | 328 testAscii(); |
323 testReadLine1(); | 329 testReadLine1(); |
324 testReadLine2(); | 330 testReadLine2(); |
325 testReadChunks(); | 331 testReadChunks(); |
326 testReadMixed(); | 332 testReadMixed(); |
327 testErrorHandler(); | 333 testErrorHandler(); |
328 testEncodingErrorWithHandler(); | 334 testEncodingErrorWithHandler(); |
329 } | 335 } |
OLD | NEW |