OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:path/path.dart"; | 5 import "dart:convert"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:json"; | 7 import "dart:json"; |
8 | 8 |
| 9 import "package:path/path.dart"; |
| 10 |
9 void testReadByte() { | 11 void testReadByte() { |
10 void test(String line, List<String> expected) { | 12 void test(String line, List<String> expected) { |
11 var script = join(dirname(Platform.script), "stdin_sync_script.dart"); | 13 var script = join(dirname(Platform.script), "stdin_sync_script.dart"); |
12 Process.start(Platform.executable, | 14 Process.start(Platform.executable, |
13 ["--checked", script]..addAll( | 15 ["--checked", script]..addAll( |
14 expected.map(stringify))).then((process) { | 16 expected.map(stringify))).then((process) { |
15 process.stdin.write(line); | 17 process.stdin.write(line); |
16 process.stdin.close(); | 18 process.stdin.close(); |
17 process.stderr | 19 process.stderr |
18 .transform(new StringDecoder()) | 20 .transform(new StringDecoder()) |
19 .transform(new LineTransformer()) | 21 .transform(new LineSplitter()) |
20 .fold(new StringBuffer(), (b, d) => b..write(d)) | 22 .fold(new StringBuffer(), (b, d) => b..write(d)) |
21 .then((data) { | 23 .then((data) { |
22 if (data.toString() != '') throw "Bad output: '$data'"; | 24 if (data.toString() != '') throw "Bad output: '$data'"; |
23 }); | 25 }); |
24 process.stdout | 26 process.stdout |
25 .transform(new StringDecoder()) | 27 .transform(new StringDecoder()) |
26 .transform(new LineTransformer()) | 28 .transform(new LineSplitter()) |
27 .fold(new StringBuffer(), (b, d) => b..write(d)) | 29 .fold(new StringBuffer(), (b, d) => b..write(d)) |
28 .then((data) { | 30 .then((data) { |
29 if (data.toString() != 'true') throw "Bad output: '$data'"; | 31 if (data.toString() != 'true') throw "Bad output: '$data'"; |
30 }); | 32 }); |
31 }); | 33 }); |
32 } | 34 } |
33 | 35 |
34 test("hej\x01\x00\x0d\x0a\x0a4\x0a", ['hej\x01\x00', '', '4']); | 36 test("hej\x01\x00\x0d\x0a\x0a4\x0a", ['hej\x01\x00', '', '4']); |
35 | 37 |
36 test("hej\u0187", ['hej\u0187']); | 38 test("hej\u0187", ['hej\u0187']); |
(...skipping 23 matching lines...) Expand all Loading... |
60 | 62 |
61 | 63 |
62 void main() { | 64 void main() { |
63 testReadByte(); | 65 testReadByte(); |
64 | 66 |
65 // testEchoMode and testLineMode is an developer-interactive test, thus not | 67 // testEchoMode and testLineMode is an developer-interactive test, thus not |
66 // enabled. | 68 // enabled. |
67 //testEchoMode(); | 69 //testEchoMode(); |
68 //testLineMode(); | 70 //testLineMode(); |
69 } | 71 } |
OLD | NEW |